Revert internal version bump

This commit is contained in:
Xuehai Pan
2025-12-17 11:22:54 +08:00
parent b61e902dce
commit b72cd4162b
4 changed files with 24 additions and 5 deletions

View File

@@ -226,12 +226,14 @@ extern "C" inline void pybind11_meta_dealloc(PyObject *obj) {
local_internals.registered_types_cpp.erase(tinfo->cpptype);
} else {
internals.registered_types_cpp.erase(tindex);
#if PYBIND11_INTERNALS_VERSION >= 12
internals.registered_types_cpp_fast.erase(tinfo->cpptype);
for (const std::type_info *alias : tinfo->alias_chain) {
auto num_erased = internals.registered_types_cpp_fast.erase(alias);
(void) num_erased;
assert(num_erased > 0);
}
#endif
}
internals.registered_types_py.erase(tinfo->type);

View File

@@ -39,11 +39,11 @@
/// further ABI-incompatible changes may be made before the ABI is officially
/// changed to the new version.
#ifndef PYBIND11_INTERNALS_VERSION
# define PYBIND11_INTERNALS_VERSION 12
# define PYBIND11_INTERNALS_VERSION 11
#endif
#if PYBIND11_INTERNALS_VERSION < 12
# error "PYBIND11_INTERNALS_VERSION 12 is the minimum for all platforms for pybind11v3."
#if PYBIND11_INTERNALS_VERSION < 11
# error "PYBIND11_INTERNALS_VERSION 11 is the minimum for all platforms for pybind11v3."
#endif
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
@@ -242,12 +242,14 @@ struct internals {
pymutex mutex;
pymutex exception_translator_mutex;
#endif
#if PYBIND11_INTERNALS_VERSION >= 12
// non-normative but fast "hint" for registered_types_cpp. Meant
// to be used as the first level of a two-level lookup: successful
// lookups are correct, but unsuccessful lookups need to try
// registered_types_cpp and then backfill this map if they find
// anything.
fast_type_map<type_info *> registered_types_cpp_fast;
#endif
// std::type_index -> pybind11's type information
type_map<type_info *> registered_types_cpp;
@@ -273,6 +275,9 @@ struct internals {
PyObject *instance_base = nullptr;
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
thread_specific_storage<PyThreadState> tstate;
#if PYBIND11_INTERNALS_VERSION <= 11
thread_specific_storage<loader_life_support> loader_life_support_tls; // OBSOLETE (PR #5830)
#endif
// Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined:
PyInterpreterState *istate = nullptr;
@@ -353,6 +358,7 @@ struct type_info {
void *(*module_local_load)(PyObject *, const type_info *) = nullptr;
holder_enum_t holder_enum_v = holder_enum_t::undefined;
#if PYBIND11_INTERNALS_VERSION >= 12
// When a type appears in multiple DSOs,
// internals::registered_types_cpp_fast will have multiple distinct
// keys (the std::type_info from each DSO) mapped to the same
@@ -363,6 +369,7 @@ struct type_info {
// nb_alias_chain` added in
// https://github.com/wjakob/nanobind/commit/b515b1f7f2f4ecc0357818e6201c94a9f4cbfdc2
std::forward_list<const std::type_info *> alias_chain;
#endif
/* A simple type never occurs as a (direct or indirect) parent
* of a class that makes use of multiple inheritance.

View File

@@ -227,26 +227,32 @@ inline detail::type_info *get_global_type_info_lock_held(const std::type_info &t
// next time.
detail::type_info *type_info = nullptr;
auto &internals = get_internals();
#if PYBIND11_INTERNALS_VERSION >= 12
auto &fast_types = internals.registered_types_cpp_fast;
#endif
auto &types = internals.registered_types_cpp;
#if PYBIND11_INTERNALS_VERSION >= 12
auto fast_it = fast_types.find(&tp);
if (fast_it != fast_types.end()) {
#ifndef NDEBUG
# ifndef NDEBUG
auto types_it = types.find(std::type_index(tp));
assert(types_it != types.end());
assert(types_it->second == fast_it->second);
#endif
# endif
return fast_it->second;
}
#endif // PYBIND11_INTERNALS_VERSION >= 12
auto it = types.find(std::type_index(tp));
if (it != types.end()) {
#if PYBIND11_INTERNALS_VERSION >= 12
// We found the type in the slow map but not the fast one, so
// some other DSO added it (otherwise it would be in the fast
// map under &tp) and therefore we must be an alias. Record
// that.
it->second->alias_chain.push_front(&tp);
fast_types.emplace(&tp, it->second);
#endif
type_info = it->second;
}
return type_info;

View File

@@ -1692,7 +1692,9 @@ protected:
local_internals.registered_types_cpp[rec.type] = tinfo;
} else {
internals.registered_types_cpp[tindex] = tinfo;
#if PYBIND11_INTERNALS_VERSION >= 12
internals.registered_types_cpp_fast[rec.type] = tinfo;
#endif
}
PYBIND11_WARNING_PUSH
@@ -2199,7 +2201,9 @@ public:
type_info *const val
= internals.registered_types_cpp[std::type_index(typeid(type))];
internals.registered_types_cpp[std::type_index(typeid(type_alias))] = val;
#if PYBIND11_INTERNALS_VERSION >= 12
internals.registered_types_cpp_fast[&typeid(type_alias)] = val;
#endif
}
});
}