summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorDouglas Mencken <dougmencken@gmail.com>2014-03-30 02:32:16 -0400
committerStephan Bergmann <sbergman@redhat.com>2014-04-01 07:55:36 +0000
commitdfc2e4573157abcb70418f9c7738acda63602ddd (patch)
tree14ba6644d450768d8bb8d2ad3b05ebecc024d172 /sal
parentac1e33b069e0fb9136ac1e0807610adb4b2990ee (diff)
sal: add aligned memory allocation with malloc for OS X < 10.6
Note that posix_memalign is not available everywhere (as are its replacements like memalign). For example, Darwin/OSX <10.6 has neither posix_memalign or memalign. Incorporating changes by Stephan Bergmann <sbergman@redhat.com>. Change-Id: I4a02b40c36d353c2b7a78d0bacb3b14e1f2d94da Reviewed-on: https://gerrit.libreoffice.org/8405 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/memory.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sal/osl/unx/memory.c b/sal/osl/unx/memory.c
index ca241b10d103..bde2fac83273 100644
--- a/sal/osl/unx/memory.c
+++ b/sal/osl/unx/memory.c
@@ -16,25 +16,36 @@
void* osl_aligned_alloc( sal_Size align, sal_Size size )
{
-#ifdef __ANDROID__
- return memalign(align, size);
-#else
if (size == 0)
{
return NULL;
}
else
{
+#if defined __ANDROID__
+ return memalign(align, size);
+#elif defined MAC_OS_X_VERSION_MAX_ALLOWED && MAC_OS_X_VERSION_MAX_ALLOWED < 1060
+ void* ptr = malloc(size + (align - 1) + sizeof(void*));
+ if (!ptr) return NULL;
+ char* aptr = ((char*)ptr) + sizeof(void*);
+ aptr += (align - ((size_t)aptr & (align - 1))) & (align - 1);
+ ((void**)aptr)[-1] = ptr;
+ return aptr;
+#else
void* ptr;
int err = posix_memalign(&ptr, align, size);
return err ? NULL : ptr;
- }
#endif
+ }
}
void osl_aligned_free( void* p )
{
+#if defined __APPLE__ && MAC_OS_X_VERSION_MAX_ALLOWED < 1060
+ free(((void**)p)[-1]);
+#else
free(p);
+#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */