bug-gnulib
[Top][All Lists]
Advanced

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

Re: portability checks, errors and warnings


From: Bruno Haible
Subject: Re: portability checks, errors and warnings
Date: Sat, 3 Feb 2007 02:01:27 +0100
User-agent: KMail/1.5.4

Paul Eggert wrote:
> > Therefore all problems that installers would face from this technique
> > will be noticeable by the maintainer already.
> 
> No, because the code might look like this (taken from mountlist):
> 
> #ifdef MOUNTED_VMOUNT         /* AIX.  */
>   ...
>       ignore = strstr (options, "ignore");
>   ...
> #endif
> 
> If the maintainer uses GNU/Linux, he won't see the use of strstr,
> because the code is AIX-only.

Point taken. Hence the "checking" mode can not be the same as the
"release" mode. I'm applying the appended patch.

> > Indeed that deserves some documentation. Here is a beginning:
> 
> I already understood the details.  But the combination of the details
> in the current code is still confusing, at least to me.  There is too
> much complexity for what ought to be a fairly simple thing.

It's not so simple from the beginning, since there are many cases:
  1) The function may have to be replaced
     a. if it is missing
     b. if it is missing or broken
     c. if it is missing or broken or the declaration is nonstandard
     d. if it is missing and not a macro
     e. always.
  2) The function's declaration is present in
     a. a single header file,
     b. several header files.
  3) The declaration may have to be replaced
     a. when missing
     b. never
Basically, for each combination of these possibilities we have a different
replacement idiom.

And in the cases 1b and 1c we need
  #define func rpl_func
whereas in the case 1a we _don't_ want
  #define func rpl_func
because it would hamper debugging (setting a breakpoint at 'func' should
better work if possible).

> I noticed that HAVE_ and REPLACE_ are inverses

Sometimes. Not always: not for gettimeofday, not for strstr, not for stpncpy.

> > Hmm, I would much prefer if we could keep the facility for replacement / 
> > fixup
> > of portability problems separate from the facility for detecting the 
> > portability
> > problems. Otherwise setting _GL_CHECK_PORTABILITY may hide portability
> > problsm - which would defeat its purpose.
> 
> I don't see how setting it would hide portability problems.  What's the
> scenario you're worried about?

I'm worried that if you activate the replacement
  # define strstr rpl_strstr
with its lib/strstr.o file depending on _GL_CHECK_PORTABILITY, or if you
activate the declaration
  extern char *strstr (char const *__haystack, char const *__needle);
only if _GL_CHECK_PORTABILITY, then the program may compile fine with
_GL_CHECK_PORTABILITY and break without it.

Or, if the declaration
  extern char *strstr (char const *__haystack, char const *__needle);
is activated only if ! _GL_CHECK_PORTABILITY, then a conflict with the
system's header file may occur if ! _GL_CHECK_PORTABILITY but be
invisible if _GL_CHECK_PORTABILITY. But _GL_CHECK_PORTABILITY should
only signal more problems, not make any kind of problem disappear.

>      #if ! @HAVE_STRSTR@
>      # undef strstr
>      # define strstr rpl_strstr
>      #endif

As mentioned above, for some functions, no "# define strstr rpl_strstr"
is desired.

>      #if ! @HAVE_STRSTR@ || ! @HAVE_DECL_STRSTR@
>      extern char *strstr (char const *__haystack, char const *__needle);
>      #endif
> 
>    @HAVE_STRSTR@ is:
> 
>      1 if 'configure' checks the system strstr and found it to be OK.
> 
>      0 if 'configure' checks the system strstr and found problems.
> 
>      (!_GL_CHECK_PORTABILITY) otherwise.

What does "otherwise" mean? Either 'configure' finds the system's strstr
OK or it finds problems. What is the third alternative?

Bruno


2007-02-02  Bruno Haible  <address@hidden>

        * lib/string_.h (memmem, mempcpy, memrchr, stpcpy, stpncpy, strchrnul,
        strdup, strndup, strnlen, strpbrk, strsep, strtok_r): Provoke a link
        error only if GNULIB_POSIXCHECK is defined. Needed to avoid artificial
        portability problems if one of these functions is only used on specific
        platforms.
        Reported by Paul Eggert.

--- lib/string_.h       2 Feb 2007 03:46:59 -0000       1.6
+++ lib/string_.h       2 Feb 2007 23:51:38 -0000
@@ -62,7 +62,7 @@
 extern void *memmem (void const *__haystack, size_t __haystack_len,
                     void const *__needle, size_t __needle_len);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef memmem
 # define memmem memmem_is_unportable__use_gnulib_module_memmem_for_portability
 #endif
@@ -74,7 +74,7 @@
 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
                      size_t __n);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef mempcpy
 # define mempcpy 
mempcpy_is_unportable__use_gnulib_module_mempcpy_for_portability
 #endif
@@ -84,7 +84,7 @@
 # if ! @HAVE_DECL_MEMRCHR@
 extern void *memrchr (void const *, int, size_t);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef memrchr
 # define memrchr 
memrchr_is_unportable__use_gnulib_module_memrchr_for_portability
 #endif
@@ -94,7 +94,7 @@
 # if ! @HAVE_STPCPY@
 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef stpcpy
 # define stpcpy stpcpy_is_unportable__use_gnulib_module_stpcpy_for_portability
 #endif
@@ -107,7 +107,7 @@
 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
                      size_t __n);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef stpncpy
 # define stpncpy 
stpncpy_is_unportable__use_gnulib_module_stpncpy_for_portability
 #endif
@@ -153,7 +153,7 @@
 # if ! @HAVE_STRCHRNUL@
 extern char *strchrnul (char const *__s, int __c_in);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strchrnul
 # define strchrnul 
strchrnul_is_unportable__use_gnulib_module_strchrnul_for_portability
 #endif
@@ -163,7 +163,7 @@
 # if ! @HAVE_DECL_STRDUP@ && ! defined strdup
 extern char *strdup (char const *__s);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strdup
 # define strdup strdup_is_unportable__use_gnulib_module_strdup_for_portability
 #endif
@@ -177,7 +177,7 @@
 extern char *strndup (char const *__string, size_t __n);
 #  endif
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strndup
 # define strndup 
strndup_is_unportable__use_gnulib_module_strndup_for_portability
 #endif
@@ -189,7 +189,7 @@
 # if ! @HAVE_DECL_STRNLEN@
 extern size_t strnlen (char const *__string, size_t __maxlen);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strnlen
 # define strnlen 
strnlen_is_unportable__use_gnulib_module_strnlen_for_portability
 #endif
@@ -199,7 +199,7 @@
 # if ! @HAVE_STRPBRK@
 extern char *strpbrk (char const *__s, char const *__accept);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strpbrk
 # define strpbrk 
strpbrk_is_unportable__use_gnulib_module_strpbrk_for_portability
 #endif
@@ -224,7 +224,7 @@
 # if ! @HAVE_STRSEP@
 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strsep
 # define strsep strsep_is_unportable__use_gnulib_module_strsep_for_portability
 #endif
@@ -290,7 +290,7 @@
 extern char *strtok_r (char *restrict __s, char const *restrict __sep,
                       char **restrict __lasts);
 # endif
-#else
+#elif defined GNULIB_POSIXCHECK
 # undef strtok_r
 # define strtok_r 
strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability
 #endif





reply via email to

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