bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* memalign: Work around Solaris bug
@ 2020-12-31 21:21 Bruno Haible
  2020-12-31 21:25 ` Jeffrey Walton
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2020-12-31 21:21 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]

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  <bruno@clisp.org>

	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 <malloc.h> 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.


[-- Attachment #2: 0001-malloc-h-New-module.patch --]
[-- Type: text/x-patch, Size: 8277 bytes --]

From ee523efd38e33c3d7acb77ea8c5941c88d54a8cb Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
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  <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 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 <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 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 <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 0000000..115b870
--- /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
-- 
2.7.4


[-- Attachment #3: 0002-malloc-h-Add-tests.patch --]
[-- Type: text/x-patch, Size: 4348 bytes --]

From ec9385e0feffe6257bba8c47a568fcdddb8d5772 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
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  <bruno@clisp.org>
 
+	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 <malloc.h> 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
+
+#define GNULIB_NAMESPACE gnulib
+#include <config.h>
+
+#include <malloc.h>
+
+#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 <malloc.h> 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
+
+#include <config.h>
+
+#include <malloc.h>
+
+int
+main (void)
+{
+  return 0;
+}
-- 
2.7.4


[-- Attachment #4: 0003-memalign-Work-around-Solaris-bug.patch --]
[-- Type: text/x-patch, Size: 5837 bytes --]

From 3374e597f208292530d40d180f32b6bbbafd7586 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
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 <malloc.h> 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  <bruno@clisp.org>
 
+	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 <malloc.h> 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{<stdlib.h>} instead of @code{<malloc.h>}
+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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <malloc.h>
+
+#include <stdlib.h>
+
+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 <malloc.h>
+              #include <stdlib.h>
+            ]],
+            [[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 <malloc.h>
-#endif
 
 License:
 LGPLv2+
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: memalign: Work around Solaris bug
  2020-12-31 21:21 memalign: Work around Solaris bug Bruno Haible
@ 2020-12-31 21:25 ` Jeffrey Walton
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Walton @ 2020-12-31 21:25 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib@gnu.org List

On Thu, Dec 31, 2020 at 4:21 PM Bruno Haible <bruno@clisp.org> wrote:
>
> 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.)

AIX may be the same. Heap memory is aligned to 4 by default, not 16.

I don't know what happens with, say, posix_memalign. I don't think
I've ever asked for an alignment of 1 or 2 when using it on AIX.

Jeff


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-31 21:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-31 21:21 memalign: Work around Solaris bug Bruno Haible
2020-12-31 21:25 ` Jeffrey Walton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).