This source file includes following definitions.
- generic_cpp_alloc
- _set_new_mode
- calloc
- cfree
- _recalloc
- _calloc_impl
- error_handler
- _CrtDbgReport
- _CrtDbgReportW
- _CrtSetReportMode
- _malloc_dbg
- _realloc_dbg
- _free_dbg
- _calloc_dbg
inline void* generic_cpp_alloc(size_t size, bool nothrow) {
void* ptr;
for (;;) {
ptr = malloc(size);
if (ptr)
return ptr;
if (!call_new_handler(nothrow))
break;
}
return ptr;
}
extern "C++" {
void* __cdecl operator new(size_t size) {
return generic_cpp_alloc(size, false);
}
void operator delete(void* p) __THROW {
free(p);
}
void* operator new[](size_t size) {
return generic_cpp_alloc(size, false);
}
void operator delete[](void* p) __THROW {
free(p);
}
void* operator new(size_t size, const std::nothrow_t& nt) __THROW {
return generic_cpp_alloc(size, true);
}
void* operator new[](size_t size, const std::nothrow_t& nt) __THROW {
return generic_cpp_alloc(size, true);
}
int _set_new_mode(int flag) __THROW {
int old_mode = new_mode;
new_mode = flag;
return old_mode;
}
}
extern "C" {
void* calloc(size_t n, size_t elem_size) __THROW {
const size_t size = n * elem_size;
if (elem_size != 0 && size / elem_size != n) return NULL;
void* result = malloc(size);
if (result != NULL) {
memset(result, 0, size);
}
return result;
}
void cfree(void* p) __THROW {
free(p);
}
#ifdef WIN32
void* _recalloc(void* p, size_t n, size_t elem_size) {
if (!p)
return calloc(n, elem_size);
const size_t size = n * elem_size;
if (elem_size != 0 && size / elem_size != n) return NULL;
return realloc(p, size);
}
void* _calloc_impl(size_t n, size_t size) {
return calloc(n, size);
}
#ifndef NDEBUG
#undef malloc
#undef free
#undef calloc
static int error_handler(int reportType) {
switch (reportType) {
case 0:
__debugbreak();
return 0;
case 1:
__debugbreak();
return 0;
case 2:
__debugbreak();
return 0;
}
char* p = NULL;
*p = '\0';
return 0;
}
int _CrtDbgReport(int reportType,
const char*,
int, const char*,
const char*,
...) {
return error_handler(reportType);
}
int _CrtDbgReportW(int reportType,
const wchar_t*,
int, const wchar_t*,
const wchar_t*,
...) {
return error_handler(reportType);
}
int _CrtSetReportMode(int, int) {
return 0;
}
void* _malloc_dbg(size_t size, int , const char*, int) {
return malloc(size);
}
void* _realloc_dbg(void* ptr, size_t size, int, const char*, int) {
return realloc(ptr, size);
}
void _free_dbg(void* ptr, int) {
free(ptr);
}
void* _calloc_dbg(size_t n, size_t size, int, const char*, int) {
return calloc(n, size);
}
#endif
#endif
}