Date: Thu, 18 Dec 2014 07:41:53 -0700 From: Ian Lepore <ian@freebsd.org> To: Luigi Rizzo <rizzo@iet.unipi.it> Cc: current@freebsd.org Subject: Re: wrapping a vararg C function (specifically, log() in the kernel) Message-ID: <1418913713.1018.4.camel@freebsd.org> In-Reply-To: <20141218142115.GA17786@onelab2.iet.unipi.it> References: <20141218142115.GA17786@onelab2.iet.unipi.it>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 2014-12-18 at 15:21 +0100, Luigi Rizzo wrote: > Hi, > in the porting of some kernel code to FreeBSD, i need to remap one > function with a variable number of arguments to the log() function > from the freebsd kernel. > > Normally i would do > > #define WARN(x, args...) log(LOG_WARNING, args) > > but this does not work in my case because the function is called in > (many) blocks where there is already a local variable with the same name > > bool log; > > which is used a ton of times. > > I was wondering if there is some C compiler magic i can use to do the > remapping without going through a macro; I haven't found any direct one, > though perhaps something like > > extern void (*freebsd_log)(int level, const char *fmt, ...); > > #define WARN(x, args...) freebsd_log(LOG_WARNING, args) > > followed somewhere in a safe place by > > freebsd_log = log; > > may do the job. > > Any other option ? > > cheers > luigi Normally I'd fix it like: #define WARN(x,args...) locallog(LOG_WARNING, args) static inline void locallog(int lvl, const char *fmt, ...) { va_list ap; va_start(ap, fmt); logv(level, fmt, ap); va_end(ap); } But unfortunately we don't have a logv() function. I think maybe we should have one. :) -- Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1418913713.1018.4.camel>