From patchwork Fri May 23 17:34:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 1107 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id DD889360098 for ; Fri, 23 May 2014 10:35:07 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14307373) id 706795D5D574; Fri, 23 May 2014 10:35:07 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 0E3AA5D5D51A for ; Fri, 23 May 2014 10:35:07 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; q=dns; s=default; b=t85r0iv6i/i9h6S8f4jD34xxkEsr7f q9WTACHS8DXE7qce2xk5ld7mQtAw7+wYFiXaZYrEK09QsbtHFsymA/KMBd1D7VoU 22z2T0P3U/BnkZ9/BtVXcAwUtTlRtwi6xseYm4lfBdeDzIlhGXPeNAscv0mDMi4Y wTfjuDlGNaIbM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=default; bh=LqMBO6A9JszzRd7uC3lCOL7JGw4=; b=rAFl wI+yflhBrBsNS5o8aXuaY4Gm9L6o9kwcF2NeAjpkiI50WFesNKsJY7TBgeCxUARP t69UZRMC3CSYxqRdnrw8WbOEx2nJXzPyQaPmetetpg8hmMFtqcqG4eE9m7H8G3mg ZOARqw7uuXCt8XnZoim/eqp+MqSPhcGxryn069g= Received: (qmail 2849 invoked by alias); 23 May 2014 17:35:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2835 invoked by uid 89); 23 May 2014 17:35:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL, BAYES_05, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Fri, 23 May 2014 19:34:57 +0200 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Paul Eggert Cc: Will Newton , aurelien@aurel32.net, libc-alpha , bug-gnulib@gnu.org Subject: [PATCH][BZ #16907] Sync argp.h __attribute__ with gnulib. Message-ID: <20140523173457.GA26513@domone.podge> References: <20140518125743.GA11620@domone.podge> <20140523100038.GA15258@domone.podge> <537F60D7.3060106@cs.ucla.edu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <537F60D7.3060106@cs.ucla.edu> User-Agent: Mutt/1.5.20 (2009-06-14) X-DH-Original-To: glibc@patchwork.siddhesh.in On Fri, May 23, 2014 at 07:53:11AM -0700, Paul Eggert wrote: > Ondřej Bílka wrote: > >CCing gnulib. Could this be backported also there or do you have > >different solution? > > We solved this problem in a different way years ago, using something > like this: > > #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR >= 7) > # define _GL_ATTRIBUTE_FORMAT(s) __attribute__ ((__format__ s)) > #else > # define _GL_ATTRIBUTE_FORMAT(s) > #endif > > and then using _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)) later, > instead of __attribute__ ((__format__ (__printf__, 2, 3))). > Presumably glibc could do something similar. Glibc could use a > different name; that's all right, gnulib will just switch to the > name that glibc uses. Ok, here is patch that does that with unchanged name (Does somebody have better one?). As I looked at header differences they are mostly minor, like using `foo' instead "foo" in comments so it migth be worthwhile to sync them up. * argp/argp-fmtstream.h (_GL_ATTRIBUTE_FORMAT): Define. (argp_error, argp_failure): Use _GL_ATTRIBUTE_FORMAT. * argp/argp.h (__argp_fmtstream_printf): Likewise. extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); --- argp/argp.h 2014-05-19 11:41:01.642730292 +0200 +++ ../argp/argp.h 2013-09-08 21:46:15.382388772 +0200 @@ -35,19 +34,16 @@ # define __NTH(fct) fct __THROW #endif -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \ - defined __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \ - defined __STRICT_ANSI__ -# define __format__ format -# define __printf__ printf -# endif +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ #endif /* GCC 2.95 and later have "__restrict"; C99 compilers have @@ -496,19 +519,19 @@ FILE *__restrict __stream, unsigned int __flags); /* Possibly output the standard usage message for ARGP to stderr and exit. */ extern void argp_usage (const struct argp_state *__state); extern void __argp_usage (const struct argp_state *__state); /* If appropriate, print the printf string FMT and following args, preceded by the program name and `:', to stderr, and followed by a `Try ... --help' message, then exit (1). */ extern void argp_error (const struct argp_state *__restrict __state, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); extern void __argp_error (const struct argp_state *__restrict __state, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); + _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); /* Similar to the standard gnu error-reporting function error(), but will respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print @@ -521,12 +546,12 @@ extern void argp_failure (const struct argp_state *__restrict __state, int __status, int __errnum, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 4, 5))); + _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); extern void __argp_failure (const struct argp_state *__restrict __state, 7int __status, int __errnum, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 4, 5))); + _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); /* Returns true if the option OPT is a valid short option. */ extern int _option_is_short (const struct argp_option *__opt) __THROW; extern int __option_is_short (const struct argp_option *__opt) __THROW; --- argp/argp-fmtstream.h 2014-05-19 11:41:01.642730292 +0200 +++ ../argp/argp-fmtstream.h 2013-09-08 21:46:15.378388647 +0200 @@ -29,22 +28,19 @@ #include #include -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \ - defined __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \ - defined __STRICT_ANSI__ -# define __format__ format -# define __printf__ printf -# endif +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ #endif #if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H) /* line_wrap_stream is available, so use that. */ #define ARGP_FMTSTREAM_USE_LINEWRAP #endif @@ -132,9 +128,9 @@ extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); + _GL_ATTRIBUTE_FORMAT ((printf, 2, 3)); extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); + _GL_ATTRIBUTE_FORMAT ((printf, 2, 3)); extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);