From 2868a955bbdc1e8185f9c862accbcb25caf976a5 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 20 May 2024 18:20:41 +0800 Subject: [PATCH] some fix --- include/pocketpy/obj.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h index 53497c93..77c5f6d4 100644 --- a/include/pocketpy/obj.h +++ b/include/pocketpy/obj.h @@ -102,12 +102,14 @@ struct Slice { }; struct PyObject final{ + static constexpr int FIXED_SIZE = 16; + bool gc_marked; // whether this object is marked Type type; // we have a duplicated type here for saving memory NameDict* _attr; bool is_attr_valid() const noexcept { return _attr != nullptr; } - void* _value_ptr() noexcept { return 1 + &_attr; } + void* _value_ptr() noexcept { return (char*)this + FIXED_SIZE; } NameDict& attr() { PK_DEBUG_ASSERT(is_attr_valid()) @@ -144,10 +146,9 @@ struct PyObject final{ } }; +static_assert(sizeof(PyObject) <= PyObject::FIXED_SIZE); template -inline constexpr int py_sizeof = sizeof(PyObject) + sizeof(T); - -static_assert(sizeof(PyObject) <= 16); +inline constexpr int py_sizeof = PyObject::FIXED_SIZE + sizeof(T); const int kTpIntIndex = 3; const int kTpFloatIndex = 4;