From e5d45e52096eecbb61aab0702970bbce7b8afd43 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 15 Nov 2024 16:30:15 +0100 Subject: [PATCH] Modernize DECREF in `rvp_rxd_to_callable_` (py_obj & result). --- src/nrnpython/nrnpy_hoc.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 44457053a5..98fdc41c04 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2843,12 +2843,10 @@ static Object** nrnpy_vec_to_python(void* v) { static Object* rvp_rxd_to_callable_(Object* obj) { if (obj) { - PyObject* py_obj = nrnpy_ho2po(obj); - PyObject* result = PyObject_CallFunctionObjArgs(nrnpy_rvp_pyobj_callback, py_obj, NULL); - Py_DECREF(py_obj); - Object* obj_result = nrnpy_po2ho(result); - Py_DECREF(result); // the previous line incremented the reference count - return obj_result; + auto py_obj = nb::steal(nrnpy_ho2po(obj)); + auto result = nb::steal( + PyObject_CallFunctionObjArgs(nrnpy_rvp_pyobj_callback, py_obj.ptr(), NULL)); + return nrnpy_po2ho(result.ptr()); } else { return 0; }