From 4bb0ae303515b51506998b5114de16be532edab0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 20 Jun 2025 18:24:30 +0800 Subject: [PATCH] some optimize --- include/pocketpy/interpreter/typeinfo.h | 2 +- src/interpreter/vm.c | 4 ++-- src/modules/pickle.c | 4 ++-- src/public/internal.c | 2 +- src/public/py_object.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/pocketpy/interpreter/typeinfo.h b/include/pocketpy/interpreter/typeinfo.h index 88bf4c0a..958ff3a1 100644 --- a/include/pocketpy/interpreter/typeinfo.h +++ b/include/pocketpy/interpreter/typeinfo.h @@ -12,7 +12,7 @@ typedef struct py_TypeInfo { struct py_TypeInfo* base_ti; py_TValue self; - py_TValue module; // the module where the type is defined + py_GlobalRef module; bool is_python; // is it a python class? (not derived from c object) bool is_sealed; // can it be subclassed? diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 383987c6..dafac22b 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -44,7 +44,7 @@ static void py_TypeInfo__ctor(py_TypeInfo* self, py_Type index, py_Type base, py_TypeInfo* base_ti, - py_TValue module) { + py_GlobalRef module) { memset(self, 0, sizeof(py_TypeInfo)); self->name = name; @@ -403,7 +403,7 @@ py_Type pk_newtype(const char* name, if(base_ti && base_ti->is_sealed) { c11__abort("type '%s' is not an acceptable base type", py_name2str(base_ti->name)); } - py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? *module : *py_NIL()); + py_TypeInfo__ctor(ti, py_name(name), index, base, base_ti, module ? module : py_NIL()); if(!dtor && base) dtor = base_ti->dtor; ti->dtor = dtor; ti->is_python = is_python; diff --git a/src/modules/pickle.c b/src/modules/pickle.c index b9e2e6e3..3777371c 100644 --- a/src/modules/pickle.c +++ b/src/modules/pickle.c @@ -62,11 +62,11 @@ static void PickleObject__write_bytes(PickleObject* buf, const void* data, int s static void c11_sbuf__write_type_path(c11_sbuf* path_buf, py_Type type) { py_TypeInfo* ti = pk__type_info(type); - if(py_isnil(&ti->module)) { + if(py_isnil(ti->module)) { c11_sbuf__write_cstr(path_buf, py_name2str(ti->name)); return; } - const char* mod_path = py_tostr(py_getdict(&ti->module, __path__)); + const char* mod_path = py_tostr(py_getdict(ti->module, __path__)); c11_sbuf__write_cstr(path_buf, mod_path); c11_sbuf__write_char(path_buf, '.'); c11_sbuf__write_cstr(path_buf, py_name2str(ti->name)); diff --git a/src/public/internal.c b/src/public/internal.c index d1268624..8a9628d5 100644 --- a/src/public/internal.c +++ b/src/public/internal.c @@ -265,7 +265,7 @@ py_Ref py_tpfindname(py_Type t, py_Name name) { py_Type py_tpbase(py_Type t) { assert(t); py_TypeInfo* ti = pk__type_info(t); - return py_totype(&ti->base_ti->self); + return ti->base; } PK_DEPRECATED py_Ref py_tpgetmagic(py_Type type, py_Name name) { diff --git a/src/public/py_object.c b/src/public/py_object.c index 827c0065..c056642e 100644 --- a/src/public/py_object.c +++ b/src/public/py_object.c @@ -101,10 +101,10 @@ static bool type__or__(int argc, py_Ref argv) { static bool type__module__(int argc, py_Ref argv) { PY_CHECK_ARGC(1); py_TypeInfo* ti = pk__type_info(py_totype(argv)); - if(py_isnil(&ti->module)) { + if(py_isnil(ti->module)) { py_newnone(py_retval()); } else { - py_Ref path = py_getdict(&ti->module, __path__); + py_Ref path = py_getdict(ti->module, __path__); py_assign(py_retval(), path); } return true;