Skip to content

Commit 74fad35

Browse files
committed
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.
1 parent 8e323b8 commit 74fad35

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

py/gc.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,27 +628,18 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
628628

629629
void *ptr = ptr_in;
630630

631-
// sanity check the ptr
632-
if (!VERIFY_PTR(ptr)) {
633-
return NULL;
634-
}
635-
636-
// get first block
637-
size_t block = BLOCK_FROM_PTR(ptr);
638-
639631
GC_ENTER();
640632

641-
// sanity check the ptr is pointing to the head of a block
642-
if (ATB_GET_KIND(block) != AT_HEAD) {
643-
GC_EXIT();
644-
return NULL;
645-
}
646-
647633
if (MP_STATE_MEM(gc_lock_depth) > 0) {
648634
GC_EXIT();
649635
return NULL;
650636
}
651637

638+
// get the GC block number corresponding to this pointer
639+
assert(VERIFY_PTR(ptr));
640+
size_t block = BLOCK_FROM_PTR(ptr);
641+
assert(ATB_GET_KIND(block) == AT_HEAD);
642+
652643
// compute number of new blocks that are requested
653644
size_t new_blocks = (n_bytes + BYTES_PER_BLOCK - 1) / BYTES_PER_BLOCK;
654645

0 commit comments

Comments
 (0)