diff --git a/src/nrnpython/nrnpy_p2h.cpp b/src/nrnpython/nrnpy_p2h.cpp index 78c9b681bb..aecc00a8b7 100644 --- a/src/nrnpython/nrnpy_p2h.cpp +++ b/src/nrnpython/nrnpy_p2h.cpp @@ -844,10 +844,10 @@ static Object* py_alltoall_type(int size, int type) { #if NRNMPI setpickle(); int root; - PyObject* pdest = NULL; + nb::object pdest; if (type == 2) { - pdest = py_allgather(psrc); + pdest = nb::steal(py_allgather(psrc)); Py_DECREF(psrc); } else if (type != 1 && type != 5) { root = size; @@ -855,9 +855,9 @@ static Object* py_alltoall_type(int size, int type) { hoc_execerror("root rank must be >= 0 and < nhost", 0); } if (type == 3) { - pdest = py_gather(psrc, root); + pdest = nb::steal(py_gather(psrc, root)); } else if (type == 4) { - pdest = py_broadcast(psrc, root); + pdest = nb::steal(py_broadcast(psrc, root)); } Py_DECREF(psrc); } else { @@ -912,9 +912,9 @@ static Object* py_alltoall_type(int size, int type) { sdispl = mk_displ(scnt.data()); rdispl = mk_displ(rcnt); if (size < 0) { - pdest = PyTuple_New(2); - PyTuple_SetItem(pdest, 0, Py_BuildValue("l", (long) sdispl[np])); - PyTuple_SetItem(pdest, 1, Py_BuildValue("l", (long) rdispl[np])); + pdest = nb::steal(PyTuple_New(2)); + PyTuple_SetItem(pdest.ptr(), 0, Py_BuildValue("l", (long) sdispl[np])); + PyTuple_SetItem(pdest.ptr(), 1, Py_BuildValue("l", (long) rdispl[np])); delete[] sdispl; delete[] rcnt; delete[] rdispl; @@ -923,7 +923,7 @@ static Object* py_alltoall_type(int size, int type) { nrnmpi_char_alltoallv(s.data(), scnt.data(), sdispl, r, rcnt, rdispl); delete[] sdispl; - pdest = char2pylist(r, np, rcnt, rdispl); + pdest = nb::steal(char2pylist(r, np, rcnt, rdispl)); delete[] r; delete[] rcnt; @@ -946,19 +946,16 @@ static Object* py_alltoall_type(int size, int type) { delete[] sdispl; if (rcnt[0]) { - nb::object po = unpickle(r); - pdest = po.release().ptr(); + pdest = unpickle(r); } else { - pdest = Py_None; - Py_INCREF(pdest); + pdest = nb::none(); } delete[] rcnt; assert(rdispl == NULL); } } - Object* ho = nrnpy_po2ho(pdest); - Py_XDECREF(pdest); + Object* ho = nrnpy_po2ho(pdest.ptr()); if (ho) { --ho->refcount; }