Browse Source

modgc: Implement return value for gc.collect(), enable on Unix.

pull/668/head
Paul Sokolovsky 11 years ago
parent
commit
755a55f507
  1. 10
      py/gc.c
  2. 6
      py/modgc.c
  3. 5
      py/mpconfig.h
  4. 1
      unix/mpconfigport.h

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:

6
py/modgc.c

@ -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);

5
py/mpconfig.h

@ -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)

1
unix/mpconfigport.h

@ -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…
Cancel
Save