mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-08 18:36:17 +01:00
Remove posix_memalign() checks for an old glibc bug
POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS was added in https://bugzilla.gnome.org/show_bug.cgi?id=328254 to work around a glibc bug where it wrongly checked the size argument to be a power of two instead of the alignment. This was fixed in glibc in https://sourceware.org/git/?p=glibc.git;a=commit;h=b2bffca2e3b59dd882039e3b0ab835d127bdaf7a about 16 years ago.
This commit is contained in:
parent
e03f83212d
commit
fe59a18f89
@ -689,9 +689,6 @@
|
||||
/* Define to the version of this package. */
|
||||
#mesondefine PACKAGE_VERSION
|
||||
|
||||
/* define if posix_memalign() can allocate any size */
|
||||
#mesondefine POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS
|
||||
|
||||
/* The size of `char', as computed by sizeof. */
|
||||
#mesondefine SIZEOF_CHAR
|
||||
|
||||
|
@ -704,9 +704,6 @@
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "@GLIB_MAJOR_VERSION@.@GLIB_MINOR_VERSION@.@GLIB_MICRO_VERSION@"
|
||||
|
||||
/* define if posix_memalign() can allocate any size */
|
||||
/* #undef POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS */
|
||||
|
||||
/* The size of `char', as computed by sizeof. */
|
||||
#define SIZEOF_CHAR 1
|
||||
|
||||
|
42
configure.ac
42
configure.ac
@ -1335,48 +1335,6 @@ if test x$glib_cv_langinfo_abaltmon = xyes; then
|
||||
fi
|
||||
AC_LANG_RESTORE
|
||||
|
||||
dnl ****************************************
|
||||
dnl *** posix_memalign ***
|
||||
dnl ****************************************
|
||||
AC_MSG_CHECKING(for a compliant posix_memalign() implementation)
|
||||
AC_CACHE_VAL(glib_cv_compliant_posix_memalign,[
|
||||
glib_cv_compliant_posix_memalign=0
|
||||
if test "$ac_cv_func_posix_memalign" = "yes" ; then
|
||||
AC_TRY_RUN([
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <stdlib.h> /* posix_memalign() should be defined here */
|
||||
/* some systems break if #include <malloc.h> used */
|
||||
static void test_memalign (size_t boundary, size_t size) {
|
||||
void *mem = 0;
|
||||
if (posix_memalign (&mem, boundary, size) != 0 || !mem)
|
||||
exit (1);
|
||||
else
|
||||
free (mem);
|
||||
}
|
||||
int main() {
|
||||
test_memalign ( 128, 128 - 2 * sizeof (void*));
|
||||
test_memalign ( 256, 256 - 2 * sizeof (void*));
|
||||
test_memalign ( 512, 512 - 2 * sizeof (void*));
|
||||
test_memalign ( 1024, 1024 - 2 * sizeof (void*));
|
||||
test_memalign ( 2048, 2048 - 2 * sizeof (void*));
|
||||
test_memalign ( 4096, 4096 - 2 * sizeof (void*));
|
||||
test_memalign ( 8192, 8192 - 2 * sizeof (void*));
|
||||
test_memalign (16384, 16384 - 2 * sizeof (void*));
|
||||
test_memalign (32768, 32768 - 2 * sizeof (void*));
|
||||
exit (0); /* success */
|
||||
}
|
||||
],
|
||||
[glib_cv_compliant_posix_memalign=1], [], [:])
|
||||
:
|
||||
fi
|
||||
])
|
||||
AS_IF([test "$glib_cv_compliant_posix_memalign" = "1"], [
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS, 1, [define if posix_memalign() can allocate any size])
|
||||
], [
|
||||
AC_MSG_RESULT(no)
|
||||
])
|
||||
|
||||
|
||||
dnl ****************************************
|
||||
dnl *** strlcpy/strlcat ***
|
||||
|
@ -19,11 +19,7 @@
|
||||
#include "config.h"
|
||||
#include "glibconfig.h"
|
||||
|
||||
#if defined HAVE_POSIX_MEMALIGN && defined POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS
|
||||
# define HAVE_COMPLIANT_POSIX_MEMALIGN 1
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COMPLIANT_POSIX_MEMALIGN) && !defined(_XOPEN_SOURCE)
|
||||
#if defined(HAVE_POSIX_MEMALIGN) && !defined(_XOPEN_SOURCE)
|
||||
#define _XOPEN_SOURCE 600 /* posix_memalign() */
|
||||
#endif
|
||||
#include <stdlib.h> /* posix_memalign() */
|
||||
@ -416,7 +412,7 @@ g_slice_init_nomessage (void)
|
||||
mem_assert ((sys_page_size & (sys_page_size - 1)) == 0);
|
||||
slice_config_init (&allocator->config);
|
||||
allocator->min_page_size = sys_page_size;
|
||||
#if HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN
|
||||
#if HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN
|
||||
/* allow allocation of pages up to 8KB (with 8KB alignment).
|
||||
* this is useful because many medium to large sized structures
|
||||
* fit less than 8 times (see [4]) into 4KB pages.
|
||||
@ -1394,13 +1390,12 @@ slab_allocator_free_chunk (gsize chunk_size,
|
||||
|
||||
/* from config.h:
|
||||
* define HAVE_POSIX_MEMALIGN 1 // if free(posix_memalign(3)) works, <stdlib.h>
|
||||
* define HAVE_COMPLIANT_POSIX_MEMALIGN 1 // if free(posix_memalign(3)) works for sizes != 2^n, <stdlib.h>
|
||||
* define HAVE_MEMALIGN 1 // if free(memalign(3)) works, <malloc.h>
|
||||
* define HAVE_VALLOC 1 // if free(valloc(3)) works, <stdlib.h> or <malloc.h>
|
||||
* if none is provided, we implement malloc(3)-based alloc-only page alignment
|
||||
*/
|
||||
|
||||
#if !(HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC)
|
||||
#if !(HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC)
|
||||
static GTrashStack *compat_valloc_trash = NULL;
|
||||
#endif
|
||||
|
||||
@ -1410,7 +1405,7 @@ allocator_memalign (gsize alignment,
|
||||
{
|
||||
gpointer aligned_memory = NULL;
|
||||
gint err = ENOMEM;
|
||||
#if HAVE_COMPLIANT_POSIX_MEMALIGN
|
||||
#if HAVE_POSIX_MEMALIGN
|
||||
err = posix_memalign (&aligned_memory, alignment, memsize);
|
||||
#elif HAVE_MEMALIGN
|
||||
errno = 0;
|
||||
@ -1454,7 +1449,7 @@ static void
|
||||
allocator_memfree (gsize memsize,
|
||||
gpointer mem)
|
||||
{
|
||||
#if HAVE_COMPLIANT_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC
|
||||
#if HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_VALLOC
|
||||
free (mem);
|
||||
#else
|
||||
mem_assert (memsize <= sys_page_size);
|
||||
|
Loading…
Reference in New Issue
Block a user