summaryrefslogtreecommitdiff
path: root/src/libFLAC/memory.c
diff options
context:
space:
mode:
authorJosh Coalson <jcoalson@users.sourceforce.net>2007-06-14 06:10:00 +0000
committerJosh Coalson <jcoalson@users.sourceforce.net>2007-06-14 06:10:00 +0000
commitcebba2a5dc9c791c3f8c400cf8c1b503c30b6fea (patch)
tree7f7c628d152299ac60ddecb834d066dea9e4184a /src/libFLAC/memory.c
parent60a43f073f7e24c2b855c70a03c63c783a5d3f6b (diff)
downloadflac-cebba2a5dc9c791c3f8c400cf8c1b503c30b6fea.tar.gz
cleaner pointer alignment logic for autoconf-based builds
Diffstat (limited to 'src/libFLAC/memory.c')
-rw-r--r--src/libFLAC/memory.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libFLAC/memory.c b/src/libFLAC/memory.c
index 2df3bfb5..7c7aee94 100644
--- a/src/libFLAC/memory.c
+++ b/src/libFLAC/memory.c
@@ -45,6 +45,16 @@ void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
#ifdef FLAC__ALIGN_MALLOC_DATA
/* align on 32-byte (256-bit) boundary */
x = malloc(bytes+31);
+#ifdef SIZEOF_VOIDP
+#if SIZEOF_VOIDP == 4
+ /* could do *aligned_address = x + ((unsigned) (32 - (((unsigned)x) & 31))) & 31; */
+ *aligned_address = (void*)(((unsigned)x + 31) & -32);
+#elif SIZEOF_VOIDP == 8
+ *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
+#else
+# error Unsupported sizeof(void*)
+#endif
+#else
/* there's got to be a better way to do this right for all archs */
if(sizeof(void*) == sizeof(unsigned))
*aligned_address = (void*)(((unsigned)x + 31) & -32);
@@ -52,6 +62,7 @@ void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
*aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
else
return 0;
+#endif
#else
x = malloc(bytes);
*aligned_address = x;