1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-08 17:22:05 +03:00

realloc-gnu: Replace module with an alias to realloc-posix.

* tests/test-realloc-posix.c: Renamed from tests/test-realloc-gnu.c. Add
more tests, not yet activated.
* modules/realloc-posix-tests: Renamed from modules/realloc-gnu-tests.
Test test-realloc-posix instead of test-realloc-gnu.
* modules/realloc-gnu: Mark as a deprecated alias of 'realloc-posix'.
* lib/stdlib.in.h (realloc): Ignore GNULIB_REALLOC_GNU.
* modules/stdlib (Makefile.am): Don't substitute GNULIB_REALLOC_GNU,
REPLACE_REALLOC_FOR_REALLOC_GNU.
* m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Don't initialize
GNULIB_REALLOC_GNU.
(gl_STDLIB_H_DEFAULTS): Don't initialize
REPLACE_REALLOC_FOR_REALLOC_GNU.
* m4/realloc.m4 (gl_FUNC_REALLOC_GNU): Remove macro.
* m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Update comment.
* doc/posix-functions/realloc.texi: Remove description of module
'realloc-gnu'.
* MODULES.html.sh (Memory management functions <stdlib.h>): Remove
realloc-gnu. Add realloc-posix.
This commit is contained in:
Bruno Haible
2024-10-28 00:18:35 +01:00
parent c36a0f21b3
commit 6659e01616
12 changed files with 64 additions and 71 deletions

View File

@@ -1,3 +1,25 @@
2024-10-27 Bruno Haible <bruno@clisp.org>
realloc-gnu: Replace module with an alias to realloc-posix.
* tests/test-realloc-posix.c: Renamed from tests/test-realloc-gnu.c. Add
more tests, not yet activated.
* modules/realloc-posix-tests: Renamed from modules/realloc-gnu-tests.
Test test-realloc-posix instead of test-realloc-gnu.
* modules/realloc-gnu: Mark as a deprecated alias of 'realloc-posix'.
* lib/stdlib.in.h (realloc): Ignore GNULIB_REALLOC_GNU.
* modules/stdlib (Makefile.am): Don't substitute GNULIB_REALLOC_GNU,
REPLACE_REALLOC_FOR_REALLOC_GNU.
* m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Don't initialize
GNULIB_REALLOC_GNU.
(gl_STDLIB_H_DEFAULTS): Don't initialize
REPLACE_REALLOC_FOR_REALLOC_GNU.
* m4/realloc.m4 (gl_FUNC_REALLOC_GNU): Remove macro.
* m4/malloc.m4 (gl_CHECK_MALLOC_POSIX): Update comment.
* doc/posix-functions/realloc.texi: Remove description of module
'realloc-gnu'.
* MODULES.html.sh (Memory management functions <stdlib.h>): Remove
realloc-gnu. Add realloc-posix.
2024-10-27 Bruno Haible <bruno@clisp.org>
doc: Add a module index.

View File

@@ -1738,7 +1738,7 @@ func_all_modules ()
func_module free-posix
func_module malloc-gnu
func_module memalign
func_module realloc-gnu
func_module realloc-posix
func_module reallocarray
func_module pagealign_alloc
func_end_table

View File

@@ -99,20 +99,3 @@ even though POSIX.1-2024 requires this:
glibc 2.1.1--2.40, most likely glibc 2.41+ at least by default,
Android, mingw, MSVC.
@end itemize
@mindex realloc-gnu
Extension: Gnulib provides a module @samp{realloc-gnu} that substitutes a
@code{realloc} implementation that behaves more like the current
glibc implementation.
It fixes these portability problems:
@itemize
@item
@code{realloc (NULL, 0)} returns @code{NULL} on success on some platforms:
AIX 7.3.
@item
On some platforms, @code{realloc (p, 0)} with non-null @code{p}
might not free @code{p}, or might clobber @code{errno},
or might not return @code{NULL}.
@end itemize

View File

@@ -1454,8 +1454,7 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
#if @GNULIB_REALLOC_POSIX@
# if (@GNULIB_REALLOC_POSIX@ && @REPLACE_REALLOC_FOR_REALLOC_POSIX@) \
|| (@GNULIB_REALLOC_GNU@ && @REPLACE_REALLOC_FOR_REALLOC_GNU@)
# if (@GNULIB_REALLOC_POSIX@ && @REPLACE_REALLOC_FOR_REALLOC_POSIX@)
# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
|| _GL_USE_STDLIB_ALLOC)
# undef realloc

View File

@@ -1,5 +1,5 @@
# malloc.m4
# serial 34
# serial 35
dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -134,7 +134,7 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX],
dnl some systems go to their knees when you do that. So assume that
dnl all Unix implementations of the function set errno on failure,
dnl except on those platforms where we have seen 'test-malloc-gnu',
dnl 'test-realloc-gnu', 'test-calloc-gnu' fail.
dnl 'test-realloc-posix', 'test-calloc-gnu' fail.
case "$host_os" in
mingw* | windows*)
gl_cv_func_malloc_posix=no ;;

View File

@@ -1,5 +1,5 @@
# realloc.m4
# serial 33
# serial 34
dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -51,25 +51,6 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
])# AC_FUNC_REALLOC
# gl_FUNC_REALLOC_GNU
# -------------------
# Replace realloc if it is not compatible with GNU libc.
AC_DEFUN([gl_FUNC_REALLOC_GNU],
[
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
dnl Through the dependency on module extensions-aix, _LINUX_SOURCE_COMPAT
dnl gets defined already before this macro gets invoked. This helps
dnl if !(__VEC__ || __AIXVEC), and doesn't hurt otherwise.
AC_REQUIRE([gl_FUNC_REALLOC_SANITIZED])
if test "$gl_cv_func_realloc_sanitize" = no \
&& test $REPLACE_REALLOC_FOR_REALLOC_GNU = 0; then
_AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC_FOR_REALLOC_GNU=1])
fi
])# gl_FUNC_REALLOC_GNU
# gl_FUNC_REALLOC_POSIX
# ---------------------
# Test whether 'realloc' is POSIX compliant (sets errno to ENOMEM when it

View File

@@ -1,5 +1,5 @@
# stdlib_h.m4
# serial 81
# serial 82
dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -141,7 +141,6 @@ AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS],
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM_R])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOCARRAY])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOC_GNU])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOC_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALPATH])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RPMATCH])
@@ -248,7 +247,6 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
REPLACE_RAND=0; AC_SUBST([REPLACE_RAND])
REPLACE_RANDOM=0; AC_SUBST([REPLACE_RANDOM])
REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R])
REPLACE_REALLOC_FOR_REALLOC_GNU=0; AC_SUBST([REPLACE_REALLOC_FOR_REALLOC_GNU])
REPLACE_REALLOC_FOR_REALLOC_POSIX=0; AC_SUBST([REPLACE_REALLOC_FOR_REALLOC_POSIX])
REPLACE_REALLOCARRAY=0; AC_SUBST([REPLACE_REALLOCARRAY])
REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])

View File

@@ -1,22 +1,18 @@
Description:
realloc() function that is glibc compatible.
Status:
deprecated
Notice:
This module is deprecated. Use the module 'filename' instead.
Files:
lib/realloc.c
Depends-on:
realloc-posix
extensions-aix
free-posix [test $REPLACE_REALLOC_FOR_REALLOC_GNU = 1]
malloc-gnu [test $REPLACE_REALLOC_FOR_REALLOC_GNU = 1]
xalloc-oversized [test $REPLACE_REALLOC_FOR_REALLOC_GNU = 1]
configure.ac:
gl_FUNC_REALLOC_GNU
if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 1; then
AC_LIBOBJ([realloc])
fi
gl_STDLIB_MODULE_INDICATOR([realloc-gnu])
Makefile.am:
@@ -27,4 +23,4 @@ License:
LGPLv2+
Maintainer:
Jim Meyering
all

View File

@@ -1,12 +0,0 @@
Files:
tests/test-realloc-gnu.c
tests/macros.h
Depends-on:
stdint
configure.ac:
Makefile.am:
TESTS += test-realloc-gnu
check_PROGRAMS += test-realloc-gnu

View File

@@ -0,0 +1,12 @@
Files:
tests/test-realloc-posix.c
tests/macros.h
Depends-on:
stdint
configure.ac:
Makefile.am:
TESTS += test-realloc-posix
check_PROGRAMS += test-realloc-posix

View File

@@ -66,7 +66,6 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
-e 's/@''GNULIB_RAND''@/$(GNULIB_RAND)/g' \
-e 's/@''GNULIB_RANDOM''@/$(GNULIB_RANDOM)/g' \
-e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \
-e 's/@''GNULIB_REALLOC_GNU''@/$(GNULIB_REALLOC_GNU)/g' \
-e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \
-e 's/@''GNULIB_REALLOCARRAY''@/$(GNULIB_REALLOCARRAY)/g' \
-e 's/@''GNULIB_REALPATH''@/$(GNULIB_REALPATH)/g' \
@@ -168,7 +167,6 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
-e 's|@''REPLACE_RAND''@|$(REPLACE_RAND)|g' \
-e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
-e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
-e 's|@''REPLACE_REALLOC_FOR_REALLOC_GNU''@|$(REPLACE_REALLOC_FOR_REALLOC_GNU)|g' \
-e 's|@''REPLACE_REALLOC_FOR_REALLOC_POSIX''@|$(REPLACE_REALLOC_FOR_REALLOC_POSIX)|g' \
-e 's|@''REPLACE_REALLOCARRAY''@|$(REPLACE_REALLOCARRAY)|g' \
-e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \

View File

@@ -27,9 +27,25 @@
int
main (int argc, _GL_UNUSED char **argv)
{
void *volatile p;
/* Check that realloc (NULL, 0) is not a NULL pointer. */
void *volatile p = realloc (NULL, 0);
p = realloc (NULL, 0);
ASSERT (p != NULL);
#ifdef NOT_YET
free (p);
/* Check that realloc (p, 0) for non-NULL p is not a NULL pointer. */
p = malloc (200);
p = realloc (p, 0);
ASSERT (p != NULL);
free (p);
/* Check that realloc (p, 0) for non-NULL p is not a NULL pointer. */
p = malloc (2 * 1024 * 1024);
p = realloc (p, 0);
ASSERT (p != NULL);
#endif
/* Check that realloc (p, n) fails when p is non-null and n exceeds
PTRDIFF_MAX. */