gmio_core: get rid of alloca() support
This commit is contained in:
parent
0f5141979a
commit
85839abf00
@ -103,20 +103,6 @@ if(NOT BUILD_STRICT_C90)
|
|||||||
message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
|
message(WARNING "<sys/stat.h> does not provide 64b variant of fstat(), you may encounter problems with files > 2GB")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Have BSD-like alloca() function ?
|
|
||||||
check_c_source_compiles(
|
|
||||||
"#include <alloca.h>
|
|
||||||
int main() { void* ptr = alloca(256); return 0; }"
|
|
||||||
GMIO_HAVE_BSD_ALLOCA_FUNC)
|
|
||||||
|
|
||||||
# Have Win32 _alloca() function ?
|
|
||||||
if(WIN32)
|
|
||||||
check_c_source_compiles(
|
|
||||||
"#include <malloc.h>
|
|
||||||
int main() { void* ptr = _alloca(256); return 0; }"
|
|
||||||
GMIO_HAVE_WIN__ALLOCA_FUNC)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Have builtin byte swap functions ?
|
# Have builtin byte swap functions ?
|
||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
||||||
|
@ -17,14 +17,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if defined(GMIO_HAVE_BSD_ALLOCA_FUNC)
|
|
||||||
# include <alloca.h>
|
|
||||||
#elif defined(GMIO_HAVE_WIN__ALLOCA_FUNC)
|
|
||||||
# include "error.h"
|
|
||||||
# include <windows.h>
|
|
||||||
# include <malloc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GMIO_INLINE gmio_buffer_t gmio_buffer_null()
|
GMIO_INLINE gmio_buffer_t gmio_buffer_null()
|
||||||
{
|
{
|
||||||
gmio_buffer_t buff = { 0 };
|
gmio_buffer_t buff = { 0 };
|
||||||
@ -56,30 +48,6 @@ gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size)
|
|||||||
return gmio_buffer(realloc(ptr, size), size, &free);
|
return gmio_buffer(realloc(ptr, size), size, &free);
|
||||||
}
|
}
|
||||||
|
|
||||||
gmio_buffer_t gmio_buffer_alloca(size_t size)
|
|
||||||
{
|
|
||||||
#if defined(GMIO_HAVE_BSD_ALLOCA_FUNC)
|
|
||||||
return gmio_buffer(alloca(size), size, NULL);
|
|
||||||
#elif defined(GMIO_HAVE_WIN__ALLOCA_FUNC)
|
|
||||||
# ifdef _MSC_VER
|
|
||||||
__try {
|
|
||||||
return gmio_buffer(_alloca(size), size, NULL);
|
|
||||||
}
|
|
||||||
__except(GetExceptionCode() == STATUS_STACK_OVERFLOW) {
|
|
||||||
/* The stack overflowed */
|
|
||||||
if (_resetstkoflw() == 0)
|
|
||||||
exit(GMIO_ERROR_UNKNOWN);
|
|
||||||
return gmio_buffer_null();
|
|
||||||
}
|
|
||||||
# else
|
|
||||||
return gmio_buffer(_alloca(size), size, NULL);
|
|
||||||
# endif /* _MSC_VER */
|
|
||||||
#else
|
|
||||||
GMIO_UNUSED(size);
|
|
||||||
return gmio_buffer_null();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void gmio_buffer_deallocate(gmio_buffer_t *buffer)
|
void gmio_buffer_deallocate(gmio_buffer_t *buffer)
|
||||||
{
|
{
|
||||||
if (buffer != NULL && buffer->deallocate_func != NULL)
|
if (buffer != NULL && buffer->deallocate_func != NULL)
|
||||||
|
@ -57,9 +57,6 @@ GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_calloc(size_t num, size_t size);
|
|||||||
/*! Returns a gmio_buffer object allocated with standard \c realloc() */
|
/*! Returns a gmio_buffer object allocated with standard \c realloc() */
|
||||||
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size);
|
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_realloc(void* ptr, size_t size);
|
||||||
|
|
||||||
/*! Returns a gmio_buffer object allocated with OS-specific \c alloca() */
|
|
||||||
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_alloca(size_t size);
|
|
||||||
|
|
||||||
/*! Safe and convenient call to gmio_buffer::deallocate_func() */
|
/*! Safe and convenient call to gmio_buffer::deallocate_func() */
|
||||||
GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer);
|
GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer);
|
||||||
|
|
||||||
|
@ -37,10 +37,6 @@
|
|||||||
#cmakedefine GMIO_HAVE_POSIX_FSTAT64_FUNC
|
#cmakedefine GMIO_HAVE_POSIX_FSTAT64_FUNC
|
||||||
#cmakedefine GMIO_HAVE_WIN__FSTAT64_FUNC
|
#cmakedefine GMIO_HAVE_WIN__FSTAT64_FUNC
|
||||||
|
|
||||||
/* alloca()-like */
|
|
||||||
#cmakedefine GMIO_HAVE_BSD_ALLOCA_FUNC
|
|
||||||
#cmakedefine GMIO_HAVE_WIN__ALLOCA_FUNC
|
|
||||||
|
|
||||||
/* Compiler byte-swap functions */
|
/* Compiler byte-swap functions */
|
||||||
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
||||||
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
#cmakedefine GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
||||||
|
Loading…
Reference in New Issue
Block a user