From a96173fd6a9eff2e4dd5c57775e042010dc764c8 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 9 Aug 2024 13:11:56 +0800 Subject: [PATCH] ... --- src/interpreter/ceval.c | 7 +++++++ src/interpreter/vm.c | 6 +++++- src/public/py_exception.c | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index b5dbcb8d..492bf961 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -909,6 +909,13 @@ FrameResult VM__run_top_frame(VM* self) { base = py_totype(TOP()); } POP(); + + py_TypeInfo* base_ti = c11__at(py_TypeInfo, &self->types, base); + if(base_ti->is_sealed){ + TypeError("type '%t' is not an acceptable base type", base); + goto __ERROR; + } + py_Type type = pk_newtype(py_name2str(name), base, frame->module, NULL, true, false); PUSH(py_tpobject(type)); diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 1d8049d7..4e3590f9 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -313,8 +313,12 @@ py_Type pk_newtype(const char* name, c11_vector* types = &pk_current_vm->types; py_Type index = types->count; py_TypeInfo* ti = c11_vector__emplace(types); + py_TypeInfo* base_ti = base ? c11__at(py_TypeInfo, types, base) : NULL; + 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, module ? *module : *py_NIL); - if(!dtor && base) { dtor = c11__at(py_TypeInfo, types, base)->dtor; } + if(!dtor && base) dtor = base_ti->dtor; ti->dtor = dtor; ti->is_python = is_python; ti->is_sealed = is_sealed; diff --git a/src/public/py_exception.c b/src/public/py_exception.c index 4ccdeee1..8c328c43 100644 --- a/src/public/py_exception.c +++ b/src/public/py_exception.c @@ -106,7 +106,7 @@ py_Type pk_BaseException__register() { } py_Type pk_Exception__register() { - py_Type type = pk_newtype("Exception", tp_BaseException, NULL, NULL, false, true); + py_Type type = pk_newtype("Exception", tp_BaseException, NULL, NULL, false, false); return type; }