bug-gnulib
[Top][All Lists]
Advanced

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

Re: gnulib string module problems on Debian stable, maybe other platform


From: Bruno Haible
Subject: Re: gnulib string module problems on Debian stable, maybe other platforms
Date: Fri, 2 Feb 2007 04:49:38 +0100
User-agent: KMail/1.5.4

Paul Eggert wrote:
> But I see further problems in this area.  For example,
> mountlist uses strstr in a system-dependent way where the ASCII-only
> system strstr is just fine.  A program that uses mountlist shouldn't
> need to use the gnulib strstr if it doesn't want to.

Indeed, the gnulib modules for 'strstr' and similar are only optional.
If they are not used, it deserves not an error, but only a warning, and
only in full checking mode. This patch implements it; more patches for
the "full POSIX checking mode" later.

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

        * lib/string_.h (GL_LINK_WARNING): New macro.
        (strcasecmp, strstr, strcasestr): If provided by the system,
        conditionally define as a macro that leads to a warning instead of to
        an error.
        (strncasecmp): Conditionally define as a macro that leads to a warning.

*** lib/string_.h       1 Feb 2007 08:57:49 -0000       1.5
--- lib/string_.h       2 Feb 2007 03:30:14 -0000
***************
*** 21,26 ****
--- 21,57 ----
  
  #include @ABSOLUTE_STRING_H@
  
+ 
+ /* GL_LINK_WARNING("literal string") arranges to emit the literal string as
+    a linker warning on most glibc systems.
+    We use a linker warning rather than a preprocessor warning, because
+    #warning cannot be used inside macros.  */
+ #ifndef GL_LINK_WARNING
+   /* This works on platforms with GNU ld and ELF object format.
+      Testing __GLIBC__ is sufficient for asserting that GNU ld is in use.
+      Testing __ELF__ guarantees the ELF object format.
+      Testing __GNUC__ is necessary for the compound expression syntax.  */
+ # if defined __GLIBC__ && defined __ELF__ && defined __GNUC__
+ #  define GL_LINK_WARNING(message) \
+      GL_LINK_WARNING1 (__FILE__, __LINE__, message)
+ #  define GL_LINK_WARNING1(file, line, message) \
+      GL_LINK_WARNING2 (file, line, message)  /* macroexpand file and line */
+ #  define GL_LINK_WARNING2(file, line, message) \
+      GL_LINK_WARNING3 (file ":" #line ": " message)
+ #  define GL_LINK_WARNING3(message) \
+      ({ static const char warning[sizeof (message)]           \
+           __attribute__ ((__unused__,                         \
+                           __section__ (".gnu.warning"),               \
+                           __aligned__ (1)))                   \
+           = message "\n";                                     \
+         (void)0;                                              \
+      })
+ # else
+ #  define GL_LINK_WARNING(message) ((void) 0)
+ # endif
+ #endif
+ 
+ 
  #ifdef __cplusplus
  extern "C" {
  #endif
***************
*** 94,102 ****
  #  define strcasecmp rpl_strcasecmp
  extern int strcasecmp (char const *__s1, char const *__s2);
  # endif
! #else
  # undef strcasecmp
! # define strcasecmp 
strcasecmp_is_unportable__use_gnulib_module_strcase_for_portability
  #endif
  
  /* Compare no more than N bytes of strings S1 and S2, ignoring case,
--- 125,135 ----
  #  define strcasecmp rpl_strcasecmp
  extern int strcasecmp (char const *__s1, char const *__s2);
  # endif
! #elif defined GNULIB_POSIXCHECK
  # undef strcasecmp
! # define strcasecmp(a,b) \
!     (GL_LINK_WARNING ("strcasecmp is often incorrectly implemented for 
multibyte locales - use gnulib module 'strcase' for correct and portable 
internationalization"), \
!      strcasecmp (a, b))
  #endif
  
  /* Compare no more than N bytes of strings S1 and S2, ignoring case,
***************
*** 107,115 ****
  # if ! @HAVE_DECL_STRNCASECMP@
  extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
  # endif
! #else
  # undef strncasecmp
! # define strncasecmp 
strncasecmp_is_unportable__use_gnulib_module_strcase_for_portability
  #endif
  
  /* Find the first occurrence of C in S or the final NUL byte.  */
--- 140,151 ----
  # if ! @HAVE_DECL_STRNCASECMP@
  extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
  # endif
! #endif
! #if defined GNULIB_POSIXCHECK
  # undef strncasecmp
! # define strncasecmp(a,b) \
!     (GL_LINK_WARNING ("strncasecmp cannot work correctly in multibyte locales 
- don't use it if you care about internationalization"), \
!      strncasecmp (a, b))
  #endif
  
  /* Find the first occurrence of C in S or the final NUL byte.  */
***************
*** 203,211 ****
  #  define strstr rpl_strstr
  extern char *strstr (char const *__haystack, char const *__needle);
  # endif
! #else
  # undef strstr
! # define strstr strstr_is_unportable__use_gnulib_module_strstr_for_portability
  #endif
  
  /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
--- 239,249 ----
  #  define strstr rpl_strstr
  extern char *strstr (char const *__haystack, char const *__needle);
  # endif
! #elif defined GNULIB_POSIXCHECK
  # undef strstr
! # define strstr(a,b) \
!     (GL_LINK_WARNING ("strstr is often incorrectly implemented for multibyte 
locales - use gnulib module 'strstr' for correct and portable 
internationalization"), \
!      strstr (a, b))
  #endif
  
  /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
***************
*** 218,226 ****
  #  define strcasestr rpl_strcasestr
  extern char *strcasestr (const char *haystack, const char *needle);
  # endif
! #else
  # undef strcasestr
! # define strcasestr 
strcasestr_is_unportable__use_gnulib_module_strcasestr_for_portability
  #endif
  
  /* Parse S into tokens separated by characters in DELIM.
--- 256,266 ----
  #  define strcasestr rpl_strcasestr
  extern char *strcasestr (const char *haystack, const char *needle);
  # endif
! #elif defined GNULIB_POSIXCHECK
  # undef strcasestr
! # define strcasestr(a,b) \
!     (GL_LINK_WARNING ("strcasestr is often incorrectly implemented for 
multibyte locales - use gnulib module 'strcasestr' for correct and portable 
internationalization"), \
!      strcasestr (a, b))
  #endif
  
  /* Parse S into tokens separated by characters in DELIM.





reply via email to

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