bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test-argmatch: fix a link failure


From: Jim Meyering
Subject: Re: test-argmatch: fix a link failure
Date: Wed, 14 Nov 2007 11:26:20 +0100

Bruno Haible <address@hidden> wrote:
> Hi Jim,
>
>>      Avoid link failure for the argmatch test.
>>      * tests/test-argmatch.c (usage): Define function to avoid a link
>>      failure: argmatch_die requires a usage function.
>
> This change may be justified inside coreutils. But in gnulib, the argmatch
> module does not make any reference to a 'usage' function. The link error
> comes from coreutils defining
>   #define ARGMATCH_DIE usage (1)
> in its config.h. Another package could be doing
>   #define ARGMATCH_DIE foobar (17)
> and by the same argumentation then we would need to define a function
> 'foobar' in the test. So adding a 'usage' function in the test does not
> smell like the right fix.
>
> Furthermore the signature of the usage() function that you added is not right.
>
> I propose this patch instead:
>
> *** tests/test-argmatch.c.orig  2007-11-11 02:07:26.000000000 +0100
> --- tests/test-argmatch.c       2007-11-11 02:02:32.000000000 +0100
> ***************
> *** 19,24 ****
> --- 19,28 ----
>
>   #include <config.h>
>
> + /* Some packages define ARGMATCH_DIE in their <config.h>.  Here we want to
> +    assume the default definition of ARGMATCH_DIE.  */
> + #undef ARGMATCH_DIE

To my chagrin, this doesn't work, either.
The trouble is that the argmatch code being linked against
is that from the library, and for coreutils, that module
includes references to usage, so an #undef here doesn't change anything.

Here are some possibilities:

1 a package like coreutils can define a new symbol, ARGMATCH_DIE_DEFINITION,
  that would expand to e.g., "void usage () { exit (1); }", and
  test-argmatch.c would add the single line,

  ARGMATCH_DIE_DEFINITION

  to define the required function.

2 try to derive automatically the above definition from the
  ARGMATCH_DIE_DECL string, when it's defined.
  For coreutils, I use this:

    #define ARGMATCH_DIE_DECL extern void usage ()

3 disallow use of "extern" in ARGMATCH_DIE_DECL,
  and simply add this line to test-argmatch.c:

  ARGMATCH_DIE_DECL { exit (1); }

I prefer #3.  It is simplest, and doesn't require a new symbol or added
autoconf tests, but it does slightly abuse the ARGMATCH_DIE_DECL symbol,
by making a definition out of it.  I actually tested it, this time.

Here's the proposed gnulib change:

diff --git a/tests/test-argmatch.c b/tests/test-argmatch.c
index f6126f6..ebba8b7 100644
--- a/tests/test-argmatch.c
+++ b/tests/test-argmatch.c
@@ -19,9 +19,11 @@

 #include <config.h>

-/* Some packages define ARGMATCH_DIE in their <config.h>.  Here we want to
-   assume the default definition of ARGMATCH_DIE.  */
-#undef ARGMATCH_DIE
+/* Some packages define ARGMATCH_DIE and ARGMATCH_DIE_DECL in <config.h>, and
+   thus must link with a definition of that function.  Provide it here.  */
+#ifdef ARGMATCH_DIE_DECL
+ARGMATCH_DIE_DECL { exit (1); }
+#endif

 #include "argmatch.h"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]