[vlc-commits] vlc_memalign(): osx 10.5 doesn't have posix_memalign()
Rafaël Carré
git at videolan.org
Sun Sep 25 05:25:05 CEST 2011
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Sat Sep 24 23:22:41 2011 -0400| [06c9784ad684c52330495f9658fa662bdb5b9d10] | committer: Rafaël Carré
vlc_memalign(): osx 10.5 doesn't have posix_memalign()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=06c9784ad684c52330495f9658fa662bdb5b9d10
---
include/vlc_common.h | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/include/vlc_common.h b/include/vlc_common.h
index a127bfd..4c8c5e9 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -886,10 +886,34 @@ static inline void SetQWLE (void *p, uint64_t qw)
VLC_API bool vlc_ureduce( unsigned *, unsigned *, uint64_t, uint64_t, uint64_t );
/* Aligned memory allocator */
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+
#ifdef WIN32
# include <malloc.h>
# define vlc_memalign(align, size) (__mingw_aligned_malloc(size, align))
# define vlc_free(base) (__mingw_aligned_free(base))
+#elif defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
+static inline void *vlc_memalign(size_t align, size_t size)
+{
+ long diff;
+ void *ptr;
+
+ ptr = malloc(size+align);
+ if(!ptr)
+ return ptr;
+ diff = ((-(long)ptr - 1)&(align-1)) + 1;
+ ptr = (char*)ptr + diff;
+ ((char*)ptr)[-1]= diff;
+ return ptr;
+}
+
+static void vlc_free(void *ptr)
+{
+ if (ptr)
+ free((char*)ptr - ((char*)ptr)[-1]);
+}
#else
static inline void *vlc_memalign(size_t align, size_t size)
{
More information about the vlc-commits
mailing list