From 9b880ba743a39b35cfa3b806a96c5f99428d7c2b Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 25 Apr 2016 03:25:13 +0200 Subject: [PATCH] keep_alive: don't fail when there is no patient --- include/pybind11/pybind11.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index f653ba97f..e93139200 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -982,6 +982,9 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg if (!nurse || !patient) pybind11_fail("Could not activate keep_alive!"); + if (patient.ptr() == Py_None) + return; /* Nothing to keep alive */ + cpp_function disable_lifesupport( [patient](handle weakref) { patient.dec_ref(); weakref.dec_ref(); });