Skip to content

Commit 3ca29e8

Browse files
committed
Implement reviewer comments: revert PY_VERSION_HEX change, fix REVIEW comment, add two-level lookup comments. ci.yml coming separately
1 parent 8651580 commit 3ca29e8

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

include/pybind11/detail/internals.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@
3939
/// further ABI-incompatible changes may be made before the ABI is officially
4040
/// changed to the new version.
4141
#ifndef PYBIND11_INTERNALS_VERSION
42-
# if PY_VERSION_HEX >= 0x030E0000
43-
// Get test coverage for ABI version 12 without breaking existing
44-
// Python versions.
45-
# define PYBIND11_INTERNALS_VERSION 12
46-
# else
47-
# define PYBIND11_INTERNALS_VERSION 11
48-
# endif
42+
# define PYBIND11_INTERNALS_VERSION 11
4943
#endif
5044

5145
#if PYBIND11_INTERNALS_VERSION < 11
@@ -182,10 +176,10 @@ struct type_equal_to {
182176
};
183177
#endif
184178

179+
// For now, we don't bother adding a fancy hash for pointers and just
180+
// let the standard library use the identity hash function if that's
181+
// what it wants to do (e.g., as in libstdc++).
185182
template <typename value_type>
186-
// REVIEW: do we need to add a fancy hash for pointers or is the
187-
// possible identity hash function from the standard library (e.g.,
188-
// libstdc++) sufficient?
189183
using fast_type_map = std::unordered_map<const std::type_info *, value_type>;
190184

191185
template <typename value_type>
@@ -249,10 +243,11 @@ struct internals {
249243
pymutex exception_translator_mutex;
250244
#endif
251245
#if PYBIND11_INTERNALS_VERSION >= 12
252-
// non-normative but fast "hint" for
253-
// registered_types_cpp. Successful lookups are correct;
254-
// unsuccessful lookups need to try registered_types_cpp and then
255-
// backfill this map if they find anything.
246+
// non-normative but fast "hint" for registered_types_cpp. Meant
247+
// to be used as the first level of a two-level lookup: successful
248+
// lookups are correct, but unsuccessful lookups need to try
249+
// registered_types_cpp and then backfill this map if they find
250+
// anything.
256251
fast_type_map<type_info *> registered_types_cpp_fast;
257252
#endif
258253

include/pybind11/detail/type_caster_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ inline detail::type_info *get_local_type_info(const std::type_info &tp) {
215215
}
216216

217217
inline detail::type_info *get_global_type_info(const std::type_info &tp) {
218+
// This is a two-level lookup. Hopefully we find the type info in
219+
// registered_types_cpp_fast, but if not we try
220+
// registered_types_cpp and fill registered_types_cpp_fast for
221+
// next time.
218222
return with_internals([&](internals &internals) {
219223
detail::type_info *type_info = nullptr;
220224
#if PYBIND11_INTERNALS_VERSION >= 12

0 commit comments

Comments
 (0)