summaryrefslogtreecommitdiff
path: root/py/gc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-29 17:17:08 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-29 17:17:08 +1100
commit74fad3536b961e2ffe08e545b1cf787c0c0b4772 (patch)
tree0973f7dd7c0e8ce6535134f0c69473ce51aa5a92 /py/gc.c
parent8e323b8fa84277531685985327fb682761abd53d (diff)
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.
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/py/gc.c b/py/gc.c
index 9752b3532..172a5e8fc 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -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;