py/gc: Fix 2 cases of concurrent access to ATB and FTB.

This commit is contained in:
Damien George 2016-05-04 09:14:43 +00:00
parent 7f4658a7ee
commit e33806aaff
1 changed files with 10 additions and 9 deletions

19
py/gc.c
View File

@ -594,13 +594,14 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
// get first block // get first block
size_t block = BLOCK_FROM_PTR(ptr); size_t block = BLOCK_FROM_PTR(ptr);
GC_ENTER();
// sanity check the ptr is pointing to the head of a block // sanity check the ptr is pointing to the head of a block
if (ATB_GET_KIND(block) != AT_HEAD) { if (ATB_GET_KIND(block) != AT_HEAD) {
GC_EXIT();
return NULL; return NULL;
} }
GC_ENTER();
if (MP_STATE_MEM(gc_lock_depth) > 0) { if (MP_STATE_MEM(gc_lock_depth) > 0) {
GC_EXIT(); GC_EXIT();
return NULL; return NULL;
@ -682,6 +683,12 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
return ptr_in; return ptr_in;
} }
#if MICROPY_ENABLE_FINALISER
bool ftb_state = FTB_GET(block);
#else
bool ftb_state = false;
#endif
GC_EXIT(); GC_EXIT();
if (!allow_move) { 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 // can't resize inplace; try to find a new contiguous chain
void *ptr_out = gc_alloc(n_bytes, void *ptr_out = gc_alloc(n_bytes, ftb_state);
#if MICROPY_ENABLE_FINALISER
FTB_GET(block)
#else
false
#endif
);
// check that the alloc succeeded // check that the alloc succeeded
if (ptr_out == NULL) { if (ptr_out == NULL) {