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

malloc-h: New module.

* lib/malloc.in.h: New file.
* m4/malloc_h.m4: New file.
* modules/malloc-h: New file.
* doc/glibc-headers/malloc.texi: New file.
* doc/gnulib.texi (Glibc Header File Substitutes): Include it.
This commit is contained in:
Bruno Haible
2020-12-31 22:16:52 +01:00
parent d943f7dc46
commit ee523efd38
6 changed files with 202 additions and 0 deletions

View File

@@ -1,3 +1,12 @@
2020-12-31 Bruno Haible <bruno@clisp.org>
malloc-h: New module.
* lib/malloc.in.h: New file.
* m4/malloc_h.m4: New file.
* modules/malloc-h: New file.
* doc/glibc-headers/malloc.texi: New file.
* doc/gnulib.texi (Glibc Header File Substitutes): Include it.
2020-12-31 Bruno Haible <bruno@clisp.org>
unistd: Fix portability warnings.

View File

@@ -0,0 +1,29 @@
@node malloc.h
@section @file{malloc.h}
Declares the function @code{memalign} and functions for customizing the
@code{malloc} behavior.
Documentation:
@itemize
@item
@ifinfo
@ref{Unconstrained Allocation,,,libc},
@end ifinfo
@ifnotinfo
@url{https://www.gnu.org/software/libc/manual/html_node/Unconstrained-Allocation.html}.
@end ifnotinfo
@end itemize
Gnulib module: malloc-h
Portability problems fixed by Gnulib:
@itemize
@item
This header file is missing on some platforms:
Mac OS X 10.13, OpenBSD 6.7.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@end itemize

View File

@@ -3739,6 +3739,7 @@ not worked around by Gnulib.
* ifaddrs.h::
* libintl.h::
* link.h::
* malloc.h::
* mcheck.h::
* mntent.h::
* obstack.h::
@@ -3775,6 +3776,7 @@ not worked around by Gnulib.
@include glibc-headers/ifaddrs.texi
@include glibc-headers/libintl.texi
@include glibc-headers/link.texi
@include glibc-headers/malloc.texi
@include glibc-headers/mcheck.texi
@include glibc-headers/mntent.texi
@include glibc-headers/obstack.texi

69
lib/malloc.in.h Normal file
View File

@@ -0,0 +1,69 @@
/* Substitute for and wrapper around <malloc.h>.
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#ifndef _@GUARD_PREFIX@_MALLOC_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
@PRAGMA_COLUMNS@
/* The include_next requires a split double-inclusion guard. */
#if @HAVE_MALLOC_H@
# @INCLUDE_NEXT@ @NEXT_MALLOC_H@
#endif
#ifndef _@GUARD_PREFIX@_MALLOC_H
#define _@GUARD_PREFIX@_MALLOC_H
/* Solaris declares memalign() in <stdlib.h>, not in <malloc.h>.
Also get size_t. */
#include <stdlib.h>
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
/* The definition of _GL_WARN_ON_USE is copied here. */
/* Declare overridden functions. */
#if @GNULIB_MEMALIGN@
# if @REPLACE_MEMALIGN@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef memalign
# define memalign rpl_memalign
# endif
_GL_FUNCDECL_RPL (memalign, void *, (size_t alignment, size_t size));
_GL_CXXALIAS_RPL (memalign, void *, (size_t alignment, size_t size));
# else
# if @HAVE_MEMALIGN@
_GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size));
# endif
# endif
# if @HAVE_MEMALIGN@
_GL_CXXALIASWARN (memalign);
# endif
#elif defined GNULIB_POSIXCHECK
# undef memalign
# if HAVE_RAW_DECL_MEMALIGN
_GL_WARN_ON_USE (memalign, "memalign is not portable - "
"use gnulib module memalign for portability");
# endif
#endif
#endif /* _@GUARD_PREFIX@_MALLOC_H */
#endif /* _@GUARD_PREFIX@_MALLOC_H */

47
m4/malloc_h.m4 Normal file
View File

@@ -0,0 +1,47 @@
# malloc_h.m4 serial 1
dnl Copyright (C) 2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl Written by Bruno Haible.
AC_DEFUN([gl_MALLOC_H],
[
dnl Use AC_REQUIRE here, so that the default behavior below is expanded
dnl once only, before all statements that occur in other macros.
AC_REQUIRE([gl_MALLOC_H_DEFAULTS])
gl_CHECK_NEXT_HEADERS([malloc.h])
if test $ac_cv_header_malloc_h = yes; then
HAVE_MALLOC_H=1
else
HAVE_MALLOC_H=0
fi
AC_SUBST([HAVE_MALLOC_H])
dnl Check for declarations of anything we want to poison if the
dnl corresponding gnulib module is not in use.
gl_WARN_ON_USE_PREPARE([[
#if HAVE_MALLOC_H
# include <malloc.h>
#endif
]], [memalign])
])
AC_DEFUN([gl_MALLOC_MODULE_INDICATOR],
[
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
AC_REQUIRE([gl_MALLOC_H_DEFAULTS])
gl_MODULE_INDICATOR_SET_VARIABLE([$1])
dnl Define it also as a C macro, for the benefit of the unit tests.
gl_MODULE_INDICATOR_FOR_TESTS([$1])
])
AC_DEFUN([gl_MALLOC_H_DEFAULTS],
[
GNULIB_MEMALIGN=0; AC_SUBST([GNULIB_MEMALIGN])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_MEMALIGN=1; AC_SUBST([HAVE_MEMALIGN])
REPLACE_MEMALIGN=0; AC_SUBST([REPLACE_MEMALIGN])
])

46
modules/malloc-h Normal file
View File

@@ -0,0 +1,46 @@
Description:
A <malloc.h> that works around platform issues.
Files:
lib/malloc.in.h
m4/malloc_h.m4
Depends-on:
include_next
snippet/c++defs
snippet/warn-on-use
configure.ac:
gl_MALLOC_H
Makefile.am:
BUILT_SOURCES += malloc.h
# We need the following in order to create <malloc.h> when we add workarounds.
malloc.h: malloc.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
$(AM_V_GEN)rm -f $@-t $@ && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
-e 's|@''HAVE_MALLOC_H''@|$(HAVE_MALLOC_H)|g' \
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_MALLOC_H''@|$(NEXT_MALLOC_H)|g' \
-e 's/@''GNULIB_MEMALIGN''@/$(GNULIB_MEMALIGN)/g' \
-e 's|@''HAVE_MEMALIGN''@|$(HAVE_MEMALIGN)|g' \
-e 's|@''REPLACE_MEMALIGN''@|$(REPLACE_MEMALIGN)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
< $(srcdir)/malloc.in.h; \
} > $@-t && \
mv $@-t $@
MOSTLYCLEANFILES += malloc.h malloc.h-t
Include:
<malloc.h>
License:
LGPLv2+
Maintainer:
all