This commit is contained in:
blueloveTH 2023-04-29 14:36:09 +08:00
parent e384407494
commit 084725e2b3
3 changed files with 11 additions and 13 deletions

View File

@ -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<typename T>
void gc_mark(T& t) {
if constexpr(std::is_base_of_v<BaseIter, T>){
t._gc_mark();
}
}
} // namespace pkpy

View File

@ -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 <typename, typename=void> struct has_gc_marker : std::false_type {};
template <typename T> struct has_gc_marker<T, std::void_t<decltype(&T::_gc_mark)>> : std::true_type {};
template <typename T>
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<T>::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(); }
};

View File

@ -55,7 +55,7 @@ public:
}
PyObject* next() override;
void _gc_mark() const override;
void _gc_mark() const;
};
struct PyTypeInfo{