Repository navigation
fix: use the internals registry in type_is_managed_by_our_internals() - #6229
Conversation
Comparing tp_new against this module's pybind11_object_new fails for types whose pybind11_object base was created by another module (the inherited pointer belongs to that module's copy). The registry lookup, which was the PyPy path, is correct across modules and does not read type-object fields. See pybind#6104 (B5). Assisted-by: ClaudeCode:claude-opus-5-5
— codex GPT-6 on behalf of Ralf — Check that a Python proxy can still forward conduit conversions after all_type_info caches that its type has no registered pybind11 bases. The same conversion succeeds before and after populating the empty entry. The regression fails if the nonempty-entry condition is removed.
|
— codex GPT-6 on behalf of Ralf — Added 3c34d7f2 to cover the second fix: an empty cached I rebuilt and ran the full local default and free-threaded CPython 3.14.4 suites (GCC 13.3, C++20), temporarily removing only
In both runs, the only failure was After restoring the guard and rebuilding, both full suites passed again: 1,458 default and 1,441 free-threaded tests. All formatting/lint checks also passed. I updated the PR description and suggested changelog to document both fixes. |
rwgk
left a comment
There was a problem hiding this comment.
Thanks for catching the two bugs!
— codex GPT-6 on behalf of Ralf —
Description
On non-PyPy builds,
type_is_managed_by_our_internals()comparedtp_newwith this module'spybind11_object_new. Each extension module has its own copy of that function. A type whosepybind11_objectbase was created by a different module (which shares the same internals) inherits the other module's pointer, so the check gave the wrong result in all modules except the one that created the internals. The conduit lookup then used the genericgetattrpath for types that pybind11 manages.This change uses the
registered_types_pylookup, which was already the PyPy path, on all platforms. It also removes the forward declaration ofpybind11_object_newfromcpp_conduit.hbecause nothing uses it now.The existing PyPy registry path had a second bug:
registered_types_pyalso caches empty vectors for types with no registered pybind11 bases. An empty entry was incorrectly treated as evidence that the type was managed, which could cause its Python-defined conduit method to be ignored. The lookup now also requires!it->second.empty().The cross-module test subclasses
Travelerin Python and overrides_pybind11_conduit_v1_with a plain function. Then it callsget_pointsfrompybind11_testsand fromhome_planet_very_lonely_traveler. Both modules must skip the override. Without the fix,home_planet_very_lonely_travelercalls it.An additional regression uses a Python proxy that forwards the conduit method to a wrapped
Traveler. Conversion must succeed both before and after caching that the proxy type has no registered pybind11 bases. It fails after caching if the nonempty-entry check is removed.From finding B5 in #6104.
Suggested changelog entry:
type_is_managed_by_our_internals()for modules that share internals but did not create thepybind11_objectbase type. It now uses the internals registry on all platforms.