use std::type_index

This commit is contained in:
blueloveTH 2024-04-04 00:12:01 +08:00
parent a5cb806749
commit 3b4d43714d
5 changed files with 8 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,13 +6,13 @@
namespace pkpy {
#define PY_CLASS(T, mod, name) \
static Type _type(VM* vm) { return vm->_cxx_typeid_map[&typeid(T)]; } \
static Type _type(VM* vm) { return vm->_cxx_typeid_map[typeid(T)]; } \
static PyObject* register_class(VM* vm, PyObject* mod, Type base=0) { \
std::string_view mod_name = PK_OBJ_GET(Str, mod->attr("__name__")).sv(); \
if(mod_name != #mod) throw std::runtime_error(_S("register_class() failed: ", mod_name, " != ", #mod).str()); \
PyObject* type = vm->new_type_object(mod, #name, base); \
mod->attr().set(#name, type); \
vm->_cxx_typeid_map[&typeid(T)] = PK_OBJ_GET(Type, type); \
vm->_cxx_typeid_map[typeid(T)] = PK_OBJ_GET(Type, type); \
T::_register(vm, mod, type); \
return type; \
}

View File

@ -18,7 +18,7 @@
#include <type_traits>
#include <random>
#include <deque>
#include <typeinfo>
#include <typeindex>
#include <initializer_list>
#define PK_VERSION "1.4.4"

View File

@ -123,7 +123,7 @@ public:
std::map<std::string_view, CodeObject_> _cached_codes;
// typeid -> Type
std::map<const std::type_info*, Type> _cxx_typeid_map;
std::map<const std::type_index, Type> _cxx_typeid_map;
void (*_ceval_on_step)(VM*, Frame*, Bytecode bc) = nullptr;
@ -436,7 +436,7 @@ public:
template<typename T>
Type _find_type_in_cxx_typeid_map(){
auto it = _cxx_typeid_map.find(&typeid(T));
auto it = _cxx_typeid_map.find(typeid(T));
if(it == _cxx_typeid_map.end()){
#if __GNUC__ || __clang__
throw std::runtime_error(__PRETTY_FUNCTION__ + std::string(" failed: T not found"));

View File

@ -23,7 +23,8 @@ def generate_python_sources():
namespace pkpy{
'''
for key, value in sources.items():
for key in sorted(sources.keys()):
value = sources[key]
header += f' inline const char kPythonLibs_{key}[] = {value};\n'
header += '}\n'
return header