summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authormux <freelancer.c@gmail.com>2014-04-05 15:49:03 +0200
committermux <freelancer.c@gmail.com>2014-04-05 15:49:03 +0200
commitcc849f70f478f7442d19ed2f4c0b4297035b2393 (patch)
tree4b51f36aee08b764ef12e558c2a91246409cb41c
parent4f7e9f5c445b5c0b262d9dfb8fceda4830f4844b (diff)
downloadmicropython-cc849f70f478f7442d19ed2f4c0b4297035b2393.tar.gz
micropython-cc849f70f478f7442d19ed2f4c0b4297035b2393.zip
Move del to locals
-rw-r--r--py/gc.c22
-rw-r--r--py/obj.h2
-rw-r--r--py/qstrdefs.h1
-rw-r--r--stm/file.c8
4 files changed, 15 insertions, 18 deletions
diff --git a/py/gc.c b/py/gc.c
index 0d28828c0d..e330e5c4a7 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -8,6 +8,7 @@
#include "misc.h"
#include "qstr.h"
#include "obj.h"
+#include "runtime.h"
#if MICROPY_ENABLE_GC
@@ -175,12 +176,14 @@ STATIC void gc_sweep(void) {
switch (ATB_GET_KIND(block)) {
case AT_HEAD:
if (ATB_IS_MPOBJ(block)) {
- ATB_CLR_MPOBJ(block); // clear mpobj flag
- mp_obj_t *self = (mp_obj_t*)PTR_FROM_BLOCK(block);
- mp_obj_type_t *type= mp_obj_get_type(self);
- if (type->del != NULL) {
- type->del(self);
+ mp_obj_t dest[2];
+ mp_load_method((mp_obj_t*)PTR_FROM_BLOCK(block), MP_QSTR___del__, dest);
+ // load_method returned a method
+ if (dest[1] != MP_OBJ_NULL) {
+ mp_call_method_n_kw(0, 0, dest);
}
+ // clear mpobj flag
+ ATB_CLR_MPOBJ(block);
}
free_tail = 1;
// fall through to free the head
@@ -305,16 +308,17 @@ found:
// mark first block as used head
ATB_FREE_TO_HEAD(start_block);
- if (is_mpobj) {
- ATB_SET_MPOBJ(start_block);
- }
-
// mark rest of blocks as used tail
// TODO for a run of many blocks can make this more efficient
for (machine_uint_t bl = start_block + 1; bl <= end_block; bl++) {
ATB_FREE_TO_TAIL(bl);
}
+ if (is_mpobj) {
+ // set mp_obj flag only if it has del
+ ATB_SET_MPOBJ(start_block);
+ }
+
// return pointer to first block
return (void*)(gc_pool_start + start_block * WORDS_PER_BLOCK);
}
diff --git a/py/obj.h b/py/obj.h
index 4178295bea..952187e464 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -154,7 +154,6 @@ typedef mp_obj_t (*mp_binary_op_fun_t)(int op, mp_obj_t, mp_obj_t);
typedef void (*mp_load_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest); // for fail, do nothing; for attr, dest[0] = value; for method, dest[0] = method, dest[1] = self
typedef bool (*mp_store_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t value); // return true if store succeeded
typedef bool (*mp_store_item_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); // return true if store succeeded
-typedef void (*mp_del_fun_t)(mp_obj_t self_in);
typedef struct _mp_method_t {
qstr name;
@@ -237,7 +236,6 @@ struct _mp_obj_type_t {
unpack seq list tuple
*/
- mp_del_fun_t del;
};
typedef struct _mp_obj_type_t mp_obj_type_t;
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 368b0fc8e1..591c96a948 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -27,6 +27,7 @@ Q(__sub__)
Q(__repr__)
Q(__str__)
Q(__getattr__)
+Q(__del__)
Q(micropython)
Q(byte_code)
diff --git a/stm/file.c b/stm/file.c
index fc6abfcd6f..a8f66f4b06 100644
--- a/stm/file.c
+++ b/stm/file.c
@@ -13,12 +13,6 @@ typedef struct _pyb_file_obj_t {
FIL fp;
} pyb_file_obj_t;
-void file_obj_del(mp_obj_t self_in) {
- pyb_file_obj_t *self = self_in;
- f_close(&self->fp);
- printf("<file del called>\n");
-}
-
void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
printf("<file %p>", self_in);
}
@@ -62,6 +56,7 @@ STATIC const mp_map_elem_t file_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&file_obj_read_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&file_obj_write_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&file_obj_close_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&file_obj_close_obj },
};
STATIC MP_DEFINE_CONST_DICT(file_locals_dict, file_locals_dict_table);
@@ -70,7 +65,6 @@ static const mp_obj_type_t file_obj_type = {
{ &mp_type_type },
.name = MP_QSTR_File,
.print = file_obj_print,
- .del = file_obj_del,
.locals_dict = (mp_obj_t)&file_locals_dict,
};