A gettext bug report <https://savannah.gnu.org/bugs/?65958>
found that GNU gettext, when compiled on mingw with builddir = srcdir,
produces a compilation error due to the symbol
'close_used_without_requesting_gnulib_module_close'.
What happens, is that:
* Under the scope of the same configure.ac, there are two gnulib-tool
invocations:
- one that produces gnulib-lib/unistd.h, with module 'close'
included and thus @GNULIB_CLOSE@ expanding to 1,
- one that produces libgrep/unistd.h, with module 'close' excluded
and thus @GNULIB_CLOSE@ expanding to 0.
This is supported since April 2021.
* The -I options mention directory libgrep before directory gnulib-lib.
Thus, in the #include_next chain, both unistd.h files are included,
and the outermost one is libgrep/unistd.h.
* Thus, the prevailing definition of the symbol 'close' is the one
from libgrep/unistd.h, namely
#define close close_used_without_requesting_gnulib_module_close
But it is wrong to assume that if gnulib module 'close' is not used
in *this* gnulib-tool invocation, it is not used in other gnulib-tool
invocations either.
The fix is therefore to avoid doing
#define close close_used_without_requesting_gnulib_module_close
if at least one of the gnulib-tool invocations used module 'close'.
The patch below does this. It thus avoids the error, if the -I options
are so that multiple unistd.h files are included. It _may_ omit a
safeguard if there is only one -I option; but a missed safeguard is
better than a false error.
2024-07-24 Bruno Haible <[email protected]>
Avoid false error close_used_without_requesting_gnulib_module_close.
Reported by Frédéric at <https://savannah.gnu.org/bugs/?65958>.
* modules/close (configure.ac): Invoke gl_MODULE_INDICATOR.
* lib/unistd.in.h (close): Don't define to
close_used_without_requesting_gnulib_module_close if the gnulib module
'close' is in use under the same configure.ac.
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index e01629af25..688988e9e2 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -412,8 +412,10 @@ _GL_CXXALIAS_SYS (close, int, (int fd));
# endif
_GL_CXXALIASWARN (close);
#elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
-# undef close
-# define close close_used_without_requesting_gnulib_module_close
+# if !GNULIB_CLOSE
+# undef close
+# define close close_used_without_requesting_gnulib_module_close
+# endif
#elif defined GNULIB_POSIXCHECK
# undef close
/* Assume close is always declared. */
diff --git a/modules/close b/modules/close
index 926ea85501..fbb54063c6 100644
--- a/modules/close
+++ b/modules/close
@@ -14,6 +14,7 @@ configure.ac:
gl_FUNC_CLOSE
gl_CONDITIONAL([GL_COND_OBJ_CLOSE], [test $REPLACE_CLOSE = 1])
gl_UNISTD_MODULE_INDICATOR([close])
+gl_MODULE_INDICATOR([close])
Makefile.am:
if GL_COND_OBJ_CLOSE