@@ -265,10 +265,10 @@ PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp,
265265 return handle ((PyObject *) type_info->type );
266266 }
267267 if (foreign_ok) {
268- auto &foreign_internals = detail::get_foreign_internals ();
269- if (foreign_internals .imported_any ) {
268+ auto &interop_internals = detail::get_interop_internals ();
269+ if (interop_internals .imported_any ) {
270270 handle ret = with_internals ([&](internals &) {
271- auto range = foreign_internals .bindings .equal_range (tp);
271+ auto range = interop_internals .bindings .equal_range (tp);
272272 if (range.first != range.second ) {
273273 return handle ((PyObject *) range.first ->second ->pytype );
274274 }
@@ -1052,7 +1052,7 @@ class type_caster_generic {
10521052 if (!srcs.result .second ) {
10531053 // No pybind11 type info. See if we can use another framework's
10541054 // type to complete this cast. Set srcs.used_foreign if so.
1055- if (get_foreign_internals ().imported_any ) {
1055+ if (get_interop_internals ().imported_any ) {
10561056 if (handle ret = cast_foreign (srcs, policy, parent)) {
10571057 return ret;
10581058 }
@@ -1215,10 +1215,11 @@ class type_caster_generic {
12151215 return nullptr ;
12161216 }
12171217
1218- // / Try to load as a type exposed by a different binding framework.
1218+ // / Try to load as a type exposed by a different binding framework (which
1219+ // / might be an ABI-incompatible version of pybind11).
12191220 bool try_load_other_framework (handle src, bool convert) {
1220- auto &foreign_internals = get_foreign_internals ();
1221- if (!foreign_internals .imported_any || !cpptype || src.is_none ()) {
1221+ auto &interop_internals = get_interop_internals ();
1222+ if (!interop_internals .imported_any || !cpptype || src.is_none ()) {
12221223 return false ;
12231224 }
12241225
@@ -1245,30 +1246,35 @@ class type_caster_generic {
12451246 return false ;
12461247 }
12471248
1248- // / Try to load with foreign typeinfo, if available. Used when there is no
1249- // / native typeinfo, or when the native one wasn't able to produce a value.
1250- PYBIND11_NOINLINE bool try_load_foreign (handle src, bool convert) {
1251- constexpr auto *local_key = PYBIND11_MODULE_LOCAL_ID;
1252- const auto pytype = type::handle_of (src);
1253- if (!hasattr (pytype, local_key)) {
1254- return try_load_other_framework (src, convert);
1255- }
1256-
1257- type_info *foreign_typeinfo = reinterpret_borrow<capsule>(getattr (pytype, local_key));
1258- // Only consider this foreign loader if actually foreign and is a loader of the correct cpp
1259- // type
1260- if (foreign_typeinfo->module_local_load == &local_load
1261- || (cpptype && !same_type (*cpptype, *foreign_typeinfo->cpptype ))) {
1249+ // / Try to load as a type bound as py::module_local() in a different (but
1250+ // / ABI-compatible) pybind11 module.
1251+ bool try_load_other_module_local (handle src, type_info *remote_typeinfo) {
1252+ // Only consider this loader if it's not ours and it loads the correct cpp type
1253+ if (remote_typeinfo->module_local_load == &local_load
1254+ || (cpptype && !same_type (*cpptype, *remote_typeinfo->cpptype ))) {
12621255 return false ;
12631256 }
12641257
1265- if (auto *result = foreign_typeinfo ->module_local_load (src.ptr (), foreign_typeinfo )) {
1258+ if (auto *result = remote_typeinfo ->module_local_load (src.ptr (), remote_typeinfo )) {
12661259 value = result;
12671260 return true ;
12681261 }
12691262 return false ;
12701263 }
12711264
1265+ // / Try to load with foreign typeinfo, if available. Used when there is no
1266+ // / native typeinfo, or when the native one wasn't able to produce a value.
1267+ PYBIND11_NOINLINE bool try_load_foreign (handle src, bool convert) {
1268+ constexpr auto *local_key = PYBIND11_MODULE_LOCAL_ID;
1269+ const auto pytype = type::handle_of (src);
1270+ if (hasattr (pytype, local_key)) {
1271+ return try_load_other_module_local (
1272+ src, reinterpret_borrow<capsule>(getattr (pytype, local_key)));
1273+ } else {
1274+ return try_load_other_framework (src, convert);
1275+ }
1276+ }
1277+
12721278 // Implementation of `load`; this takes the type of `this` so that it can dispatch the relevant
12731279 // bits of code between here and copyable_holder_caster where the two classes need different
12741280 // logic (without having to resort to virtual inheritance).
0 commit comments