Skip to content

Let the borrowed() hook survive an overload that did not match - #650

Merged
julianspeith merged 2 commits into
masterfrom
fix/borrowed-postcall-sentinel
Sep 10, 2026
Merged

julianspeith merged 2 commits into
masterfrom
fix/borrowed-postcall-sentinel

Conversation

@julianspeith

Copy link
Copy Markdown
Contributor

Summary

Fixes the macOS CI failure in runTest-python_binding_smoke that has been present on master since the runner's Homebrew pybind11 moved to 3.1.0.

Since pybind11 3.1.0, cpp_function::initialize runs 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's hal::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 is Netlist.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

  • Reproduced locally only after installing the runner's versions (Homebrew Python 3.14.7, pybind11 3.1.0): the smoke test segfaults at the same line with the same C stack as CI. Earlier attempts with a pip-installed pybind11 3.1.0 silently compiled against Homebrew's 3.0.1 headers in /opt/homebrew/include, which is why the crash looked environment-specific for so long.
  • With this change the full suite passes, 39 of 39, on a Debug build against those versions.
  • pybind11's own py::keep_alive<0, 1> crashes on the same input with 3.1.0 and not with 3.0.4 (minimal reproducer: two overloads with keep_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

  • macOS CI green, including runTest-python_binding_smoke
  • Ubuntu jobs unchanged

🤖 Generated with Claude Code

julianspeith and others added 2 commits September 10, 2026 13:53
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>
@julianspeith
julianspeith merged commit 078b17d into master Sep 10, 2026
5 checks passed
@julianspeith
julianspeith deleted the fix/borrowed-postcall-sentinel branch September 10, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant