py/gc: In gc_realloc, convert pointer sanity checks to assertions.

These checks are assumed to be true in all cases where gc_realloc is
called with a valid pointer, so no need to waste code space and time
checking them in a non-debug build.
pull/3458/merge
Damien George 2017-11-29 17:17:08 +11:00
rodzic 8e323b8fa8
commit 74fad3536b
1 zmienionych plików z 5 dodań i 14 usunięć

19
py/gc.c
Wyświetl plik

@ -628,27 +628,18 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
void *ptr = ptr_in;
// sanity check the ptr
if (!VERIFY_PTR(ptr)) {
return NULL;
}
// get first block
size_t block = BLOCK_FROM_PTR(ptr);
GC_ENTER();
// sanity check the ptr is pointing to the head of a block
if (ATB_GET_KIND(block) != AT_HEAD) {
GC_EXIT();
return NULL;
}
if (MP_STATE_MEM(gc_lock_depth) > 0) {
GC_EXIT();
return NULL;
}
// get the GC block number corresponding to this pointer
assert(VERIFY_PTR(ptr));
size_t block = BLOCK_FROM_PTR(ptr);
assert(ATB_GET_KIND(block) == AT_HEAD);
// compute number of new blocks that are requested
size_t new_blocks = (n_bytes + BYTES_PER_BLOCK - 1) / BYTES_PER_BLOCK;