From owner-freebsd-stable@FreeBSD.ORG Tue Nov 24 22:30:25 2009 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13622106568F; Tue, 24 Nov 2009 22:30:25 +0000 (UTC) (envelope-from marka@isc.org) Received: from farside.isc.org (farside.isc.org [IPv6:2001:4f8:3:bb::5]) by mx1.freebsd.org (Postfix) with ESMTP id EC1FB8FC12; Tue, 24 Nov 2009 22:30:24 +0000 (UTC) Received: from drugs.dv.isc.org (drugs.dv.isc.org [IPv6:2001:470:1f00:820:214:22ff:fed9:fbdc]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "drugs.dv.isc.org", Issuer "ISC CA" (not verified)) by farside.isc.org (Postfix) with ESMTP id 42713E6065; Tue, 24 Nov 2009 22:30:24 +0000 (UTC) (envelope-from marka@isc.org) Received: from drugs.dv.isc.org (localhost [127.0.0.1]) by drugs.dv.isc.org (8.14.3/8.14.3) with ESMTP id nAOMUKmh052215; Wed, 25 Nov 2009 09:30:20 +1100 (EST) (envelope-from marka@drugs.dv.isc.org) Message-Id: <200911242230.nAOMUKmh052215@drugs.dv.isc.org> To: Daniel Eischen From: Mark Andrews References: <86aayc7z4g.fsf@zhuzha.ua1> <8663907xyy.fsf@zhuzha.ua1> <20091124153422.GT2331@deviant.kiev.zoral.com.ua> <200911242141.nAOLfAQa050429@drugs.dv.isc.org> In-reply-to: Your message of "Tue, 24 Nov 2009 17:20:25 CDT." Date: Wed, 25 Nov 2009 09:30:20 +1100 Sender: marka@isc.org Cc: Kostik Belousov , FreeBSD Stable , Mikolaj Golub Subject: Re: pthread.h: typo in #define pthread_cleanup_push/pthread_cleanup_pop X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2009 22:30:25 -0000 In message , Daniel Eischen wri tes: > On Wed, 25 Nov 2009, Mark Andrews wrote: > > > > > In message <20091124153422.GT2331@deviant.kiev.zoral.com.ua>, Kostik Belous > ov write > > s: > >> > >> --i616tqyc3hrkKsk2 > >> Content-Type: text/plain; charset=us-ascii > >> Content-Disposition: inline > >> Content-Transfer-Encoding: quoted-printable > >> > >> On Tue, Nov 24, 2009 at 05:18:29PM +0200, Mikolaj Golub wrote: > >> > >> pthread_cleanup_push/pop are supposed to be used from the common > >> lexical scope. Citation from SUSv4: > >> > >> These functions may be implemented as macros. The application shall > >> ensure that they appear as statements, and in pairs within the same > >> lexical scope (that is, the pthread_cleanup_push() macro may be > >> thought to expand to a token list whose first token is '{' with > >> pthread_cleanup_pop() expanding to a token list whose last token is the > >> corresponding '}' ). > >> > >> Your change is wrong. > >> > >> Basically, the code should do > >> pthread_cleanup_push(some_func, arh); > >> something ... > >> pthread_cleanup_pop(1); > >> (1 denotes that some_func should be called). > > > > The problem is that that expands to C code that can only be used > > with newer C compilers. This expansion should be usable with all > > C compilers. > > > > #define pthread_cleanup_push(cleanup_routine, cleanup_arg) > \ > > { \ > > struct _pthread_cleanup_info __cleanup_info__; \ > > __pthread_cleanup_push_imp(cleanup_routine, cleanup > _arg,\ > > &__cleanup_info__) > > > > #define pthread_cleanup_pop(execute) > \ > > __pthread_cleanup_pop_imp(execute); \ > > } ((void)0) > > Hmm, agreed. But note that Solaris 10 does it this way: > > #define pthread_cleanup_push(routine, args) { \ > _cleanup_t _cleanup_info; \ > __pthread_cleanup_push((_Voidfp)(routine), (void *)(args), \ > (caddr_t)_getfp(), &_cleanup_info); > > #define pthread_cleanup_pop(ex) \ > __pthread_cleanup_pop(ex, &_cleanup_info); \ > } Writing portable macros that don't generate compiler warnings is fun. :-) Tricks like "do { } while (0)" and "{ } ((void)0)" absorb the pesky semi-colon. > -- > DE -- Mark Andrews, ISC 1 Seymour St., Dundas Valley, NSW 2117, Australia PHONE: +61 2 9871 4742 INTERNET: marka@isc.org