Commit 3d3d8f10 authored by Eugene Kosov's avatar Eugene Kosov

MDEV-21337 fix aligned_malloc()

do not fallback to malloc(), always return properly aligned buffer
parent 984b3c15
...@@ -94,11 +94,6 @@ IF(NOT MSVC) ...@@ -94,11 +94,6 @@ IF(NOT MSVC)
SET_SOURCE_FILES_PROPERTIES(trx/trx0rec.cc PROPERTIES COMPILE_FLAGS -O1) SET_SOURCE_FILES_PROPERTIES(trx/trx0rec.cc PROPERTIES COMPILE_FLAGS -O1)
ENDIF() ENDIF()
CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
IF(HAVE_POSIX_MEMALIGN)
ADD_DEFINITIONS(-DHAVE_POSIX_MEMALIGN)
ENDIF()
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not # either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
# workaround for old gcc on x86, gcc atomic ops only work under -march=i686 # workaround for old gcc on x86, gcc atomic ops only work under -march=i686
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
......
...@@ -82,19 +82,16 @@ Created 11/5/1995 Heikki Tuuri ...@@ -82,19 +82,16 @@ Created 11/5/1995 Heikki Tuuri
#include "snappy-c.h" #include "snappy-c.h"
#endif #endif
inline void* aligned_malloc(size_t size, size_t align) { static void *aligned_malloc(size_t size, size_t align)
void *result; {
#ifdef _MSC_VER #ifdef _MSC_VER
result = _aligned_malloc(size, align); return _aligned_malloc(size, align);
#elif defined (HAVE_POSIX_MEMALIGN)
if(posix_memalign(&result, align, size)) {
result = 0;
}
#else #else
/* Use unaligned malloc as fallback */ void *result;
result = malloc(size); if (posix_memalign(&result, align, size))
result= NULL;
#endif #endif
return result; return result;
} }
inline void aligned_free(void *ptr) { inline void aligned_free(void *ptr) {
......
...@@ -93,11 +93,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-class-memaccess") ...@@ -93,11 +93,6 @@ MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-class-memaccess")
IF(NOT MSVC) IF(NOT MSVC)
CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
IF(HAVE_POSIX_MEMALIGN)
ADD_DEFINITIONS(-DHAVE_POSIX_MEMALIGN)
ENDIF()
# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not # either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
# workaround for old gcc on x86, gcc atomic ops only work under -march=i686 # workaround for old gcc on x86, gcc atomic ops only work under -march=i686
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
......
...@@ -92,17 +92,14 @@ buf_mark_space_corrupt( ...@@ -92,17 +92,14 @@ buf_mark_space_corrupt(
/* prototypes for new functions added to ha_innodb.cc */ /* prototypes for new functions added to ha_innodb.cc */
trx_t* innobase_get_trx(); trx_t* innobase_get_trx();
inline void* aligned_malloc(size_t size, size_t align) { static void* aligned_malloc(size_t size, size_t align) {
void *result; void *result;
#ifdef _MSC_VER #ifdef _MSC_VER
result = _aligned_malloc(size, align); result = _aligned_malloc(size, align);
#elif defined (HAVE_POSIX_MEMALIGN) #else
if(posix_memalign(&result, align, size)) { if(posix_memalign(&result, align, size)) {
result = 0; result = NULL;
} }
#else
/* Use unaligned malloc as fallback */
result = malloc(size);
#endif #endif
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment