Handle platforms (like Darwin 9) that do not have posix_memalign
This commit is contained in:
+1
-1
@@ -113,7 +113,7 @@ AC_FUNC_FORK
|
|||||||
AC_FUNC_MALLOC
|
AC_FUNC_MALLOC
|
||||||
AC_FUNC_MBRTOWC
|
AC_FUNC_MBRTOWC
|
||||||
AC_FUNC_REALLOC
|
AC_FUNC_REALLOC
|
||||||
AC_CHECK_FUNCS([gettimeofday setrlimit inet_ntoa iswprint memchr memset nl_langinfo setenv setlocale sigaction socket strchr strdup strerror strtol wcwidth])
|
AC_CHECK_FUNCS([gettimeofday setrlimit inet_ntoa iswprint memchr memset nl_langinfo posix_memalign setenv setlocale sigaction socket strchr strdup strerror strtol wcwidth])
|
||||||
|
|
||||||
AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if clock_gettime is available.])])
|
AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if clock_gettime is available.])])
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,27 @@ static void * sse_alloc( int len )
|
|||||||
{
|
{
|
||||||
void *ptr = NULL;
|
void *ptr = NULL;
|
||||||
|
|
||||||
|
#if defined(HAVE_POSIX_MEMALIGN)
|
||||||
if( (0 != posix_memalign( (void **)&ptr, 16, len )) || (ptr == NULL) ) {
|
if( (0 != posix_memalign( (void **)&ptr, 16, len )) || (ptr == NULL) ) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// Some platforms will align malloc. Let's try that first.
|
||||||
|
if( ! (ptr = malloc(len)) ) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
if( (size_t)ptr & 0xF ) {
|
||||||
|
// The pointer wasn't 16-byte aligned, so try again with valloc
|
||||||
|
free(ptr);
|
||||||
|
if( ! (ptr = valloc(len)) ) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
if( (size_t)ptr & 0xF ) {
|
||||||
|
free(ptr);
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !defined(HAVE_POSIX_MEMALIGN) */
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user