Skip to content

Commit

Permalink
Modernize DECREF in py_alltoall_type (pdest).
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 14, 2024
1 parent 53f2384 commit 71bb637
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/nrnpython/nrnpy_p2h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,20 +857,20 @@ 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;
if (root < 0 || root >= np) {
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 {
Expand Down Expand Up @@ -925,9 +925,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;
Expand All @@ -936,7 +936,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;
Expand All @@ -959,19 +959,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;
}
Expand Down

0 comments on commit 71bb637

Please sign in to comment.