Discussion:
[PATCH] strerror_r-posix: Fix override of AC_FUNC_STRERROR_R
(too old to reply)
Eric Blake
2016-11-04 20:43:15 UTC
Permalink
Raw Message
Requiring autoconf's AC_FUNC_STRERROR_R and then calling AC_DEFINE
ourselves leads to two insertions of #define STRERROR_R_CHAR_P
in confdefs.h, but with different values (at least on glibc). This
in turn sparks a gcc warning about redeclaring the macro, and kills
any subsequent tests that use -Werror (which now error because of
the conflicting define, whether or not the test used to error).

A better approach is to replace the autoconf macro with a version
of our own that doesn't probe anything, so that the AC_DEFINE is
reached exactly once.

* m4/strerror_r.m4 (AC_FUNC_STRERROR_R): New override.
(gl_FUNC_STRERROR_R): Don't reuse AC_DEFINE() with a potentially
different value.

Signed-off-by: Eric Blake <***@redhat.com>
---
ChangeLog | 7 +++++++
m4/strerror_r.m4 | 13 ++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e5d7987..4837fe2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-11-04 Eric Blake <***@redhat.com>
+
+ strerror_r-posix: Fix override of AC_FUNC_STRERROR_R
+ * m4/strerror_r.m4 (AC_FUNC_STRERROR_R): New override.
+ (gl_FUNC_STRERROR_R): Don't reuse AC_DEFINE() with a potentially
+ different value.
+
2016-11-03 Eric Blake <***@redhat.com>

bootstrap: Fix get_version() for AIX 5.3
diff --git a/m4/strerror_r.m4 b/m4/strerror_r.m4
index 06c51e1..c566f38 100644
--- a/m4/strerror_r.m4
+++ b/m4/strerror_r.m4
@@ -1,4 +1,4 @@
-# strerror_r.m4 serial 16
+# strerror_r.m4 serial 17
dnl Copyright (C) 2002, 2007-2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -41,8 +41,15 @@ AC_DEFUN([gl_FUNC_STRERROR_R],

# Overwrite the findings of AC_FUNC_STRERROR_R (for code that uses that).
AC_REQUIRE([AC_FUNC_STRERROR_R])
- AC_DEFINE([HAVE_DECL_STRERROR_R], [1])
- AC_DEFINE([STRERROR_R_CHAR_P], [0])
+])
+
+# If this module is in use, we unconditionally want POSIX semantics; so
+# replace autoconf's macro with a version that does not probe
+AC_DEFUN([AC_FUNC_STRERROR_R], [
+ AC_DEFINE([HAVE_DECL_STRERROR_R], [1],
+ [Define to 1, since you should have the declaration of strerror_r.])
+ AC_DEFINE([STRERROR_R_CHAR_P], [0],
+ [Define to 0, since strerror_r should not return char *.])
])

# Prerequisites of lib/strerror_r.c.
--
2.7.4
Bruno Haible
2016-11-04 22:50:48 UTC
Permalink
Raw Message
Hi Eric,

Thanks for noticing and fixing this faster than I could.
Post by Eric Blake
A better approach is to replace the autoconf macro with a version
of our own that doesn't probe anything, so that the AC_DEFINE is
reached exactly once.
Yes, agreed.
Post by Eric Blake
+AC_DEFUN([AC_FUNC_STRERROR_R], [
+ AC_DEFINE([HAVE_DECL_STRERROR_R], [1],
+ [Define to 1, since you should have the declaration of strerror_r.])
+ AC_DEFINE([STRERROR_R_CHAR_P], [0],
+ [Define to 0, since strerror_r should not return char *.])
])
In this definition I would also add

AC_DEFINE([HAVE_STRERROR_R], [1],
[Define to 1, since you should have the function strerror_r.])

Rationale: The autoconf documentation says that AC_FUNC_STRERROR_R
defines HAVE_STRERROR_R too. The user's configure.ac may possibly
- invoke or AC_REQUIRE AC_FUNC_STRERROR_R,
- then rely on the value of HAVE_STRERROR_R,
- then only invoke gl_INIT.

Bruno
Eric Blake
2016-11-12 20:50:44 UTC
Permalink
Raw Message
Post by Bruno Haible
Hi Eric,
Thanks for noticing and fixing this faster than I could.
Post by Eric Blake
A better approach is to replace the autoconf macro with a version
of our own that doesn't probe anything, so that the AC_DEFINE is
reached exactly once.
Yes, agreed.
Post by Eric Blake
+AC_DEFUN([AC_FUNC_STRERROR_R], [
+ AC_DEFINE([HAVE_DECL_STRERROR_R], [1],
+ [Define to 1, since you should have the declaration of strerror_r.])
+ AC_DEFINE([STRERROR_R_CHAR_P], [0],
+ [Define to 0, since strerror_r should not return char *.])
])
In this definition I would also add
AC_DEFINE([HAVE_STRERROR_R], [1],
[Define to 1, since you should have the function strerror_r.])
Okay, I made that change and pushed.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Eric Blake
2016-11-14 21:42:48 UTC
Permalink
Raw Message
Post by Eric Blake
Post by Bruno Haible
Hi Eric,
Thanks for noticing and fixing this faster than I could.
Post by Eric Blake
A better approach is to replace the autoconf macro with a version
of our own that doesn't probe anything, so that the AC_DEFINE is
reached exactly once.
Yes, agreed.
Post by Eric Blake
+AC_DEFUN([AC_FUNC_STRERROR_R], [
+ AC_DEFINE([HAVE_DECL_STRERROR_R], [1],
+ [Define to 1, since you should have the declaration of strerror_r.])
+ AC_DEFINE([STRERROR_R_CHAR_P], [0],
+ [Define to 0, since strerror_r should not return char *.])
])
In this definition I would also add
AC_DEFINE([HAVE_STRERROR_R], [1],
[Define to 1, since you should have the function strerror_r.])
Okay, I made that change and pushed.
Well, it fixed things on glibc systems, but broke it on mingw (where
HAVE_DECL_STRERROR_R is now defined twice). I'm testing a followup patch...
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Loading...