diff options
author | Bruno Haible <bruno@clisp.org> | 2020-12-31 22:16:52 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-12-31 22:16:52 +0100 |
commit | ee523efd38e33c3d7acb77ea8c5941c88d54a8cb (patch) | |
tree | bf13b90cebe1dd9f3b96bf690d562aa329a20804 | |
parent | d943f7dc4666bea8ae6747e6240208f2eea348fa (diff) | |
download | gnulib-ee523efd38e33c3d7acb77ea8c5941c88d54a8cb.tar.gz |
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.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | doc/glibc-headers/malloc.texi | 29 | ||||
-rw-r--r-- | doc/gnulib.texi | 2 | ||||
-rw-r--r-- | lib/malloc.in.h | 69 | ||||
-rw-r--r-- | m4/malloc_h.m4 | 47 | ||||
-rw-r--r-- | modules/malloc-h | 46 |
6 files changed, 202 insertions, 0 deletions
@@ -1,5 +1,14 @@ 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. * lib/unistd.in.h (fchownat, unlinkat): Fix module name in warning. diff --git a/doc/glibc-headers/malloc.texi b/doc/glibc-headers/malloc.texi new file mode 100644 index 0000000000..2fb66fe656 --- /dev/null +++ b/doc/glibc-headers/malloc.texi @@ -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 diff --git a/doc/gnulib.texi b/doc/gnulib.texi index d646d6de1c..f0b48682f2 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -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 index 0000000000..a4360fcf3d --- /dev/null +++ b/lib/malloc.in.h @@ -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 index 0000000000..f8cd17018b --- /dev/null +++ b/m4/malloc_h.m4 @@ -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 index 0000000000..115b870642 --- /dev/null +++ b/modules/malloc-h @@ -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 |