Let the borrowed() hook survive an overload that did not match - #650
Merged
Merged
Conversation
Since pybind11 3.1.0 the post-call hook of a binding runs even when the arguments did not load, and is then handed the try-next-overload sentinel, a fake pointer of value 1, instead of an object. Before 3.1.0 a failed load returned before the hook. The borrowed() hook read the sentinel as an object and segfaulted on the first binding whose first overload rejects the arguments, which in the binding smoke test is Netlist.create_module called with a name, a parent, and a list of gates. That is what has been failing the macOS CI job since its Homebrew pybind11 moved to 3.1.0: the Ubuntu jobs build against an older pybind11 and never see it. Reproduced here after installing the same versions, and gone with this check. pybind11's own keep_alive<0, 1> shows the same crash on the same input, so this is worth reporting upstream. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the macOS CI failure in
runTest-python_binding_smokethat has been present on master since the runner's Homebrew pybind11 moved to 3.1.0.Since pybind11 3.1.0,
cpp_function::initializeruns the post-call hook of every attribute even when the overload's arguments did not load, handing it the try-next-overload sentinel ((PyObject*) 1) instead of an object. Before 3.1.0 a failed argument load returned before the hook. HAL'shal::borrowed()hook treated the sentinel as an object and segfaulted on the first binding whose first overload rejects the call. In the smoke test that isNetlist.create_module(name, parent, gates), whose four-argument overload is registered first.The hook now returns early on a null or sentinel handle. That is the whole change, plus a changelog entry.
Verification
/opt/homebrew/include, which is why the crash looked environment-specific for so long.py::keep_alive<0, 1>crashes on the same input with 3.1.0 and not with 3.0.4 (minimal reproducer: two overloads withkeep_alive<0, 1>, call with arguments matching only the second). This is an upstream regression and worth reporting to pybind11; the guard here is correct regardless.Test plan
runTest-python_binding_smoke🤖 Generated with Claude Code