summaryrefslogtreecommitdiffstatshomepage
path: root/py/gc.c
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2015-11-06 14:32:47 -0800
committerDamien George <damien.p.george@gmail.com>2015-11-07 14:26:11 +0000
commit7f3c0d1ea8fa21df3b2078c7189f2b26fe36da59 (patch)
tree885907a70dafd8a91fa8240d338d76d333ed46ef /py/gc.c
parent41b688e25f537479afc0b0e806cd0cb02ea47bb0 (diff)
downloadmicropython-7f3c0d1ea8fa21df3b2078c7189f2b26fe36da59.tar.gz
micropython-7f3c0d1ea8fa21df3b2078c7189f2b26fe36da59.zip
py: Clear finalizer flag when calling gc_free.
Currently, the only place that clears the bit is in gc_collect. So if a block with a finalizer is allocated, and subsequently freed, and then the block is reallocated with no finalizer then the bit remains set. This could also be fixed by having gc_alloc clear the bit, but I'm pretty sure that free is called way less than alloc, so doing it in free is more efficient.
Diffstat (limited to 'py/gc.c')
-rw-r--r--py/gc.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/gc.c b/py/gc.c
index e4d29d130f..077c291f3a 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -442,6 +442,7 @@ void *gc_alloc_with_finaliser(mp_uint_t n_bytes) {
*/
// force the freeing of a piece of memory
+// TODO: freeing here does not call finaliser
void gc_free(void *ptr_in) {
if (MP_STATE_MEM(gc_lock_depth) > 0) {
// TODO how to deal with this error?
@@ -454,6 +455,9 @@ void gc_free(void *ptr_in) {
if (VERIFY_PTR(ptr)) {
mp_uint_t block = BLOCK_FROM_PTR(ptr);
if (ATB_GET_KIND(block) == AT_HEAD) {
+ #if MICROPY_ENABLE_FINALISER
+ FTB_CLEAR(block);
+ #endif
// set the last_free pointer to this block if it's earlier in the heap
if (block / BLOCKS_PER_ATB < MP_STATE_MEM(gc_last_free_atb_index)) {
MP_STATE_MEM(gc_last_free_atb_index) = block / BLOCKS_PER_ATB;