diff options
author | Damien George <damien.p.george@gmail.com> | 2014-10-31 21:30:46 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-10-31 21:30:46 +0000 |
commit | 109c1de015eeee385020233e2f8cc6f921149103 (patch) | |
tree | 9cd3851ac9b580fcc7d84824bdf14c2bc968ee88 /py/gc.c | |
parent | 4029f51842656e7a1576dbe7c41aeea3eef83645 (diff) |
py: Make gc.enable/disable just control auto-GC; alloc is still allowed.
gc.enable/disable are now the same as CPython: they just control whether
automatic garbage collection is enabled or not. If disabled, you can
still allocate heap memory, and initiate a manual collection.
Diffstat (limited to 'py/gc.c')
-rw-r--r-- | py/gc.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -28,6 +28,7 @@ #include <stdio.h> #include <string.h> #include <stdbool.h> +#include <stdint.h> #include "mpconfig.h" #include "misc.h" @@ -68,7 +69,8 @@ STATIC mp_uint_t *gc_pool_end; STATIC int gc_stack_overflow; STATIC mp_uint_t gc_stack[STACK_SIZE]; STATIC mp_uint_t *gc_sp; -STATIC mp_uint_t gc_lock_depth; +STATIC uint16_t gc_lock_depth; +uint16_t gc_auto_collect_enabled; STATIC mp_uint_t gc_last_free_atb_index; // ATB = allocation table byte @@ -163,6 +165,9 @@ void gc_init(void *start, void *end) { // unlock the GC gc_lock_depth = 0; + // allow auto collection + gc_auto_collect_enabled = 1; + DEBUG_printf("GC layout:\n"); DEBUG_printf(" alloc table at %p, length " UINT_FMT " bytes, " UINT_FMT " blocks\n", gc_alloc_table_start, gc_alloc_table_byte_len, gc_alloc_table_byte_len * BLOCKS_PER_ATB); #if MICROPY_ENABLE_FINALISER @@ -375,7 +380,7 @@ void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) { mp_uint_t end_block; mp_uint_t start_block; mp_uint_t n_free = 0; - int collected = 0; + int collected = !gc_auto_collect_enabled; for (;;) { // look for a run of n_blocks available blocks |