Skip to content

Commit

Permalink
py/gc: In gc_realloc, convert pointer sanity checks to assertions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpgeorge committed Nov 29, 2017
1 parent 8e323b8 commit 74fad35
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions py/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 74fad35

Please sign in to comment.