do not use aligned_alloc since it requires c11
This commit is contained in:
parent
0dc4914b4e
commit
2d410fc74b
|
@ -225,20 +225,16 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
|
||||||
include(TestLargeFiles)
|
include(TestLargeFiles)
|
||||||
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
|
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
|
||||||
|
|
||||||
|
# Allocating Aligned Memory Blocks
|
||||||
include(CheckIncludeFiles)
|
include(CheckIncludeFiles)
|
||||||
check_include_files(malloc.h HAVE_MALLOC_H)
|
check_include_files(malloc.h HAVE_MALLOC_H)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
# aligned_alloc
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-std=c11")
|
|
||||||
check_symbol_exists(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
|
# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
|
||||||
check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
|
check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
|
||||||
# memalign
|
|
||||||
check_symbol_exists(memalign malloc.h HAVE_MEMALIGN)
|
|
||||||
# posix_memalign
|
# posix_memalign
|
||||||
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
|
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
|
||||||
|
# memalign (obsolete)
|
||||||
|
check_symbol_exists(memalign malloc.h HAVE_MEMALIGN)
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Build Library
|
# Build Library
|
||||||
if(BUILD_JPIP_SERVER)
|
if(BUILD_JPIP_SERVER)
|
||||||
|
|
|
@ -30,36 +30,34 @@
|
||||||
*/
|
*/
|
||||||
#define OPJ_SKIP_POISON
|
#define OPJ_SKIP_POISON
|
||||||
#include "opj_malloc.h"
|
#include "opj_malloc.h"
|
||||||
|
#include "opj_config_private.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static inline void *opj_aligned_alloc(size_t alignment, size_t size)
|
static inline void *opj_aligned_alloc(size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
#ifndef HAVE_ALIGNED_ALLOC
|
|
||||||
/* older linux */
|
|
||||||
#ifdef HAVE_MEMALIGN
|
|
||||||
assert( size % alignment == 0 );
|
|
||||||
return memalign( alignment, size );
|
|
||||||
#endif /* HAVE_MEMALIGN */
|
|
||||||
|
|
||||||
/* _MSC_VER */
|
|
||||||
#ifdef HAVE__ALIGNED_MALLOC
|
|
||||||
return _aligned_malloc( alignment, size );
|
|
||||||
#endif /* HAVE__ALIGNED_MALLOC */
|
|
||||||
|
|
||||||
/* MacOSX / clang */
|
/* MacOSX / clang */
|
||||||
#if defined(HAVE_POSIX_MEMALIGN) && !defined(HAVE_MEMALIGN)
|
#if defined(HAVE_POSIX_MEMALIGN)
|
||||||
|
// aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
|
||||||
|
// This function was introduced in POSIX 1003.1d. Although this function is
|
||||||
|
// superseded by aligned_alloc, it is more portable to older POSIX systems
|
||||||
|
// that do not support ISO C11.
|
||||||
void* ptr;
|
void* ptr;
|
||||||
if (posix_memalign (&ptr, alignment, size))
|
if (posix_memalign (&ptr, alignment, size))
|
||||||
{
|
{
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
#endif /* HAVE_POSIX_MEMALIGN */
|
/* older linux */
|
||||||
|
#elif defined(HAVE_MEMALIGN)
|
||||||
#else /* HAVE_ALIGNED_ALLOC */
|
assert( size % alignment == 0 );
|
||||||
return aligned_alloc( alignment, size );
|
return memalign( alignment, size );
|
||||||
#endif /* HAVE_ALIGNED_ALLOC */
|
/* _MSC_VER */
|
||||||
|
#elif defined(HAVE__ALIGNED_MALLOC)
|
||||||
|
return _aligned_malloc( alignment, size );
|
||||||
|
#else
|
||||||
/* TODO: _mm_malloc(x,y) */
|
/* TODO: _mm_malloc(x,y) */
|
||||||
|
#error missing aligned alloc function
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void * opj_malloc(size_t size)
|
void * opj_malloc(size_t size)
|
||||||
|
@ -74,7 +72,7 @@ void * opj_calloc(size_t numOfElements, size_t sizeOfElements)
|
||||||
|
|
||||||
void *opj_aligned_malloc(size_t size)
|
void *opj_aligned_malloc(size_t size)
|
||||||
{
|
{
|
||||||
return opj_aligned_alloc(size,16);
|
return opj_aligned_alloc(16u,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void opj_aligned_free(void* ptr)
|
void opj_aligned_free(void* ptr)
|
||||||
|
|
Loading…
Reference in New Issue