File tree 4 files changed +11
-4
lines changed 4 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,9 @@ struct type_record {
238
238
// / What is the alignment of the underlying C++ type?
239
239
size_t type_align = 0 ;
240
240
241
+ // Pointer to RTTI type_info data structure of holder type
242
+ const std::type_info *holder_type = nullptr ;
243
+
241
244
// / How large is the type's holder?
242
245
size_t holder_size = 0 ;
243
246
Original file line number Diff line number Diff line change @@ -1496,14 +1496,16 @@ void check_for_holder_mismatch_impl() {
1496
1496
using iholder = intrinsic_t <holder>;
1497
1497
using base_type = decltype (*holder_helper<iholder>::get (std::declval<iholder>()));
1498
1498
auto &holder_typeinfo = typeid (iholder);
1499
- auto ins = get_internals ().holders_seen .emplace (typeid (base_type), &holder_typeinfo);
1499
+ auto base_info = detail::get_type_info (typeid (base_type));
1500
+ if (!base_info)
1501
+ return ; // Don't complain if we see this type the first time
1500
1502
1501
1503
auto debug = type_id<base_type>();
1502
- if (!ins. second && ! same_type (*ins. first -> second , holder_typeinfo)) {
1504
+ if (!same_type (*base_info-> holder_type , holder_typeinfo)) {
1503
1505
#ifdef NDEBUG
1504
1506
pybind11_fail (" Mismatched holders detected (compile in debug mode for details)" );
1505
1507
#else
1506
- std::string seen_holder_name (ins. first -> second ->name ());
1508
+ std::string seen_holder_name (base_info-> holder_type ->name ());
1507
1509
detail::clean_type_id (seen_holder_name);
1508
1510
pybind11_fail (" Mismatched holders detected: "
1509
1511
" attempting to use holder type " + type_id<iholder>() + " , but " + type_id<base_type>() +
Original file line number Diff line number Diff line change @@ -97,7 +97,6 @@ struct internals {
97
97
type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information
98
98
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s)
99
99
std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance*
100
- type_map<const std::type_info *> holders_seen; // type -> seen holder type (to detect holder conflicts)
101
100
std::unordered_set<std::pair<const PyObject *, const char *>, override_hash> inactive_override_cache;
102
101
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
103
102
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
@@ -129,6 +128,7 @@ struct internals {
129
128
struct type_info {
130
129
PyTypeObject *type;
131
130
const std::type_info *cpptype;
131
+ const std::type_info *holder_type = nullptr ;
132
132
size_t type_size, type_align, holder_size_in_ptrs;
133
133
void *(*operator_new)(size_t );
134
134
void (*init_instance)(instance *, const void *);
Original file line number Diff line number Diff line change @@ -1045,6 +1045,7 @@ class generic_type : public object {
1045
1045
auto *tinfo = new detail::type_info ();
1046
1046
tinfo->type = (PyTypeObject *) m_ptr;
1047
1047
tinfo->cpptype = rec.type ;
1048
+ tinfo->holder_type = rec.holder_type ;
1048
1049
tinfo->type_size = rec.type_size ;
1049
1050
tinfo->type_align = rec.type_align ;
1050
1051
tinfo->operator_new = rec.operator_new ;
@@ -1233,6 +1234,7 @@ class class_ : public detail::generic_type {
1233
1234
record.type = &typeid (type);
1234
1235
record.type_size = sizeof (conditional_t <has_alias, type_alias, type>);
1235
1236
record.type_align = alignof (conditional_t <has_alias, type_alias, type>&);
1237
+ record.holder_type = &typeid (holder_type);
1236
1238
record.holder_size = sizeof (holder_type);
1237
1239
record.init_instance = init_instance;
1238
1240
record.dealloc = dealloc;
You can’t perform that action at this time.
0 commit comments