This commit is contained in:
blueloveTH 2024-05-20 11:14:09 +08:00
parent e88744eadc
commit 3edbe7cdf5
2 changed files with 11 additions and 0 deletions

View File

@ -48,6 +48,8 @@ struct PyTypeInfo{
Vt(): _dtor(nullptr), _gc_mark(nullptr) {} Vt(): _dtor(nullptr), _gc_mark(nullptr) {}
operator bool() const { return _dtor || _gc_mark; }
template<typename T> template<typename T>
inline static Vt get(){ inline static Vt get(){
static_assert(std::is_same_v<T, std::decay_t<T>>); static_assert(std::is_same_v<T, std::decay_t<T>>);

View File

@ -212,6 +212,15 @@ namespace pkpy{
Str error = _S("type ", base_info.name.escape(), " is not `subclass_enabled`"); Str error = _S("type ", base_info.name.escape(), " is not `subclass_enabled`");
throw std::runtime_error(error.c_str()); throw std::runtime_error(error.c_str());
} }
if(base_info.vt){
if(vt){
Str error = _S("type ", base_info.name.escape(), " has a custom vtable, cannot override");
throw std::runtime_error(error.c_str());
}else{
// promote base vt to its subclass
vt = base_info.vt;
}
}
_all_types.emplace_back(obj, base, mod, name, subclass_enabled, vt); _all_types.emplace_back(obj, base, mod, name, subclass_enabled, vt);
return obj; return obj;
} }