On 2024-11-05 I wrote: > This patch fixes it. It is possible that the same bug still occurs when there > are 2 or more gnulib-tool invocations in the scope of the same configure file; > still need to think about this case.
Indeed, the problem was not completely fixed: The CI reported a GNU libunistring build failure: /usr/bin/ld: test-realloc-posix.o:/LIBUNISTRING/libunistring/build-64/tests/../../tests/test-realloc-posix.c:29: undefined reference to `rpl_realloc' collect2: error: ld returned 1 exit status make[4]: *** [Makefile:11261: test-realloc-posix] Error 1 The problem here is that we have a file tests/realloc.o that is empty. To fix this, one needs to remember two rules: * A function should be defined in a single .o always. Having rpl_realloc defined in stdlib.o in some cases and in realloc.o in some other cases only leads to trouble. (Namely, as seen last time, stdlib.o sits in gllib/ whereas realloc.o sits in gltests/.) * One needs a *_INLINE macro per compilation unit. Like it's done in lib/stdbit.in.h. 2024-11-11 Bruno Haible <br...@clisp.org> realloc-posix: Fix link error (regression 2024-11-04). * doc/extern-inline.texi (extern inline): Mention that one needs a *_INLINE macro per compilation unit. * lib/stdlib.in.h (_GL_REALLOC_INLINE): New macro. (rpl_realloc): Use it. Don't test IN_GNULIB_TESTS. * lib/realloc.c (_GL_REALLOC_INLINE): Define. diff --git a/doc/extern-inline.texi b/doc/extern-inline.texi index 8d88d33e0d..3ebc39cdac 100644 --- a/doc/extern-inline.texi +++ b/doc/extern-inline.texi @@ -82,6 +82,15 @@ inline} so they suffer from code bloat, but they are not mainline platforms and will die out eventually. +In this coding idiom, +you need one @code{AAA_INLINE}-like macro per compilation unit, +not one per header file. +In other words, if the header file @file{aaa.h} defines functions +defined in @file{aaa-foo.c} and @file{aaa-bar.c}, +you need different macros @code{AAA_FOO_INLINE} and @code{AAA_BAR_INLINE}. +Use @code{AAA_FOO_INLINE} for the functions defined in @file{aaa-foo.c}, +and use @code{AAA_BAR_INLINE} for the functions defined in @file{aaa-bar.c}. + @findex _GL_INLINE @code{_GL_INLINE} is a portable alternative to C99 plain @code{inline}. diff --git a/lib/realloc.c b/lib/realloc.c index e1198cf633..31487b5e18 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -21,6 +21,7 @@ #define _GL_USE_STDLIB_ALLOC 1 #include <config.h> +#define _GL_REALLOC_INLINE _GL_EXTERN_INLINE #include <stdlib.h> #include <errno.h> diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 0d3e2cbf94..b4e2e723fc 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -134,6 +134,9 @@ _GL_INLINE_HEADER_BEGIN #ifndef _GL_STDLIB_INLINE # define _GL_STDLIB_INLINE _GL_INLINE #endif +#ifndef _GL_REALLOC_INLINE +# define _GL_REALLOC_INLINE _GL_INLINE +#endif /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers that can be freed by passing them as the Ith argument to the @@ -1461,9 +1464,9 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - " #if @GNULIB_REALLOC_POSIX@ # if @REPLACE_REALLOC_FOR_REALLOC_POSIX@ -# if @REPLACE_REALLOC_FOR_REALLOC_POSIX@ == 2 && !IN_GNULIB_TESTS +# if @REPLACE_REALLOC_FOR_REALLOC_POSIX@ == 2 # define _GL_INLINE_RPL_REALLOC 1 -_GL_STDLIB_INLINE void * +_GL_REALLOC_INLINE void * rpl_realloc (void *ptr, size_t size) { return realloc (ptr, size ? size : 1);