From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DB9B21F4B4 for ; Thu, 31 Dec 2020 21:21:54 +0000 (UTC) Received: from localhost ([::1]:55734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kv5OL-00023W-Bv for normalperson@yhbt.net; Thu, 31 Dec 2020 16:21:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kv5O9-00023O-Kb for bug-gnulib@gnu.org; Thu, 31 Dec 2020 16:21:41 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.24]:27099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kv5O6-0000wj-46 for bug-gnulib@gnu.org; Thu, 31 Dec 2020 16:21:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1609449695; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:From:Subject:Sender; bh=syZKRejVuMtxo0SycUyhO9OuxgHj7dMi3olVfdV1G3c=; b=oM/dLA4E2wXg/3QPK8OK8l7IeRKmLhkxpu7ihmPbXQDJDkrd0lXgV+TUI32c1AxmNQ L8cY5XKCenm6e0MfuuYI337QYCkzCaL5JskNwh9krg233lhIEWSU2FPF5E73p3pjXlTj 4WEnocTNsKYXsUwbXfr8Zrf4RW2mwTWxfDJ6s7Y0PdS+FT3riSFntaXXc1JPPoz5KxZH qCdrG3nh1KcMFP1PprTVJMdz+FRbn7akl6vp2A+eXjuqbYXoun+4QqLSZQysiZF7Ydij Yj8POXmi01e35u2x+AHnzET+3+0Jkjb5nO1USvjpAiwUJkI/MzK+MdW7vNzBc7VDWLSt wdiw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6f3z/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.10.7 DYNA|AUTH) with ESMTPSA id e012d5wBVLLYWVJ (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Thu, 31 Dec 2020 22:21:34 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: memalign: Work around Solaris bug Date: Thu, 31 Dec 2020 22:21:34 +0100 Message-ID: <178830743.E17llfbRSe@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3183730.5PWOzTBtmc" Content-Transfer-Encoding: 7Bit Received-SPF: none client-ip=85.215.255.24; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --nextPart3183730.5PWOzTBtmc Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Solaris 11.4, Solaris OpenIndiana, Solaris OmniOS, I see this test failure: ../../gltests/test-memalign.c:51: assertion 'aligned2_blocks[i] != NULL' failed FAIL test-memalign (exit status: 262) Apparently memalign() does not support alignments 1 and 2 on this platform. This patch fixes it, by using malloc() in these cases. (Bumping the alignment to 4 in these cases would be an alternative workaround.) 2020-12-31 Bruno Haible memalign: Work around Solaris bug. * lib/memalign.c: New file. * m4/memalign.m4: New file. * modules/memalign (Files): Add them. (Depends-on): Add malloc-h. (configure.ac): Invoke gl_FUNC_MEMALIGN. Conditionally compile memalign.c. Set module indicator. (Include): Include unconditionally. * doc/glibc-functions/memalign.texi: Mention the Solaris issues. malloc-h: Add tests. * tests/test-malloc-h.c: New file. * modules/malloc-h-tests: New file. * tests/test-malloc-h-c++.cc: New file. * modules/malloc-h-c++-tests: New file. 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. --nextPart3183730.5PWOzTBtmc Content-Disposition: attachment; filename="0001-malloc-h-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-malloc-h-New-module.patch" >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 --nextPart3183730.5PWOzTBtmc Content-Disposition: attachment; filename="0002-malloc-h-Add-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0002-malloc-h-Add-tests.patch" >From ec9385e0feffe6257bba8c47a568fcdddb8d5772 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 31 Dec 2020 22:17:31 +0100 Subject: [PATCH 2/3] malloc-h: Add tests. * tests/test-malloc-h.c: New file. * modules/malloc-h-tests: New file. * tests/test-malloc-h-c++.cc: New file. * modules/malloc-h-c++-tests: New file. --- ChangeLog | 6 ++++++ modules/malloc-h-c++-tests | 18 ++++++++++++++++++ modules/malloc-h-tests | 11 +++++++++++ tests/test-malloc-h-c++.cc | 35 +++++++++++++++++++++++++++++++++++ tests/test-malloc-h.c | 27 +++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 modules/malloc-h-c++-tests create mode 100644 modules/malloc-h-tests create mode 100644 tests/test-malloc-h-c++.cc create mode 100644 tests/test-malloc-h.c diff --git a/ChangeLog b/ChangeLog index 3490bf5..bc173b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-12-31 Bruno Haible + malloc-h: Add tests. + * tests/test-malloc-h.c: New file. + * modules/malloc-h-tests: New file. + * tests/test-malloc-h-c++.cc: New file. + * modules/malloc-h-c++-tests: New file. + malloc-h: New module. * lib/malloc.in.h: New file. * m4/malloc_h.m4: New file. diff --git a/modules/malloc-h-c++-tests b/modules/malloc-h-c++-tests new file mode 100644 index 0000000..829f9e5 --- /dev/null +++ b/modules/malloc-h-c++-tests @@ -0,0 +1,18 @@ +Files: +tests/test-malloc-h-c++.cc +tests/signature.h + +Status: +c++-test + +Depends-on: +ansi-c++-opt + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-malloc-h-c++ +check_PROGRAMS += test-malloc-h-c++ +test_malloc_h_c___SOURCES = test-malloc-h-c++.cc +endif diff --git a/modules/malloc-h-tests b/modules/malloc-h-tests new file mode 100644 index 0000000..ab26943 --- /dev/null +++ b/modules/malloc-h-tests @@ -0,0 +1,11 @@ +Files: +tests/test-malloc-h.c + +Depends-on: +malloc-h-c++-tests + +configure.ac: + +Makefile.am: +TESTS += test-malloc-h +check_PROGRAMS += test-malloc-h diff --git a/tests/test-malloc-h-c++.cc b/tests/test-malloc-h-c++.cc new file mode 100644 index 0000000..3758f11 --- /dev/null +++ b/tests/test-malloc-h-c++.cc @@ -0,0 +1,35 @@ +/* Test of substitute in C++ mode. + 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 3 of the License, 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 . */ + +/* Written by Bruno Haible , 2020. */ + +#define GNULIB_NAMESPACE gnulib +#include + +#include + +#include "signature.h" + + +#if GNULIB_TEST_MEMALIGN && HAVE_MEMALIGN +SIGNATURE_CHECK (GNULIB_NAMESPACE::memalign, void *, (size_t, size_t)); +#endif + + +int +main () +{ +} diff --git a/tests/test-malloc-h.c b/tests/test-malloc-h.c new file mode 100644 index 0000000..919fac3 --- /dev/null +++ b/tests/test-malloc-h.c @@ -0,0 +1,27 @@ +/* Test of substitute. + 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 3 of the License, 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 . */ + +/* Written by Bruno Haible , 2020. */ + +#include + +#include + +int +main (void) +{ + return 0; +} -- 2.7.4 --nextPart3183730.5PWOzTBtmc Content-Disposition: attachment; filename="0003-memalign-Work-around-Solaris-bug.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0003-memalign-Work-around-Solaris-bug.patch" >From 3374e597f208292530d40d180f32b6bbbafd7586 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 31 Dec 2020 22:18:05 +0100 Subject: [PATCH 3/3] memalign: Work around Solaris bug. * lib/memalign.c: New file. * m4/memalign.m4: New file. * modules/memalign (Files): Add them. (Depends-on): Add malloc-h. (configure.ac): Invoke gl_FUNC_MEMALIGN. Conditionally compile memalign.c. Set module indicator. (Include): Include unconditionally. * doc/glibc-functions/memalign.texi: Mention the Solaris issues. --- ChangeLog | 10 ++++++++ doc/glibc-functions/memalign.texi | 7 ++++++ lib/memalign.c | 35 ++++++++++++++++++++++++++++ m4/memalign.m4 | 48 +++++++++++++++++++++++++++++++++++++++ modules/memalign | 11 ++++++--- 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 lib/memalign.c create mode 100644 m4/memalign.m4 diff --git a/ChangeLog b/ChangeLog index bc173b9..7dd4ffd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2020-12-31 Bruno Haible + memalign: Work around Solaris bug. + * lib/memalign.c: New file. + * m4/memalign.m4: New file. + * modules/memalign (Files): Add them. + (Depends-on): Add malloc-h. + (configure.ac): Invoke gl_FUNC_MEMALIGN. Conditionally compile + memalign.c. Set module indicator. + (Include): Include unconditionally. + * doc/glibc-functions/memalign.texi: Mention the Solaris issues. + malloc-h: Add tests. * tests/test-malloc-h.c: New file. * modules/malloc-h-tests: New file. diff --git a/doc/glibc-functions/memalign.texi b/doc/glibc-functions/memalign.texi index 7c07bc6..ec2f533 100644 --- a/doc/glibc-functions/memalign.texi +++ b/doc/glibc-functions/memalign.texi @@ -19,6 +19,13 @@ Gnulib module: memalign Portability problems fixed by Gnulib: @itemize +@item +This function is declared in @code{} instead of @code{} +on some platforms: +Solaris 11. +@item +This function doesn't accept an alignment of 1 or 2 on some platforms: +Solaris 11. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/memalign.c b/lib/memalign.c new file mode 100644 index 0000000..494dfb6 --- /dev/null +++ b/lib/memalign.c @@ -0,0 +1,35 @@ +/* Allocate memory with indefinite extent and specified alignment. + 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 3 of the License, 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 . */ + +#include + +/* Specification. */ +#include + +#include + +void * +memalign (size_t alignment, size_t size) +#undef memalign +{ + if (alignment < 4) + /* The malloc() result has an alignment of at least 4 on all platforms. + On platforms where memalign() exists, malloc() sets errno upon + failure. */ + return malloc (size); + + return memalign (alignment, size); +} diff --git a/m4/memalign.m4 b/m4/memalign.m4 new file mode 100644 index 0000000..a27055f --- /dev/null +++ b/m4/memalign.m4 @@ -0,0 +1,48 @@ +# memalign.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. + +AC_DEFUN([gl_FUNC_MEMALIGN], +[ + AC_REQUIRE([gl_MALLOC_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + + AC_CHECK_FUNCS_ONCE([memalign]) + if test $ac_cv_func_memalign = yes; then + dnl On Solaris 11, memalign (2, n) always returns NULL. + AC_CACHE_CHECK([whether memalign works for small alignments], + [gl_cv_func_memalign_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + ]], + [[int result = 0; + if (memalign (1, 1) == NULL) + result |= 1; + if (memalign (2, 1) == NULL) + result |= 2; + return result; + ]]) + ], + [gl_cv_func_memalign_works=yes], + [gl_cv_func_memalign_works=no], + [case "$host_os" in + # Guess no on Solaris. + solaris*) gl_cv_func_memalign_works="guessing no" ;; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_memalign_works="$gl_cross_guess_normal" ;; + esac + ]) + ]) + case "$gl_cv_func_memalign_works" in + *yes) ;; + *) REPLACE_MEMALIGN=1 ;; + esac + else + dnl The system does not have memalign. + HAVE_MEMALIGN=0 + fi +]) diff --git a/modules/memalign b/modules/memalign index e8a292d..b383d19 100644 --- a/modules/memalign +++ b/modules/memalign @@ -2,18 +2,23 @@ Description: Allocate memory with indefinite extent and specified alignment. Files: +lib/memalign.c +m4/memalign.m4 Depends-on: +malloc-h configure.ac: -AC_CHECK_FUNCS([memalign]) +gl_FUNC_MEMALIGN +if test $REPLACE_MEMALIGN = 1; then + AC_LIBOBJ([memalign]) +fi +gl_MALLOC_MODULE_INDICATOR([memalign]) Makefile.am: Include: -#if HAVE_MEMALIGN #include -#endif License: LGPLv2+ -- 2.7.4 --nextPart3183730.5PWOzTBtmc--