[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
strndup.m4 cleanup
From: |
Eric Blake |
Subject: |
strndup.m4 cleanup |
Date: |
Wed, 09 Sep 2009 21:36:46 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I noticed this when cross-compiling to mingw:
| checking for working strndup... checking for strndup... no
| no
The m4 macro did a no-no - it was calling AC_CHECK_FUNC([strndup]), which
has side effects, in the body of an AC_CACHE_CHECK. Meanwhile, the
semantics of HAVE_STRNDUP were confusing - AIX 5 has it, but it needs
replacing, so the variable is better named REPLACE_STRNDUP. Cleaned up as
follows:
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkqodE0ACgkQ84KuGfSFAYCZ5ACgsoQOVuMjUztgc8ezEUpiEkDg
sDoAn3TTbkUmhLFoosc/vdhI7n3xZfff
=4v7I
-----END PGP SIGNATURE-----
>From 587f0edadfcadc708f6144de37a0653e81518484 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 9 Sep 2009 21:34:32 -0600
Subject: [PATCH] strndup: fix improper m4 caching
* m4/strndup.m4 (gl_FUNC_STRNDUP): Rework to avoid side effects
inside AC_CACHE_CHECK. Use REPLACE_STRNDUP, not HAVE_STRNDUP.
(gl_PREREQ_STRNDUP): Delete.
* m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Update default.
* modules/string (Makefile.am): Substitute it.
* lib/string.in.h (strndup): Modernize prototype.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++++
lib/string.in.h | 4 ++--
m4/string_h.m4 | 4 ++--
m4/strndup.m4 | 46 +++++++++++++++++++++-------------------------
modules/string | 2 +-
5 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b5b4494..a9664bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2009-09-09 Eric Blake <address@hidden>
+ strndup: fix improper m4 caching
+ * m4/strndup.m4 (gl_FUNC_STRNDUP): Rework to avoid side effects
+ inside AC_CACHE_CHECK. Use REPLACE_STRNDUP, not HAVE_STRNDUP.
+ (gl_PREREQ_STRNDUP): Delete.
+ * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Update default.
+ * modules/string (Makefile.am): Substitute it.
+ * lib/string.in.h (strndup): Modernize prototype.
+
getcwd: port to mingw
* m4/getcwd.m4 (gl_FUNC_GETCWD): Mingw directories are very
different from the POSIX assumptions made throughout the getcwd
diff --git a/lib/string.in.h b/lib/string.in.h
index 89c23c7..04deb42 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -203,11 +203,11 @@ extern char *strdup (char const *__s);
/* Return a newly allocated copy of at most N bytes of STRING. */
#if @GNULIB_STRNDUP@
-# if ! @HAVE_STRNDUP@
+# if @REPLACE_STRNDUP@
# undef strndup
# define strndup rpl_strndup
# endif
-# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
+# if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
extern char *strndup (char const *__string, size_t __n);
# endif
#elif defined GNULIB_POSIXCHECK
diff --git a/m4/string_h.m4 b/m4/string_h.m4
index 3dbbfe1..edc5c6e 100644
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -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 8
+# serial 9
# Written by Paul Eggert.
@@ -74,7 +74,6 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY])
HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL])
HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP])
- HAVE_STRNDUP=1; AC_SUBST([HAVE_STRNDUP])
HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP])
HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN])
HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK])
@@ -90,6 +89,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR])
REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
+ REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP])
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])
diff --git a/m4/strndup.m4 b/m4/strndup.m4
index 4fa7d5a..437e7f6 100644
--- a/m4/strndup.m4
+++ b/m4/strndup.m4
@@ -1,4 +1,4 @@
-# strndup.m4 serial 16
+# strndup.m4 serial 17
dnl Copyright (C) 2002-2003, 2005-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -9,17 +9,20 @@ AC_DEFUN([gl_FUNC_STRNDUP],
dnl Persuade glibc <string.h> to declare strndup().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_CHECK_DECLS_ONCE([strndup])
+ AC_CHECK_FUNCS_ONCE([strndup])
if test $ac_cv_have_decl_strndup = no; then
HAVE_DECL_STRNDUP=0
fi
- # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
- AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup],
- [AC_RUN_IFELSE([
- AC_LANG_PROGRAM([[#include <string.h>
- #include <stdlib.h>]], [[
+ if test $ac_cv_func_strndup = yes; then
+ # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating
'\0'.
+ AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
+ [AC_RUN_IFELSE([
+ AC_LANG_PROGRAM([[#include <string.h>
+ #include <stdlib.h>]], [[
#ifndef HAVE_DECL_STRNDUP
extern char *strndup (const char *, size_t);
#endif
@@ -28,26 +31,19 @@ AC_DEFUN([gl_FUNC_STRNDUP],
free (s);
s = strndup ("shorter string", 13);
return s[13] != '\0';]])],
- [gl_cv_func_strndup=yes],
- [gl_cv_func_strndup=no],
- [AC_CHECK_FUNC([strndup],
- [AC_EGREP_CPP([too risky], [
-#ifdef _AIX
- too risky
-#endif
- ],
- [gl_cv_func_strndup=no],
- [gl_cv_func_strndup=yes])],
- [gl_cv_func_strndup=no])])])
- if test $gl_cv_func_strndup = yes; then
- AC_DEFINE([HAVE_STRNDUP], [1],
- [Define if you have the strndup() function and it works.])
+ [gl_cv_func_strndup_works=yes],
+ [gl_cv_func_strndup_works=no],
+ [case $host_os in
+ aix*) gl_cv_func_strndup_works="guessing no";;
+ *) gl_cv_func_strndup_works="guessing yes";;
+ esac])])
+ case $gl_cv_func_strndup_works in
+ *no)
+ REPLACE_STRNDUP=1
+ AC_LIBOBJ([strndup])
+ ;;
+ esac
else
- HAVE_STRNDUP=0
AC_LIBOBJ([strndup])
- gl_PREREQ_STRNDUP
fi
])
-
-# Prerequisites of lib/strndup.c.
-AC_DEFUN([gl_PREREQ_STRNDUP], [:])
diff --git a/modules/string b/modules/string
index 9bafa7e..7a6ed94 100644
--- a/modules/string
+++ b/modules/string
@@ -66,7 +66,6 @@ string.h: string.in.h
-e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \
-e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \
-e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \
- -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \
-e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \
-e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \
-e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \
@@ -82,6 +81,7 @@ string.h: string.in.h
-e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \
-e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
-e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
+ -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|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' \
--
1.6.3.3.334.g916e1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- strndup.m4 cleanup,
Eric Blake <=