Skip to content

fix: raise instead of aborting when instantiating pybind11_object - #6244

Open
kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-pybind11-object-new-abort
Open

kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-pybind11-object-new-abort

Conversation

@kroplabeskidu

Copy link
Copy Markdown

Description

Item 11 from #6159. Calling pybind11_object() from Python, or a Python subclass of it with no registered C++ base, aborts the process because a C++ exception reaches the interpreter through the extern "C" tp_new:

terminate called after throwing an instance of 'std::runtime_error'
  what():  instance allocation failed: new instance has no pybind11-registered base types
  • pybind11_object_new now turns exceptions into Python errors, so this case raises TypeError.
  • make_new_instance checks the tp_alloc result, and releases the object if allocate_layout() throws.
  • clear_instance now uses the values_and_holders(PyObject *) constructor, which gives an empty iteration for a type with no registered base. Without this, releasing the object segfaulted in a release build, and the iterator has an assert for this case in debug builds.

The new test aborts the test process without this fix. I ran it in both release and debug builds.

Suggested changelog entry:

  • Instantiating pybind11_object from Python now raises TypeError instead of aborting the process.

This branch has not been deployed

No deployments
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