modgc: Implement return value for gc.collect(), enable on Unix.
This commit is contained in:
parent
d4c2bddd0c
commit
755a55f507
10
py/gc.c
10
py/gc.c
@ -231,7 +231,14 @@ STATIC void gc_deal_with_stack_overflow(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
uint gc_collected;
|
||||
#endif
|
||||
|
||||
STATIC void gc_sweep(void) {
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
gc_collected = 0;
|
||||
#endif
|
||||
// free unmarked heads and their tails
|
||||
int free_tail = 0;
|
||||
for (machine_uint_t block = 0; block < gc_alloc_table_byte_len * BLOCKS_PER_ATB; block++) {
|
||||
@ -254,6 +261,9 @@ STATIC void gc_sweep(void) {
|
||||
}
|
||||
#endif
|
||||
free_tail = 1;
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
gc_collected++;
|
||||
#endif
|
||||
// fall through to free the head
|
||||
|
||||
case AT_TAIL:
|
||||
|
@ -37,9 +37,15 @@
|
||||
|
||||
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
|
||||
|
||||
extern uint gc_collected;
|
||||
|
||||
STATIC mp_obj_t py_gc_collect(void) {
|
||||
gc_collect();
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
return MP_OBJ_NEW_SMALL_INT(gc_collected);
|
||||
#else
|
||||
return mp_const_none;
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect);
|
||||
|
||||
|
@ -279,6 +279,11 @@ typedef double mp_float_t;
|
||||
#define MICROPY_PY_GC (1)
|
||||
#endif
|
||||
|
||||
// Whether to return number of collected objects from gc.collect()
|
||||
#ifndef MICROPY_PY_GC_COLLECT_RETVAL
|
||||
#define MICROPY_PY_GC_COLLECT_RETVAL (0)
|
||||
#endif
|
||||
|
||||
// Whether to provide "io" module
|
||||
#ifndef MICROPY_PY_IO
|
||||
#define MICROPY_PY_IO (1)
|
||||
|
@ -46,6 +46,7 @@
|
||||
#define MICROPY_PY_SYS_STDFILES (1)
|
||||
#define MICROPY_PY_CMATH (1)
|
||||
#define MICROPY_PY_IO_FILEIO (1)
|
||||
#define MICROPY_PY_GC_COLLECT_RETVAL (1)
|
||||
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
|
||||
// names in exception messages (may require more RAM).
|
||||
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user