>From ee523efd38e33c3d7acb77ea8c5941c88d54a8cb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 31 Dec 2020 22:16:52 +0100 Subject: [PATCH 1/3] 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. --- ChangeLog | 9 ++++++ doc/glibc-headers/malloc.texi | 29 ++++++++++++++++++ doc/gnulib.texi | 2 ++ lib/malloc.in.h | 69 +++++++++++++++++++++++++++++++++++++++++++ m4/malloc_h.m4 | 47 +++++++++++++++++++++++++++++ modules/malloc-h | 46 +++++++++++++++++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 doc/glibc-headers/malloc.texi create mode 100644 lib/malloc.in.h create mode 100644 m4/malloc_h.m4 create mode 100644 modules/malloc-h diff --git a/ChangeLog b/ChangeLog index c9b22fb..3490bf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2020-12-31 Bruno Haible + 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 + 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 0000000..2fb66fe --- /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 d646d6d..f0b4868 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 0000000..a4360fc --- /dev/null +++ b/lib/malloc.in.h @@ -0,0 +1,69 @@ +/* Substitute for and wrapper around . + 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 . */ + +#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 , not in . + Also get size_t. */ +#include + +/* 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 0000000..f8cd170 --- /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 +#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 0000000..115b870 --- /dev/null +++ b/modules/malloc-h @@ -0,0 +1,46 @@ +Description: +A 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 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: + + +License: +LGPLv2+ + +Maintainer: +all -- 2.7.4