[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: realloc.c on Tru64 4.0D
From: |
Bruno Haible |
Subject: |
Re: realloc.c on Tru64 4.0D |
Date: |
Sun, 28 Oct 2007 05:20:42 +0200 |
User-agent: |
KMail/1.5.4 |
Ralf Wildenhues wrote:
> 2007-10-22 Ralf Wildenhues <address@hidden>
>
> * lib/realloc.c [defined malloc]: Undefine, for prototype
> on Tru64 4.0D. Also define NEED_REALLOC_GNU.
>
> diff --git a/lib/realloc.c b/lib/realloc.c
> index 18cc628..190e554 100644
> --- a/lib/realloc.c
> +++ b/lib/realloc.c
> @@ -23,6 +23,10 @@
> # define NEED_REALLOC_GNU
> # undef realloc
> #endif
> +#ifdef malloc
> +# define NEED_REALLOC_GNU
> +# undef malloc
> +#endif
>
This does not handle all possible cases right:
- If the module 'realloc' is used but the 'malloc' module is not,
and realloc(0) != NULL but malloc(0) == NULL, you also need
NEED_REALLOC_GNU.
- When the modules 'realloc-posix' and 'malloc' are used, but 'realloc' is
not,
there is no need to set NEED_REALLOC_GNU.
- NEED_REALLOC_GNU is overkill when realloc(0) != NULL but malloc(0) == NULL.
Also, too few comments.
How about this?
2007-10-27 Ralf Wildenhues <address@hidden>
Bruno Haible <address@hidden>
* modules/malloc (configure.ac): Define GNULIB_MALLOC_GNU always.
* modules/realloc (configure.ac): Define GNULIB_REALLOC_GNU always.
* lib/realloc.c (SYSTEM_MALLOC_GLIBC_COMPATIBLE): New macro.
(malloc): Undefine also before including <stdlib.h>.
(rpl_realloc): Turn malloc(0) into malloc(1) if necessary.
Needed on OSF/1 4.0.
*** lib/realloc.c.orig 2007-10-28 04:06:03.000000000 +0100
--- lib/realloc.c 2007-10-28 02:32:07.000000000 +0100
***************
*** 18,35 ****
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
#ifdef realloc
! # define NEED_REALLOC_GNU
! # undef realloc
#endif
/* Specification. */
#include <stdlib.h>
#include <errno.h>
! /* Call the system's malloc and realloc below. */
#undef malloc
#undef realloc
--- 18,49 ----
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
+
/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
#ifdef realloc
! # define NEED_REALLOC_GNU 1
! #endif
!
! /* Infer the properties of the system's malloc function.
! Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
! #if GNULIB_MALLOC_GNU && !defined malloc
! # define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
#endif
+ /* Below we want to call the system's malloc and realloc.
+ Undefine the symbols here so that including <stdlib.h> provides a
+ declaration of malloc(), not of rpl_malloc(), and likewise for realloc. */
+ #undef malloc
+ #undef realloc
+
/* Specification. */
#include <stdlib.h>
#include <errno.h>
! /* Below we want to call the system's malloc and realloc.
! Undefine the symbols, if they were defined by gnulib's <stdlib.h>
! replacement. */
#undef malloc
#undef realloc
***************
*** 42,48 ****
{
void *result;
! #ifdef NEED_REALLOC_GNU
if (n == 0)
{
n = 1;
--- 56,62 ----
{
void *result;
! #if NEED_REALLOC_GNU
if (n == 0)
{
n = 1;
***************
*** 53,59 ****
}
#endif
! result = (p == NULL ? malloc (n) : realloc (p, n));
#if !HAVE_REALLOC_POSIX
if (result == NULL)
--- 67,82 ----
}
#endif
! if (p == NULL)
! {
! #if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
! if (n == 0)
! n = 1;
! #endif
! result = malloc (n);
! }
! else
! result = realloc (p, n);
#if !HAVE_REALLOC_POSIX
if (result == NULL)
*** modules/malloc.orig 2007-10-28 04:06:04.000000000 +0100
--- modules/malloc 2007-10-28 02:32:42.000000000 +0100
***************
*** 9,14 ****
--- 9,15 ----
configure.ac:
AC_FUNC_MALLOC
+ AC_DEFINE([GNULIB_MALLOC_GNU], 1, [Define to indicate the 'malloc' module.])
Makefile.am:
*** modules/realloc.orig 2007-10-28 04:06:04.000000000 +0100
--- modules/realloc 2007-10-28 02:32:36.000000000 +0100
***************
*** 9,14 ****
--- 9,15 ----
configure.ac:
AC_FUNC_REALLOC
+ AC_DEFINE([GNULIB_REALLOC_GNU], 1, [Define to indicate the 'realloc' module.])
Makefile.am: