bug-gnulib
[Top][All Lists]
Advanced

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

Re: strnlen on OSX & C++


From: Bruno Haible
Subject: Re: strnlen on OSX & C++
Date: Sat, 10 Apr 2010 11:29:56 +0200
User-agent: KMail/1.9.9

Jarno Rajahalme wrote:
> main.cc:9: warning: call to 'rpl_strnlen' declared with attribute warning: 
> The symbol ::rpl_strnlen refers to the system function. Use 
> gnulib::rpl_strnlen instead.

The problem here is that gnulib's handling of strnlen is using an ancient
idiom. In string.in.h it uses _GL_CXXALIAS_SYS. _GL_CXXALIAS_RPL has a
workaround against a strange behaviour of g++, but _GL_CXXALIAS_SYS doesn't.

This should fix it.


2010-04-10  Bruno Haible  <address@hidden>

        strnlen: Fix warning in C++ mode on MacOS X.
        * lib/string.in.h (strnlen): Use the modern idiom.
        * m4/strnlen.m4 (gl_FUNC_STRNLEN): Set REPLACE_STRNLEN to 1, instead of
        defining strnlen as a macro already in <config.h>.
        * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Initialize
        REPLACE_STRNLEN.
        * modules/string (Makefile.am): Substitute REPLACE_STRNLEN.
        Reported by Jarno Rajahalme <address@hidden>.

--- lib/string.in.h.orig        Sat Apr 10 11:25:04 2010
+++ lib/string.in.h     Sat Apr 10 11:22:32 2010
@@ -372,12 +372,23 @@
    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
    return MAXLEN.  */
 #if @GNULIB_STRNLEN@
-# if ! @HAVE_DECL_STRNLEN@
+# if @REPLACE_STRNLEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef strnlen
+#   define strnlen rpl_strnlen
+#  endif
+_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)
+                                   __attribute__ ((__pure__))
+                                   _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen));
+# else
+#  if ! @HAVE_DECL_STRNLEN@
 _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)
                                    __attribute__ ((__pure__))
                                    _GL_ARG_NONNULL ((1)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen));
+# endif
 _GL_CXXALIASWARN (strnlen);
 #elif defined GNULIB_POSIXCHECK
 # undef strnlen
--- m4/string_h.m4.orig Sat Apr 10 11:25:04 2010
+++ m4/string_h.m4      Sat Apr 10 11:23:01 2010
@@ -5,7 +5,7 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 16
+# serial 17
 
 # Written by Paul Eggert.
 
@@ -105,6 +105,7 @@
   REPLACE_STRERROR=0;           AC_SUBST([REPLACE_STRERROR])
   REPLACE_STRNCAT=0;            AC_SUBST([REPLACE_STRNCAT])
   REPLACE_STRNDUP=0;            AC_SUBST([REPLACE_STRNDUP])
+  REPLACE_STRNLEN=0;            AC_SUBST([REPLACE_STRNLEN])
   REPLACE_STRSIGNAL=0;          AC_SUBST([REPLACE_STRSIGNAL])
   REPLACE_STRTOK_R=0;           AC_SUBST([REPLACE_STRTOK_R])
   UNDEFINE_STRTOK_R=0;          AC_SUBST([UNDEFINE_STRTOK_R])
--- m4/strnlen.m4.orig  Sat Apr 10 11:25:04 2010
+++ m4/strnlen.m4       Sat Apr 10 11:24:45 2010
@@ -1,4 +1,4 @@
-# strnlen.m4 serial 10
+# strnlen.m4 serial 11
 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -7,10 +7,11 @@
 
 AC_DEFUN([gl_FUNC_STRNLEN],
 [
+  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+
   dnl Persuade glibc <string.h> to declare strnlen().
   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
 
-  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
   AC_CHECK_DECLS_ONCE([strnlen])
   if test $ac_cv_have_decl_strnlen = no; then
     HAVE_DECL_STRNLEN=0
@@ -18,12 +19,11 @@
 
   AC_FUNC_STRNLEN
   if test $ac_cv_func_strnlen_working = no; then
+    REPLACE_STRNLEN=1
     # This is necessary because automake-1.6.1 doesn't understand
     # that the above use of AC_FUNC_STRNLEN means we may have to use
     # lib/strnlen.c.
     #AC_LIBOBJ([strnlen])
-    AC_DEFINE([strnlen], [rpl_strnlen],
-      [Define to rpl_strnlen if the replacement function should be used.])
     gl_PREREQ_STRNLEN
   fi
 ])
--- modules/string.orig Sat Apr 10 11:25:04 2010
+++ modules/string      Sat Apr 10 11:23:17 2010
@@ -89,6 +89,7 @@
              -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
              -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \
              -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \
+             -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \
              -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \
              -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \
              -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \




reply via email to

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