From 084725e2b36675165f196e77156bf3ae5a650dd2 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 29 Apr 2023 14:36:09 +0800 Subject: [PATCH] ... --- src/iter.h | 11 ++--------- src/obj.h | 11 ++++++++--- src/vm.h | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/iter.h b/src/iter.h index 94c59548..efa642a1 100644 --- a/src/iter.h +++ b/src/iter.h @@ -41,7 +41,7 @@ public: return array->operator[](index++); } - void _gc_mark() const override { + void _gc_mark() const{ OBJ_MARK(ref); } }; @@ -60,7 +60,7 @@ public: return VAR(str->u8_getitem(index++)); } - void _gc_mark() const override { + void _gc_mark() const{ OBJ_MARK(ref); } }; @@ -95,11 +95,4 @@ inline void Generator::_gc_mark() const{ for(PyObject* obj: s_backup) OBJ_MARK(obj); } -template -void gc_mark(T& t) { - if constexpr(std::is_base_of_v){ - t._gc_mark(); - } -} - } // namespace pkpy \ No newline at end of file diff --git a/src/obj.h b/src/obj.h index ffcf2ba7..5dd9ffab 100644 --- a/src/obj.h +++ b/src/obj.h @@ -93,7 +93,6 @@ protected: VM* vm; public: BaseIter(VM* vm) : vm(vm) {} - virtual void _gc_mark() const {} virtual PyObject* next() = 0; virtual ~BaseIter() = default; }; @@ -128,11 +127,18 @@ struct PyObject{ } }; +template struct has_gc_marker : std::false_type {}; +template struct has_gc_marker> : std::true_type {}; + template struct Py_ final: PyObject { T _value; void* value() override { return &_value; } - void _obj_gc_mark() override {} + void _obj_gc_mark() override { + if constexpr (has_gc_marker::value) { + _value._gc_mark(); + } + } Py_(Type type, const T& value) : PyObject(type), _value(value) {} Py_(Type type, T&& value) : PyObject(type), _value(std::move(value)) {} }; @@ -140,7 +146,6 @@ struct Py_ final: PyObject { struct MappingProxy{ PyObject* obj; MappingProxy(PyObject* obj) : obj(obj) {} - NameDict& attr() noexcept { return obj->attr(); } }; diff --git a/src/vm.h b/src/vm.h index b360d941..c4ce61d0 100644 --- a/src/vm.h +++ b/src/vm.h @@ -55,7 +55,7 @@ public: } PyObject* next() override; - void _gc_mark() const override; + void _gc_mark() const; }; struct PyTypeInfo{