All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: roger.pau@citrix.com, wei.liu2@citrix.com,
	Ian Campbell <ian.campbell@citrix.com>,
	stefano.stabellini@eu.citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH RFC tools 1/6] tools: Refactor "xentoollog" into its own library
Date: Mon, 21 Sep 2015 18:03:22 +0100	[thread overview]
Message-ID: <5600385A.2060704@citrix.com> (raw)
In-Reply-To: <22016.11647.190463.194074@mariner.uk.xensource.com>

On 21/09/15 17:17, Ian Jackson wrote:
> Andrew Cooper writes ("Re: [Xen-devel] [PATCH RFC tools 1/6] tools: Refactor "xentoollog" into its own library"):
>> On 10/06/15 12:36, Ian Campbell wrote:
>>> +
>>> +#define XTL_NEW_LOGGER(LOGGER,buffer) ({                                \
>>> +    xentoollog_logger_##LOGGER *new_consumer;                           \
>>> +                                                                        \
>>> +    (buffer).vtable.vmessage = LOGGER##_vmessage;                       \
>>> +    (buffer).vtable.progress = LOGGER##_progress;                       \
>>> +    (buffer).vtable.destroy  = LOGGER##_destroy;                        \
>>> +                                                                        \
>>> +    new_consumer = malloc(sizeof(*new_consumer));                       \
>>> +    if (!new_consumer) {                                                \
>>> +        xtl_log((xentoollog_logger*)&buffer,                            \
>>> +                XTL_CRITICAL, errno, "xtl",                             \
>>> +                "failed to allocate memory for new message logger");    \
>>> +    } else {                                                            \
>>> +        *new_consumer = buffer;                                         \
>>> +    }                                                                   \
>>> +                                                                        \
>>> +    new_consumer;                                                       \
>>> +});
> Ian Campbell just pointed me at this.
>
>> This macro should be ditched.
>>
>> It is a gnu-ism which shouldn't be present in the public library header,
> Do you mean that statement expressions (originally a GNU extension)
> should be avoided in tools code ?  A quick git-grep discovered that
> xenctrl already contains numerous statement expressions.

It is fine (in principle) to be used internally.  Not in a public header
for what is supposed to be a clean API.

>
>> violates several principles of least supprise,
> This is just invective.

/me googles and discovered a new word.  I stand by my statement.

It requires the user to embed one structure inside another structure
(with half a undocumented magic name), under a specific undocumented
field name, and have three functions (with half undocumented magic
names) in scope with undocumented types.  It also mandates an original
copy of the half-magically-named struct in scope to be partially
initialised, just to have another copy created in the heap.

The error handling is also broken;  It will follow a wild function
pointer, if vtable is not the first element in the structure (again
undocumented).

This macro is not fit for any purpose it attempts to perform.

https://github.com/xenserver/xen-4.5.pg/blob/master/master/xenguest.patch#L609
is the correct way to use a setup like this, even if it does require
embedding other data alongside it.

>
>> and can literally only be
>> used by its sole user in xtl_logger_stdio.c because of its internal
>> expectations of xentoollog_logger_stdiostream.  (Its sole user could do
>> the above in a cleaner manner anyway.)
> There is only one place in tree that calls this because there are only
> two in-tree loggers and the other one
> (tools/ocaml/libs/xentoollog/xentoollog_stubs.c) chose not to use it.
> It seems to me that stub_xtl_create_logger could use this macro.

Or better yet, ditch it completely.

All that needs to happen is for struct xentoollog_logger to have the
three function pointers filled in appropriately.  This in turn does not
mandate that the structure is allocated from the heap, or the prescribed
layout/naming scheme.

>
>> As part of the tidyup, we should choose a particular C standard (89,
>> probably) and ensure that the API/ABI complies with `gcc -std=c$VER
>> -pedantic`.  This will help to provide a consistent API on other
>> platforms (I seem to recall an effort to port libvchan to windows.)
> -pedantic is certainly a bad idea.

Pedantic is absolutely the correct answer.  It will cause gcc to reject
any non C compliant statements.

The APIs of each of these new libraries should be just as usable on
windows systems as Linux systems.

~Andrew

  reply	other threads:[~2015-09-21 17:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 11:36 [PATCH RFC 0/6+2+2] Begin to disentangle libxenctrl and provide some stable libraries Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 1/6] tools: Refactor "xentoollog" into its own library Ian Campbell
2015-06-11 11:20   ` Andrew Cooper
2015-06-11 11:35     ` Ian Campbell
2015-06-11 12:06       ` Jan Beulich
2015-06-11 12:21         ` Ian Campbell
2015-09-21 16:17     ` Ian Jackson
2015-09-21 17:03       ` Andrew Cooper [this message]
2015-09-21 17:13         ` Ian Jackson
2015-09-21 17:30           ` Andrew Cooper
2015-09-22  8:39             ` Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 2/6] tools: Link in-tree libvchan users against libxenvchan.so Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 3/6] tools: Do not add top-level tools dir to include path Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 4/6] tools/libxc: Remove osdep indirection for xc_evtchn Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 5/6] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn Ian Campbell
2015-06-10 16:29   ` David Vrabel
2015-06-11  8:58     ` Ian Campbell
2015-06-10 17:16   ` Andrew Cooper
2015-06-11  9:03     ` Ian Campbell
2015-06-10 11:36 ` [PATCH RFC tools 6/6] Cleanup SHLIBDEPS Ian Campbell
2015-06-10 11:37 ` [PATCH RFC qemu-trad 1/2] qemu-xen-traditional: Use xentoollog as a separate library Ian Campbell
2015-06-10 15:57   ` Ian Jackson
2015-06-11  8:59     ` Ian Campbell
2015-06-10 11:37 ` [PATCH RFC qemu-trad 2/2] qemu-xen-traditional: Use libxenevtchn Ian Campbell
2015-06-10 11:37 ` [PATCH RFC mini-os 1/2] mini-os: Include libxentoollog with libxc Ian Campbell
2015-06-10 11:37 ` [PATCH RFC mini-os 2/2] mini-os: Include libxenevtchn " Ian Campbell
2015-06-10 16:01 ` [PATCH RFC 0/6+2+2] Begin to disentangle libxenctrl and provide some stable libraries Ian Jackson
2015-06-10 16:15   ` Wei Liu
2015-06-11 10:01     ` Antti Kantee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5600385A.2060704@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.