summaryrefslogtreecommitdiffstatshomepage
path: root/py/modgc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-10-31 21:30:46 +0000
committerDamien George <damien.p.george@gmail.com>2014-10-31 21:30:46 +0000
commit109c1de015eeee385020233e2f8cc6f921149103 (patch)
tree9cd3851ac9b580fcc7d84824bdf14c2bc968ee88 /py/modgc.c
parent4029f51842656e7a1576dbe7c41aeea3eef83645 (diff)
downloadmicropython-109c1de015eeee385020233e2f8cc6f921149103.tar.gz
micropython-109c1de015eeee385020233e2f8cc6f921149103.zip
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/modgc.c')
-rw-r--r--py/modgc.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/py/modgc.c b/py/modgc.c
index 8c5a7053ae..a27ef7eed9 100644
--- a/py/modgc.c
+++ b/py/modgc.c
@@ -24,15 +24,13 @@
* THE SOFTWARE.
*/
+#include <stdint.h>
+
#include "mpconfig.h"
#include "misc.h"
#include "qstr.h"
#include "obj.h"
-#include "builtin.h"
#include "runtime.h"
-#include "objlist.h"
-#include "objtuple.h"
-#include "objstr.h"
#include "gc.h"
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
@@ -56,7 +54,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect);
/// \function disable()
/// Disable the garbage collector.
STATIC mp_obj_t gc_disable(void) {
- gc_lock();
+ gc_auto_collect_enabled = 0;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable);
@@ -64,11 +62,16 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable);
/// \function enable()
/// Enable the garbage collector.
STATIC mp_obj_t gc_enable(void) {
- gc_unlock();
+ gc_auto_collect_enabled = 1;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
+STATIC mp_obj_t gc_isenabled(void) {
+ return MP_BOOL(gc_auto_collect_enabled);
+}
+MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
+
/// \function mem_free()
/// Return the number of bytes of available heap RAM.
STATIC mp_obj_t gc_mem_free(void) {
@@ -92,6 +95,7 @@ STATIC const mp_map_elem_t mp_module_gc_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_collect), (mp_obj_t)&gc_collect_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&gc_disable_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&gc_enable_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_isenabled), (mp_obj_t)&gc_isenabled_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem_free), (mp_obj_t)&gc_mem_free_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem_alloc), (mp_obj_t)&gc_mem_alloc_obj },
};