summaryrefslogtreecommitdiffstatshomepage
path: root/py/gc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-05-04 09:14:43 +0000
committerDamien George <damien.p.george@gmail.com>2016-06-28 11:28:49 +0100
commite33806aaff5787d57bd708f99e565f1c490fc069 (patch)
tree59ddc19ea1bd99b410d527dd60e88e26682cd229 /py/gc.c
parent7f4658a7ee15dc9d6b539905f5e3a9b62f02cd70 (diff)
downloadmicropython-e33806aaff5787d57bd708f99e565f1c490fc069.tar.gz
micropython-e33806aaff5787d57bd708f99e565f1c490fc069.zip
py/gc: Fix 2 cases of concurrent access to ATB and FTB.
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/py/gc.c b/py/gc.c
index b5cf9497de..a40b9878f9 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -594,13 +594,14 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
// 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;
}
- GC_ENTER();
-
if (MP_STATE_MEM(gc_lock_depth) > 0) {
GC_EXIT();
return NULL;
@@ -682,6 +683,12 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
return ptr_in;
}
+ #if MICROPY_ENABLE_FINALISER
+ bool ftb_state = FTB_GET(block);
+ #else
+ bool ftb_state = false;
+ #endif
+
GC_EXIT();
if (!allow_move) {
@@ -690,13 +697,7 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
}
// can't resize inplace; try to find a new contiguous chain
- void *ptr_out = gc_alloc(n_bytes,
-#if MICROPY_ENABLE_FINALISER
- FTB_GET(block)
-#else
- false
-#endif
- );
+ void *ptr_out = gc_alloc(n_bytes, ftb_state);
// check that the alloc succeeded
if (ptr_out == NULL) {