Closed
Description
Issue description
- Initialize an interpreter
- Call
make_iterator
on some begin/end pair of a container - Finalize interpreter, initialize it again
- Call
make_iterator
again, same as above
Result: An exception is thrown "instance allocation failed: new instance has no pybind11-registered base types".
Reproducible example code
std::vector<int> container;
// Initialize an interpreter
pybind11::initialize_interpreter();
// Call make_iterator
{
pybind11::gil_scoped_acquire gil;
auto iter = pybind11::make_iterator(container.begin(), container.end());
}
// Finalizer interpreter, initialize it again
pybind11::finalize_interpreter();
pybind11::initialize_interpreter();
// Call make iterator again
{
pybind11::gil_scoped_acquire gil;
auto iter = pybind11::make_iterator(container.begin(), container.end());
}
pybind11::finalize_interpreter();
Proposed Fix
The culprit seems to be static state in pybind11::detail::registered_local_types_cpp()
. Clearing that container (deleting the heap-allocated values in it beforehand) in finalize_interpreter()
appears to fix the issue.