3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-26 13:06:05 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-11-21 13:48:48 -08:00
parent 8590876d18
commit 0c1408b30e
5 changed files with 88 additions and 43 deletions

View file

@ -292,8 +292,10 @@ void memory::deallocate(void * p) {
void * memory::allocate(size_t s) {
s = s + sizeof(size_t); // we allocate an extra field!
void * r = malloc(s);
if (r == 0)
if (r == 0) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
g_memory_thread_alloc_size += s;
g_memory_thread_alloc_count += 1;
@ -317,8 +319,10 @@ void* memory::reallocate(void *p, size_t s) {
}
void *r = realloc(real_p, s);
if (r == 0)
if (r == 0) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}
@ -361,8 +365,10 @@ void * memory::allocate(size_t s) {
if (counts_exceeded)
throw_alloc_counts_exceeded();
void * r = malloc(s);
if (r == nullptr)
if (r == nullptr) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}
@ -389,8 +395,10 @@ void* memory::reallocate(void *p, size_t s) {
if (counts_exceeded)
throw_alloc_counts_exceeded();
void *r = realloc(real_p, s);
if (r == nullptr)
if (r == nullptr) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}