From bf481b84dc50732517fccb36e446ffa9bb6c8c57 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 13 May 2024 02:20:11 +0800 Subject: [PATCH] some fix --- include/pocketpy/gc.h | 4 ++-- include/pocketpy/tuplelist.h | 4 +++- src/gc.cpp | 6 +++--- src/pocketpy.cpp | 2 +- src/tuplelist.cpp | 2 +- src/vm.cpp | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/pocketpy/gc.h b/include/pocketpy/gc.h index 503d1953..99f6309f 100644 --- a/include/pocketpy/gc.h +++ b/include/pocketpy/gc.h @@ -42,7 +42,7 @@ struct ManagedHeap{ PyVar gcnew(Type type, Args&&... args){ using __T = Py_>; // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476 - PyObject* p = new(pool64_alloc<__T>()) Py_>(std::forward(args)...); + PyObject* p = new(pool128_alloc<__T>()) Py_>(std::forward(args)...); PyVar obj(type, p); gen.push_back(obj); gc_counter++; @@ -53,7 +53,7 @@ struct ManagedHeap{ PyVar _new(Type type, Args&&... args){ using __T = Py_>; // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476 - PyObject* p = new(pool64_alloc<__T>()) Py_>(std::forward(args)...); + PyObject* p = new(pool128_alloc<__T>()) Py_>(std::forward(args)...); PyVar obj(type, p); obj->gc_enabled = false; _no_gc.push_back(obj); diff --git a/include/pocketpy/tuplelist.h b/include/pocketpy/tuplelist.h index d4e3c974..e8fd5779 100644 --- a/include/pocketpy/tuplelist.h +++ b/include/pocketpy/tuplelist.h @@ -10,8 +10,10 @@ namespace pkpy { using List = pod_vector; struct Tuple { + static const int INLINED_SIZE = 4; + PyVar* _args; - PyVar _inlined[4]; + PyVar _inlined[INLINED_SIZE]; int _size; Tuple(int n); diff --git a/src/gc.cpp b/src/gc.cpp index 24f0ca6d..eade7843 100644 --- a/src/gc.cpp +++ b/src/gc.cpp @@ -14,7 +14,7 @@ namespace pkpy{ #endif if(_gc_on_delete) _gc_on_delete(vm, obj); obj->~PyObject(); - pool64_dealloc(obj.get()); + pool128_dealloc(obj.get()); } } @@ -55,8 +55,8 @@ namespace pkpy{ } ManagedHeap::~ManagedHeap(){ - for(PyVar obj: _no_gc) { obj->~PyObject(); pool64_dealloc(obj.get()); } - for(PyVar obj: gen) { obj->~PyObject(); pool64_dealloc(obj.get()); } + for(PyVar obj: _no_gc) { obj->~PyObject(); pool128_dealloc(obj.get()); } + for(PyVar obj: gen) { obj->~PyObject(); pool128_dealloc(obj.get()); } } diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 10069b50..83cb013d 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -1530,7 +1530,7 @@ void VM::__post_init_builtin_types(){ bind_property(_t(tp_object), "__class__", PK_LAMBDA(vm->_t(args[0]))); bind_property(_t(tp_type), "__base__", [](VM* vm, ArgsView args){ const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])]; - return info.base.index == -1 ? vm->None : vm->_all_types[info.base].obj; + return info.base ? vm->_all_types[info.base].obj : vm->None; }); bind_property(_t(tp_type), "__name__", [](VM* vm, ArgsView args){ const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])]; diff --git a/src/tuplelist.cpp b/src/tuplelist.cpp index 2d28e0b0..888b5fe1 100644 --- a/src/tuplelist.cpp +++ b/src/tuplelist.cpp @@ -3,7 +3,7 @@ namespace pkpy { Tuple::Tuple(int n){ - if(n <= 3){ + if(n <= INLINED_SIZE){ this->_args = _inlined; }else{ this->_args = (PyVar*)pool128_alloc(n * sizeof(void*)); diff --git a/src/vm.cpp b/src/vm.cpp index 374270ff..e5cdf076 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -149,7 +149,7 @@ namespace pkpy{ val = _t(cls)->attr().try_get(name); if(val != nullptr) return val; cls = _all_types[cls].base; - if(cls.index == -1) break; + if(!cls) break; }while(true); return nullptr; } @@ -162,7 +162,7 @@ namespace pkpy{ do{ if(cls == base) return true; Type next = _all_types[cls].base; - if(next.index == -1) break; + if(!next) break; cls = next; }while(true); return false;