mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 17:26:13 +00:00
Support keep_alive where nurse may be None
For example keep_alive<0,1>() should work where the return value may sometimes be None. At present a "Could not allocate weak reference!" exception is thrown. Update documentation to clarify behaviour of keep_alive when nurse is None or does not support weak references.
This commit is contained in:
@@ -1098,8 +1098,8 @@ inline void keep_alive_impl(handle nurse, handle patient) {
|
||||
if (!nurse || !patient)
|
||||
pybind11_fail("Could not activate keep_alive!");
|
||||
|
||||
if (patient.ptr() == Py_None)
|
||||
return; /* Nothing to keep alive */
|
||||
if (patient.ptr() == Py_None || nurse.ptr() == Py_None)
|
||||
return; /* Nothing to keep alive or nothing to be kept alive by */
|
||||
|
||||
cpp_function disable_lifesupport(
|
||||
[patient](handle weakref) { patient.dec_ref(); weakref.dec_ref(); });
|
||||
|
||||
Reference in New Issue
Block a user