From owner-freebsd-current@FreeBSD.ORG Thu Dec 18 14:42:03 2014 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 524C8C2E for ; Thu, 18 Dec 2014 14:42:03 +0000 (UTC) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2839F2450 for ; Thu, 18 Dec 2014 14:42:03 +0000 (UTC) Received: from [73.34.117.227] (helo=ilsoft.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1Y1cH6-000AkZ-Bv; Thu, 18 Dec 2014 14:41:56 +0000 Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id sBIEfr9t065455; Thu, 18 Dec 2014 07:41:54 -0700 (MST) (envelope-from ian@freebsd.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1+VHCDcb2EAu2W00ta8a+CF Message-ID: <1418913713.1018.4.camel@freebsd.org> Subject: Re: wrapping a vararg C function (specifically, log() in the kernel) From: Ian Lepore To: Luigi Rizzo Date: Thu, 18 Dec 2014 07:41:53 -0700 In-Reply-To: <20141218142115.GA17786@onelab2.iet.unipi.it> References: <20141218142115.GA17786@onelab2.iet.unipi.it> Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.12.8 FreeBSD GNOME Team Port Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Dec 2014 14:42:03 -0000 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