gnupg-2.0.13: unwanted gcc-ism in source code, and a needed library

Nelson H. F. Beebe beebe at math.utah.edu
Mon Oct 12 23:15:26 CEST 2009


I've made some further progress in getting gnupg-2.0.13 installed on
various local Unix platforms, and today, hit an apparent gcc-ism in
the source code:

	% cd tests
	% sed -n 202p asschk.c
	#define die(format, args...) (die) ("%s: " format, __func__ , ##args) %%

Compiling this single file with gcc, and using the native compiler on
all other files, was sufficient to get this release on build on Sun
Solaris (SPARC, AMD64, and IA-32).

A check of the text of the 1999 ISO C Standard shows this
specification of the use of variable numbers of arguments in macro
definitions:

	6.10.3 Macro replacement
	...
	4 If the identifier-list in the macro definition does not end with an
	  ellipsis, the number of arguments (including those arguments
	  consisting of no preprocessing tokens) in an invocation of a
	  function-like macro shall equal the number of parameters in the
	  macro definition. Otherwise, there shall be more arguments in the
				       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  invocation than there are parameters in the macro definition
	  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  (excluding the ...). There shall exist a ) preprocessing token that
	  terminates the invocation.

The gnupg code seems to violate that highlighted requirement, since it
has subsequent statement like

	die ("out of core");
	die ("received line too large");

after the macro definition.  Also, the Standard's syntax description
does not appear to permit a comma to be omitted before the ellipsis.

The Sun c99 compiler on this test file

	% cat foo-die.c
	extern void die (const char *format, ...);

	#define die(format, args, ...) (die) ("%s: " format, __func__ , ##args)

	void
	foo()
	{
		die("test 1");				/* line 8 */
		die("test 1", "test 2");		/* line 9 */
		die("test 1", "test 2", "test 3");	/* line 10 */
	}

produces these errors:

	% c99 -c foo-die.c
	"foo-die.c", line 8: warning: argument mismatch
	"foo-die.c", line 8: syntax error before or at: )
	"foo-die.c", line 9: warning: argument mismatch
	c99: acomp failed for foo-die.c

Notice that lines 8 and 9 elicit a diagnostic, but line 10, which has
the required minimum number of arguments, does not.

Inasmuch as this is the ONLY file in this gnupg release that uses this
C99 feature, I suggest that it would be better to remove it, in the
interests of gnupg being compilable by a wider range of compilers.

Also, linking of this release on Solaris fails with nanosleep()
unresolved.  Restarting the build with

	make LIBS=-lrt

resolves that problem.  The -lrt (real-time) library is needed on
several systems for features like high-precision timers, so configure
scripts should be written to find whether -lrt is needed on a given
build host.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe at math.utah.edu  -
- 155 S 1400 E RM 233                       beebe at acm.org  beebe at computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------



More information about the Gnupg-devel mailing list