| 3229 | PYBIND11_NAMESPACE_BEGIN(detail) |
| 3230 | |
| 3231 | PYBIND11_NOINLINE void keep_alive_impl(handle nurse, handle patient) { |
| 3232 | if (!nurse || !patient) { |
| 3233 | pybind11_fail("Could not activate keep_alive!"); |
| 3234 | } |
| 3235 | |
| 3236 | if (patient.is_none() || nurse.is_none()) { |
| 3237 | return; /* Nothing to keep alive or nothing to be kept alive by */ |
| 3238 | } |
| 3239 | |
| 3240 | auto tinfo = all_type_info(Py_TYPE(nurse.ptr())); |
| 3241 | if (!tinfo.empty()) { |
| 3242 | /* It's a pybind-registered type, so we can store the patient in the |
| 3243 | * internal list. */ |
| 3244 | add_patient(nurse.ptr(), patient.ptr()); |
| 3245 | } else { |
| 3246 | /* Fall back to clever approach based on weak references taken from |
| 3247 | * Boost.Python. This is not used for pybind-registered types because |
| 3248 | * the objects can be destroyed out-of-order in a GC pass. */ |
| 3249 | cpp_function disable_lifesupport([patient](handle weakref) { |
| 3250 | patient.dec_ref(); |
| 3251 | weakref.dec_ref(); |
| 3252 | }); |
| 3253 | |
| 3254 | weakref wr(nurse, disable_lifesupport); |
| 3255 | |
| 3256 | patient.inc_ref(); /* reference patient and leak the weak reference */ |
| 3257 | (void) wr.release(); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | PYBIND11_NOINLINE void |
| 3262 | keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret) { |
no test coverage detected