malloc-h: New module.
authorBruno Haible <bruno@clisp.org>
Thu, 31 Dec 2020 21:16:52 +0000 (22:16 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 31 Dec 2020 21:16:52 +0000 (22:16 +0100)
* 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.

ChangeLog
doc/glibc-headers/malloc.texi [new file with mode: 0644]
doc/gnulib.texi
lib/malloc.in.h [new file with mode: 0644]
m4/malloc_h.m4 [new file with mode: 0644]
modules/malloc-h [new file with mode: 0644]

index c9b22fb02dc9f99f5bda7b5b28a5e865202475e1..3490bf5c6e478439caae00fb0a40a41e754344c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/doc/glibc-headers/malloc.texi b/doc/glibc-headers/malloc.texi
new file mode 100644 (file)
index 0000000..2fb66fe
--- /dev/null
@@ -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
index d646d6de1ced30f69aaf4e239217033f32a7ebc8..f0b48682f2aba2c523859a41b9c50a854102911a 100644 (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
diff --git a/lib/malloc.in.h b/lib/malloc.in.h
new file mode 100644 (file)
index 0000000..a4360fc
--- /dev/null
@@ -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 */
diff --git a/m4/malloc_h.m4 b/m4/malloc_h.m4
new file mode 100644 (file)
index 0000000..f8cd170
--- /dev/null
@@ -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])
+])
diff --git a/modules/malloc-h b/modules/malloc-h
new file mode 100644 (file)
index 0000000..115b870
--- /dev/null
@@ -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