File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed
Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,14 @@ STATIC void gc_deal_with_stack_overflow(void) {
231231 }
232232}
233233
234+ #if MICROPY_PY_GC_COLLECT_RETVAL
235+ uint gc_collected ;
236+ #endif
237+
234238STATIC void gc_sweep (void ) {
239+ #if MICROPY_PY_GC_COLLECT_RETVAL
240+ gc_collected = 0 ;
241+ #endif
235242 // free unmarked heads and their tails
236243 int free_tail = 0 ;
237244 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) {
254261 }
255262#endif
256263 free_tail = 1 ;
264+ #if MICROPY_PY_GC_COLLECT_RETVAL
265+ gc_collected ++ ;
266+ #endif
257267 // fall through to free the head
258268
259269 case AT_TAIL :
Original file line number Diff line number Diff line change 3737
3838#if MICROPY_PY_GC && MICROPY_ENABLE_GC
3939
40+ extern uint gc_collected ;
41+
4042STATIC mp_obj_t py_gc_collect (void ) {
4143 gc_collect ();
44+ #if MICROPY_PY_GC_COLLECT_RETVAL
45+ return MP_OBJ_NEW_SMALL_INT (gc_collected );
46+ #else
4247 return mp_const_none ;
48+ #endif
4349}
4450MP_DEFINE_CONST_FUN_OBJ_0 (gc_collect_obj , py_gc_collect );
4551
Original file line number Diff line number Diff line change @@ -279,6 +279,11 @@ typedef double mp_float_t;
279279#define MICROPY_PY_GC (1)
280280#endif
281281
282+ // Whether to return number of collected objects from gc.collect()
283+ #ifndef MICROPY_PY_GC_COLLECT_RETVAL
284+ #define MICROPY_PY_GC_COLLECT_RETVAL (0)
285+ #endif
286+
282287// Whether to provide "io" module
283288#ifndef MICROPY_PY_IO
284289#define MICROPY_PY_IO (1)
Original file line number Diff line number Diff line change 4646#define MICROPY_PY_SYS_STDFILES (1)
4747#define MICROPY_PY_CMATH (1)
4848#define MICROPY_PY_IO_FILEIO (1)
49+ #define MICROPY_PY_GC_COLLECT_RETVAL (1)
4950// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
5051// names in exception messages (may require more RAM).
5152#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
You can’t perform that action at this time.
0 commit comments