mirror of https://gitee.com/bigwinds/arangodb
nullptr
This commit is contained in:
parent
766faddaf1
commit
6ab535bd06
|
@ -230,11 +230,11 @@ static inline void _backtrace (void) {
|
||||||
size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
|
size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
|
||||||
strings = backtrace_symbols(stack_frames, size);
|
strings = backtrace_symbols(stack_frames, size);
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
if (strings != NULL) {
|
if (strings != nullptr) {
|
||||||
#ifdef TRI_USE_DEMANGLING
|
#ifdef TRI_USE_DEMANGLING
|
||||||
char *mangled_name = nullptr, *offset_begin = nullptr, *offset_end = nullptr;
|
char *mangled_name = nullptr, *offset_begin = nullptr, *offset_end = nullptr;
|
||||||
|
|
||||||
// find parantheses and +address offset surrounding mangled name
|
// find parentheses and +address offset surrounding mangled name
|
||||||
for (char *p = strings[i]; *p; ++p) {
|
for (char *p = strings[i]; *p; ++p) {
|
||||||
if (*p == '(') {
|
if (*p == '(') {
|
||||||
mangled_name = p;
|
mangled_name = p;
|
||||||
|
@ -276,7 +276,7 @@ static inline void _backtrace (void) {
|
||||||
fprintf(stderr, "[%p]\n", stack_frames[i]);
|
fprintf(stderr, "[%p]\n", stack_frames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strings != NULL) {
|
if (strings != nullptr) {
|
||||||
TRI_SystemFree(strings);
|
TRI_SystemFree(strings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -292,7 +292,7 @@ static inline void _getBacktrace (std::string& btstr) {
|
||||||
strings = backtrace_symbols(stack_frames, size);
|
strings = backtrace_symbols(stack_frames, size);
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
if (strings != NULL) {
|
if (strings != nullptr) {
|
||||||
|
|
||||||
char *mangled_name = nullptr, *offset_begin = nullptr, *offset_end = nullptr;
|
char *mangled_name = nullptr, *offset_begin = nullptr, *offset_end = nullptr;
|
||||||
|
|
||||||
|
@ -347,15 +347,15 @@ static inline void _getBacktrace (std::string& btstr) {
|
||||||
std::string("\n");
|
std::string("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strings != NULL) {
|
if (strings != nullptr) {
|
||||||
TRI_SystemFree(strings);
|
TRI_SystemFree(strings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TRI_ASSERT
|
#ifndef TRI_ASSERT
|
||||||
#define TRI_ASSERT(expr) { if (!(expr)) _backtrace(); assert(expr);}
|
#define TRI_ASSERT(expr) { if (! (expr)) _backtrace(); assert(expr); }
|
||||||
#define TRI_ASSERT_EXPENSIVE(expr) {if (!(expr)) _backtrace(); assert(expr);}
|
#define TRI_ASSERT_EXPENSIVE(expr) { if (! (expr)) _backtrace(); assert(expr); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -196,7 +196,7 @@ static char* FailMalloc (TRI_memory_zone_t* zone,
|
||||||
if (zone->_failable && ShouldFail(n)) {
|
if (zone->_failable && ShouldFail(n)) {
|
||||||
// intentionally return NULL
|
// intentionally return NULL
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<char*>(BuiltInMalloc(n));
|
return static_cast<char*>(BuiltInMalloc(n));
|
||||||
|
@ -215,7 +215,7 @@ static char* FailRealloc (TRI_memory_zone_t* zone,
|
||||||
if (zone->_failable && ShouldFail(n)) {
|
if (zone->_failable && ShouldFail(n)) {
|
||||||
// intentionally return NULL
|
// intentionally return NULL
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<char*>(BuiltInRealloc(old, n));
|
return static_cast<char*>(BuiltInRealloc(old, n));
|
||||||
|
@ -233,8 +233,8 @@ static void InitFailMalloc (void) {
|
||||||
// get failure probability
|
// get failure probability
|
||||||
value = getenv("ARANGO_FAILMALLOC_PROBABILITY");
|
value = getenv("ARANGO_FAILMALLOC_PROBABILITY");
|
||||||
|
|
||||||
if (value != NULL) {
|
if (value != nullptr) {
|
||||||
double v = strtod(value, NULL);
|
double v = strtod(value, nullptr);
|
||||||
if (v >= 0.0 && v <= 1.0) {
|
if (v >= 0.0 && v <= 1.0) {
|
||||||
FailProbability = v;
|
FailProbability = v;
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,8 @@ static void InitFailMalloc (void) {
|
||||||
// get startup delay
|
// get startup delay
|
||||||
value = getenv("ARANGO_FAILMALLOC_DELAY");
|
value = getenv("ARANGO_FAILMALLOC_DELAY");
|
||||||
|
|
||||||
if (value != NULL) {
|
if (value != nullptr) {
|
||||||
double v = strtod(value, NULL);
|
double v = strtod(value, nullptr);
|
||||||
if (v > 0.0) {
|
if (v > 0.0) {
|
||||||
FailStartStamp = CurrentTimeStamp() + v;
|
FailStartStamp = CurrentTimeStamp() + v;
|
||||||
}
|
}
|
||||||
|
@ -253,8 +253,8 @@ static void InitFailMalloc (void) {
|
||||||
// get minimum size for failures
|
// get minimum size for failures
|
||||||
value = getenv("ARANGO_FAILMALLOC_MINSIZE");
|
value = getenv("ARANGO_FAILMALLOC_MINSIZE");
|
||||||
|
|
||||||
if (value != NULL) {
|
if (value != nullptr) {
|
||||||
unsigned long long v = strtoull(value, NULL, 10);
|
unsigned long long v = strtoull(value, nullptr, 10);
|
||||||
if (v > 0) {
|
if (v > 0) {
|
||||||
FailMinSize = (size_t) v;
|
FailMinSize = (size_t) v;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ void* TRI_SystemAllocate (uint64_t n, bool set) {
|
||||||
|
|
||||||
m = static_cast<char*>(BuiltInMalloc((size_t) n));
|
m = static_cast<char*>(BuiltInMalloc((size_t) n));
|
||||||
|
|
||||||
if (m != NULL) {
|
if (m != nullptr) {
|
||||||
if (set) {
|
if (set) {
|
||||||
memset(m, 0, (size_t) n);
|
memset(m, 0, (size_t) n);
|
||||||
}
|
}
|
||||||
|
@ -340,23 +340,23 @@ void* TRI_Allocate (TRI_memory_zone_t* zone, uint64_t n, bool set) {
|
||||||
m = static_cast<char*>(MALLOC_WRAPPER(zone, (size_t) n));
|
m = static_cast<char*>(MALLOC_WRAPPER(zone, (size_t) n));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m == NULL) {
|
if (m == nullptr) {
|
||||||
if (zone->_failable) {
|
if (zone->_failable) {
|
||||||
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
|
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CoreReserve == NULL) {
|
if (CoreReserve == nullptr) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"FATAL: failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", giving up!\n",
|
"FATAL: failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", giving up!\n",
|
||||||
(unsigned long long) n,
|
(unsigned long long) n,
|
||||||
(int) zone->_zid
|
(int) zone->_zid
|
||||||
ZONE_DEBUG_PARAMS);
|
ZONE_DEBUG_PARAMS);
|
||||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(CoreReserve);
|
free(CoreReserve);
|
||||||
CoreReserve = NULL;
|
CoreReserve = nullptr;
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", retrying!\n",
|
"failed to allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", retrying!\n",
|
||||||
|
@ -405,7 +405,7 @@ void* TRI_Reallocate (TRI_memory_zone_t* zone, void* m, uint64_t n) {
|
||||||
#endif
|
#endif
|
||||||
char* p;
|
char* p;
|
||||||
|
|
||||||
if (m == NULL) {
|
if (m == nullptr) {
|
||||||
#ifdef TRI_ENABLE_MAINTAINER_MODE
|
#ifdef TRI_ENABLE_MAINTAINER_MODE
|
||||||
return TRI_AllocateZ(zone, n, false, file, line);
|
return TRI_AllocateZ(zone, n, false, file, line);
|
||||||
#else
|
#else
|
||||||
|
@ -434,23 +434,23 @@ void* TRI_Reallocate (TRI_memory_zone_t* zone, void* m, uint64_t n) {
|
||||||
p = static_cast<char*>(REALLOC_WRAPPER(zone, p, (size_t) n));
|
p = static_cast<char*>(REALLOC_WRAPPER(zone, p, (size_t) n));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (p == NULL) {
|
if (p == nullptr) {
|
||||||
if (zone->_failable) {
|
if (zone->_failable) {
|
||||||
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
|
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CoreReserve == NULL) {
|
if (CoreReserve == nullptr) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"FATAL: failed to re-allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", giving up!\n",
|
"FATAL: failed to re-allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", giving up!\n",
|
||||||
(unsigned long long) n,
|
(unsigned long long) n,
|
||||||
zone->_zid
|
zone->_zid
|
||||||
ZONE_DEBUG_PARAMS);
|
ZONE_DEBUG_PARAMS);
|
||||||
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
|
TRI_EXIT_FUNCTION(EXIT_FAILURE, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(CoreReserve);
|
free(CoreReserve);
|
||||||
CoreReserve = NULL;
|
CoreReserve = nullptr;
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"failed to re-allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", retrying!\n",
|
"failed to re-allocate %llu bytes for memory zone %d" ZONE_DEBUG_LOCATION ", retrying!\n",
|
||||||
|
@ -488,7 +488,7 @@ void TRI_Free (TRI_memory_zone_t* zone, void* m) {
|
||||||
|
|
||||||
p = (char*) m;
|
p = (char*) m;
|
||||||
|
|
||||||
if (p == NULL) {
|
if (p == nullptr) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"freeing nil ptr " ZONE_DEBUG_LOCATION
|
"freeing nil ptr " ZONE_DEBUG_LOCATION
|
||||||
ZONE_DEBUG_PARAMS);
|
ZONE_DEBUG_PARAMS);
|
||||||
|
@ -528,7 +528,7 @@ void TRI_SystemFree (void* p) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TRI_ENABLE_MAINTAINER_MODE
|
#ifdef TRI_ENABLE_MAINTAINER_MODE
|
||||||
if (p == NULL) {
|
if (p == nullptr) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"freeing nil ptr in %s:%d\n",
|
"freeing nil ptr in %s:%d\n",
|
||||||
file,
|
file,
|
||||||
|
@ -548,8 +548,8 @@ void TRI_SystemFree (void* p) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void* TRI_WrappedReallocate (void* ptr, long size) {
|
void* TRI_WrappedReallocate (void* ptr, long size) {
|
||||||
if (ptr == NULL && size == 0) {
|
if (ptr == nullptr && size == 0) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BuiltInRealloc(ptr, (size_t) size);
|
return BuiltInRealloc(ptr, (size_t) size);
|
||||||
|
@ -561,7 +561,7 @@ void* TRI_WrappedReallocate (void* ptr, long size) {
|
||||||
|
|
||||||
void TRI_InitialiseMemory () {
|
void TRI_InitialiseMemory () {
|
||||||
if (CoreInitialised == 0) {
|
if (CoreInitialised == 0) {
|
||||||
static size_t const reserveSize = 1024 * 1024 * 10;
|
static size_t const ReserveSize = 1024 * 1024 * 10;
|
||||||
|
|
||||||
TriCoreMemZone._zid = 0;
|
TriCoreMemZone._zid = 0;
|
||||||
TriCoreMemZone._failed = false;
|
TriCoreMemZone._failed = false;
|
||||||
|
@ -575,12 +575,12 @@ void TRI_InitialiseMemory () {
|
||||||
InitFailMalloc();
|
InitFailMalloc();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CoreReserve = BuiltInMalloc(reserveSize);
|
CoreReserve = BuiltInMalloc(ReserveSize);
|
||||||
|
|
||||||
if (CoreReserve == NULL) {
|
if (CoreReserve == nullptr) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"FATAL: cannot allocate initial core reserve of size %llu, giving up!\n",
|
"FATAL: cannot allocate initial core reserve of size %llu, giving up!\n",
|
||||||
(unsigned long long) reserveSize);
|
(unsigned long long) ReserveSize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CoreInitialised = 1;
|
CoreInitialised = 1;
|
||||||
|
|
Loading…
Reference in New Issue