Skip to content

Commit 78c7aec

Browse files
Remove configure code checking for various malloc alignments. Just use aligned_alloc internally instead. Fixes #278.
1 parent b889c39 commit 78c7aec

File tree

4 files changed

+2
-138
lines changed

4 files changed

+2
-138
lines changed

config/ax_check_page_aligned_malloc.m4

Lines changed: 0 additions & 36 deletions
This file was deleted.

config/qthread_check_working_valloc.m4

Lines changed: 0 additions & 41 deletions
This file was deleted.

configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,6 @@ AC_CHECK_FUNCS([strtol memalign posix_memalign memset memmove munmap memcpy fsta
668668
QTHREAD_CHECK_QSORT
669669
AC_CHECK_DECLS([MADV_ACCESS_LWP],[],[],[[#include <sys/types.h>
670670
#include <sys/mman.h>]])
671-
AX_CHECK_PAGE_ALIGNED_MALLOC
672-
QTHREAD_CHECK_WORKING_VALLOC
673671
QTHREAD_CHECK_ASSERT([],[AC_MSG_ERROR([assert() does not seem to work])])
674672

675673
AC_CACHE_SAVE

src/alloc/base.c

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,68 +34,11 @@ void *qt_realloc(void *ptr, size_t size) { return realloc(ptr, size); }
3434
void qt_internal_alignment_init(void) { _pagesize = getpagesize(); }
3535

3636
void *qt_internal_aligned_alloc(size_t alloc_size, uint_fast16_t alignment) {
37-
void *ret;
38-
39-
assert(alloc_size > 0);
40-
switch (alignment) {
41-
case 0: ret = MALLOC(alloc_size); break;
42-
case 16:
43-
case 8:
44-
case 4:
45-
case 2: ret = MALLOC(alloc_size); break;
46-
default:
47-
#if defined(HAVE_WORKING_VALLOC)
48-
if (alignment == pagesize) {
49-
ret = valloc(alloc_size);
50-
break;
51-
}
52-
#elif defined(HAVE_PAGE_ALIGNED_MALLOC)
53-
if (alignment == pagesize) {
54-
ret = MALLOC(alloc_size);
55-
break;
56-
}
57-
#endif
58-
#if defined(HAVE_MEMALIGN)
59-
ret = memalign(alignment, alloc_size);
60-
#elif defined(HAVE_POSIX_MEMALIGN)
61-
posix_memalign(&(ret), alignment, alloc_size);
62-
#else
63-
{
64-
uint8_t *tmp = MALLOC((alloc_size + alignment - 1) + sizeof(void *));
65-
if (!tmp) { return NULL; }
66-
ret = (void *)(((uintptr_t)(tmp + sizeof(void *) + alignment - 1)) &
67-
~(alignment - 1));
68-
*((void **)ret - 1) = tmp;
69-
} break;
70-
#endif /* if defined(HAVE_MEMALIGN) */
71-
}
72-
assert(ret);
73-
assert(((uintptr_t)ret & (alignment - 1)) == 0);
74-
return ret;
37+
return aligned_alloc((size_t) alignment, alloc_size);
7538
}
7639

7740
void qt_internal_aligned_free(void *ptr, uint_fast16_t alignment) {
78-
assert(ptr);
79-
switch (alignment) {
80-
case 0: qt_free(ptr); break;
81-
case 16:
82-
case 8:
83-
case 4:
84-
case 2: qt_free(ptr); break;
85-
default:
86-
#if defined(HAVE_WORKING_VALLOC) || defined(HAVE_PAGE_ALIGNED_MALLOC)
87-
if (alignment == pagesize) {
88-
qt_free(ptr);
89-
break;
90-
}
91-
#endif
92-
#if defined(HAVE_MEMALIGN) || defined(HAVE_POSIX_MEMALIGN)
93-
qt_free(ptr);
94-
#else
95-
assert((uintptr_t) * ((void **)ptr - 1) > 4096);
96-
qt_free(*((void **)ptr - 1));
97-
#endif
98-
}
41+
qt_free(ptr);
9942
}
10043

10144
/* vim:set expandtab: */

0 commit comments

Comments
 (0)