Index: libopenjpeg/j2k_lib.h =================================================================== --- libopenjpeg/j2k_lib.h (revision 463) +++ libopenjpeg/j2k_lib.h (working copy) @@ -62,42 +62,44 @@ @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available */ #ifdef WIN32 - #ifdef __GNUC__ -#include -#else /* MSVC, Intel C++ */ -#include -#endif + #include + #else /* MSVC, Intel C++ */ + #include + #endif -#ifdef _mm_malloc - #define opj_aligned_malloc(size) _mm_malloc(size, 16) - #else - #define opj_aligned_malloc(size) malloc(size) - #endif - - #ifdef _mm_free - #define opj_aligned_free(m) _mm_free(m) - #else - #define opj_aligned_free(m) free(m) - #endif - + #ifdef _mm_malloc + #define HAVE_MM_MALLOC + #endif #else /* Not WIN32 */ -/* Linux x86_64 and OSX always align allocations to 16 bytes */ -#if defined(__amd64__) || defined(__APPLE__) -#define opj_aligned_malloc(size) malloc(size) -#else -extern int posix_memalign (void **, size_t, size_t); - -static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ - void* mem = NULL; - posix_memalign(&mem, 16, size); - return mem; -} +#if defined(__sun) + #define HAVE_MEMALIGN + /* Linux x86_64 and OSX always align allocations to 16 bytes */ +#elif !defined(__amd64__) && !defined(__APPLE__) + /* FIXME: Yes, this is a big assumption */ + #define HAVE_POSIX_MEMALIGN #endif +#ifdef HAVE_MEMALIGN + extern void* memalign(size_t, size_t); + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) memalign(16, (size)) + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) +#endif + +#ifdef HAVE_POSIX_MEMALIGN + #undef opj_aligned_malloc + extern int posix_memalign(void**, size_t, size_t); -#define opj_aligned_free(m) free(m) - + static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ + void* mem = NULL; + posix_memalign(&mem, 16, size); + return mem; + } + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) + #endif #endif /**