xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>, Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()
Date: Tue, 19 Jan 2016 16:24:10 +0000	[thread overview]
Message-ID: <1453220650.29930.107.camel@citrix.com> (raw)
In-Reply-To: <1452802425-32603-1-git-send-email-andrew.cooper3@citrix.com>

On Thu, 2016-01-14 at 20:13 +0000, Andrew Cooper wrote:
> XTL_NEW_LOGGER() makes a number of unreasonable assumptions about the symbols
> visible in its scope,

It assumes that the function names to fill in the vtable and the type name
are related, that hardly seems totally "unreasonable". What else does it
assume that makes it unreasonable?

I think if you intend to remove something on this basis you need to be
specific about what you believe the short comings are.

>  and as such is only usable by its sole caller.

"not usable by every imaginable caller" is not the same as "usable by one
single possible caller", I think you are overstating the case here.

> 
> Remove it.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/libs/toollog/include/xentoollog.h | 21 ---------------------
>  tools/libs/toollog/xtl_logger_stdio.c   | 30 ++++++++++++++++++---------
> ---
>  2 files changed, 18 insertions(+), 33 deletions(-)
> 
> diff --git a/tools/libs/toollog/include/xentoollog.h
> b/tools/libs/toollog/include/xentoollog.h
> index 853e9c7..2b5bfcb 100644
> --- a/tools/libs/toollog/include/xentoollog.h
> +++ b/tools/libs/toollog/include/xentoollog.h
> @@ -112,25 +112,4 @@ void xtl_progress(struct xentoollog_logger *logger,
>  
>  const char *xtl_level_to_string(xentoollog_level); /* never fails */
>  
> -
> -#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;                                                       
> \
> -});
> -
> -
>  #endif /* XENTOOLLOG_H */
> diff --git a/tools/libs/toollog/xtl_logger_stdio.c
> b/tools/libs/toollog/xtl_logger_stdio.c
> index 0cd9206..8bce1a7 100644
> --- a/tools/libs/toollog/xtl_logger_stdio.c
> +++ b/tools/libs/toollog/xtl_logger_stdio.c
> @@ -165,28 +165,34 @@ void
> xtl_stdiostream_adjust_flags(xentoollog_logger_stdiostream *lg,
>  
>  xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
>          (FILE *f, xentoollog_level min_level, unsigned flags) {
> -    xentoollog_logger_stdiostream newlogger;
>  
> -    newlogger.f = f;
> -    newlogger.min_level = min_level;
> -    newlogger.flags = flags;
> +    xentoollog_logger_stdiostream *nl =
> +        calloc(sizeof(xentoollog_logger_stdiostream), 1);
> +
> +    if (!nl)
> +        return NULL;
> +
> +    nl->vtable.vmessage = stdiostream_vmessage;
> +    nl->vtable.progress = stdiostream_progress;
> +    nl->vtable.destroy  = stdiostream_destroy;
> +
> +    nl->f = f;
> +    nl->min_level = min_level;
> +    nl->flags = flags;
>  
>      switch (flags & (XTL_STDIOSTREAM_PROGRESS_USE_CR |
>                       XTL_STDIOSTREAM_PROGRESS_NO_CR)) {
> -    case XTL_STDIOSTREAM_PROGRESS_USE_CR: newlogger.progress_use_cr = 1;
> break;
> -    case XTL_STDIOSTREAM_PROGRESS_NO_CR:  newlogger.progress_use_cr = 0;
> break;
> +    case XTL_STDIOSTREAM_PROGRESS_USE_CR: nl->progress_use_cr = 1;
> break;
> +    case XTL_STDIOSTREAM_PROGRESS_NO_CR:  nl->progress_use_cr = 0;
> break;
>      case 0:
> -        newlogger.progress_use_cr = isatty(fileno(newlogger.f)) > 0;
> +        nl->progress_use_cr = isatty(fileno(nl->f)) > 0;
>          break;
>      default:
>          errno = EINVAL;
>          return 0;
>      }
>  
> -    if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();
> -
> -    newlogger.progress_erase_len = 0;
> -    newlogger.progress_last_percent = 0;
> +    if (nl->flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();
>  
> -    return XTL_NEW_LOGGER(stdiostream, newlogger);
> +    return nl;
>  }
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-01-19 16:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 20:13 [PATCH] tools/toollog: Drop XTL_NEW_LOGGER() Andrew Cooper
2016-01-19  9:46 ` Wei Liu
2016-01-19 16:24 ` Ian Campbell [this message]
2016-01-19 16:40   ` Andrew Cooper
2016-01-19 17:04     ` Ian Campbell
2016-01-19 17:15       ` Ian Jackson
2016-01-19 17:18         ` Ian Jackson
2016-01-19 17:36         ` Ian Jackson
2016-01-19 17:45           ` Andrew Cooper
2016-01-19 17:58             ` Ian Jackson
2016-01-20 17:21               ` Ian Campbell

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=1453220650.29930.107.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).