Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
755a55f5
Commit
755a55f5
authored
Jun 05, 2014
by
Paul Sokolovsky
Browse files
modgc: Implement return value for gc.collect(), enable on Unix.
parent
d4c2bddd
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/gc.c
View file @
755a55f5
...
...
@@ -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
:
...
...
py/modgc.c
View file @
755a55f5
...
...
@@ -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
);
...
...
py/mpconfig.h
View file @
755a55f5
...
...
@@ -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)
...
...
unix/mpconfigport.h
View file @
755a55f5
...
...
@@ -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)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment