MCPcopy Create free account
hub / github.com/pybind/pybind11 / keep_alive_impl

Function keep_alive_impl

include/pybind11/pybind11.h:3231–3259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3229PYBIND11_NAMESPACE_BEGIN(detail)
3230
3231PYBIND11_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
3261PYBIND11_NOINLINE void
3262keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret) {

Callers 5

precallMethod · 0.85
postcallMethod · 0.85
castMethod · 0.85

Calls 8

add_patientFunction · 0.85
ptrMethod · 0.80
dec_refMethod · 0.80
inc_refMethod · 0.80
releaseMethod · 0.80
handleFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected