From 2572ddd982e3a1e99f8a7d725717f9bcca2d5ad9 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 5 Mar 2025 00:50:53 +0800 Subject: [PATCH] remove custom marker --- include/pocketpy/interpreter/typeinfo.h | 1 - include/pocketpy/interpreter/types.h | 3 +++ include/pocketpy/interpreter/vm.h | 2 +- src/interpreter/vm.c | 21 ++++++++++++--------- src/modules/array2d.c | 3 +-- src/public/exec.c | 1 - src/public/modules.c | 5 +---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/pocketpy/interpreter/typeinfo.h b/include/pocketpy/interpreter/typeinfo.h index da89426f..9a5acf21 100644 --- a/include/pocketpy/interpreter/typeinfo.h +++ b/include/pocketpy/interpreter/typeinfo.h @@ -23,7 +23,6 @@ typedef struct py_TypeInfo { py_TValue annotations; // type annotations void (*on_end_subclass)(struct py_TypeInfo*); // backdoor for enum module - void (*gc_mark)(void* ud); /* Magic Slots */ py_TValue magic_0[PK_MAGIC_SLOTS_COMMON_LENGTH]; // common magic slots diff --git a/include/pocketpy/interpreter/types.h b/include/pocketpy/interpreter/types.h index eecd9497..a775cc73 100644 --- a/include/pocketpy/interpreter/types.h +++ b/include/pocketpy/interpreter/types.h @@ -23,3 +23,6 @@ typedef struct { } Dict; typedef c11_vector List; + +void c11_chunked_array2d__mark(void* ud); +void function__gc_mark(void* ud); \ No newline at end of file diff --git a/include/pocketpy/interpreter/vm.h b/include/pocketpy/interpreter/vm.h index 47b69dfe..e58491e6 100644 --- a/include/pocketpy/interpreter/vm.h +++ b/include/pocketpy/interpreter/vm.h @@ -59,7 +59,7 @@ bool pk__parse_int_slice(py_Ref slice, int length, int* restrict start, int* res bool pk__normalize_index(int* index, int length); #define pk__mark_value(val) if((val)->is_ptr && !(val)->_obj->gc_marked) PyObject__mark((val)->_obj) -void pk__tp_set_marker(py_Type type, void (*gc_mark)(void*)); + bool pk__object_new(int argc, py_Ref argv); py_TypeInfo* pk__type_info(py_Type type); diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 99f934d9..00bc78b0 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -604,12 +604,6 @@ void PyObject__dtor(PyObject* self) { if(self->slots == -1) NameDict__dtor(PyObject__dict(self)); } -void pk__tp_set_marker(py_Type type, void (*gc_mark)(void*)) { - py_TypeInfo* ti = pk__type_info(type); - assert(ti->gc_mark == NULL); - ti->gc_mark = gc_mark; -} - void PyObject__mark(PyObject* obj) { assert(!obj->gc_marked); @@ -651,10 +645,19 @@ void PyObject__mark(PyObject* obj) { if(self->frame) Frame__gc_mark(self->frame); break; } - default: { - py_TypeInfo* ti = pk__type_info(obj->type); - if(ti->gc_mark) ti->gc_mark(ud); + case tp_function: { + function__gc_mark(ud); + break; } + case tp_code: { + CodeObject* self = ud; + CodeObject__gc_mark(self); + break; + } + case tp_chunked_array2d: { + c11_chunked_array2d__mark(ud); + } + default: return; } } diff --git a/src/modules/array2d.c b/src/modules/array2d.c index 718db378..2575cb6c 100644 --- a/src/modules/array2d.c +++ b/src/modules/array2d.c @@ -1211,7 +1211,7 @@ void c11_chunked_array2d__dtor(c11_chunked_array2d* self) { c11_chunked_array2d_chunks__dtor(&self->chunks); } -static void c11_chunked_array2d__mark(void* ud) { +void c11_chunked_array2d__mark(void* ud) { c11_chunked_array2d* self = ud; pk__mark_value(&self->default_T); pk__mark_value(&self->context_builder); @@ -1291,7 +1291,6 @@ static bool chunked_array2d_view_chunks(int argc, py_Ref argv) { static void register_chunked_array2d(py_Ref mod) { py_Type type = py_newtype("chunked_array2d", tp_object, mod, (py_Dtor)c11_chunked_array2d__dtor); - pk__tp_set_marker(type, c11_chunked_array2d__mark); assert(type == tp_chunked_array2d); py_bind(py_tpobject(type), diff --git a/src/public/exec.c b/src/public/exec.c index 791a6d31..0a69931c 100644 --- a/src/public/exec.c +++ b/src/public/exec.c @@ -9,7 +9,6 @@ py_Type pk_code__register() { py_Type type = pk_newtype("code", tp_object, NULL, (py_Dtor)CodeObject__dtor, false, true); - pk__tp_set_marker(type, (void (*)(void*))CodeObject__gc_mark); return type; } diff --git a/src/public/modules.c b/src/public/modules.c index 98953daa..35caf469 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -773,7 +773,7 @@ py_TValue pk_builtins__register() { return *builtins; } -static void function__gc_mark(void* ud) { +void function__gc_mark(void* ud) { Function* func = ud; if(func->globals) pk__mark_value(func->globals); if(func->closure) { @@ -800,9 +800,6 @@ static bool function__doc__(int argc, py_Ref argv) { py_Type pk_function__register() { py_Type type = pk_newtype("function", tp_object, NULL, (void (*)(void*))Function__dtor, false, true); - - pk__tp_set_marker(type, function__gc_mark); - py_bindproperty(type, "__doc__", function__doc__, NULL); return type; }