Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std::shared_ptr<T>
bindings: avoid leaks at interpreter shutdown
The ``nb::shared_ptr<T>`` binding implementation may sometimes need to create a shared pointer wrapper around an object that was originally constructed in Python. Eventual expiry of this shared pointer will decrease the reference count of the underlying Python object. However, this is unsafe to do when Python is already shut down, which the implementation previously checked by querying ``Py_IsInitialized()``. It turns out that this is a bit too conservative since it also prevents proper cleanup *during* shutdown time/finalization (``Py_IsInitialized()`` already returns zero at this point). This commit changes the criterion to ``nb::is_alive()``.
- Loading branch information