Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from deprecated PyWeakref_GetObject #3287

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/nrnpython/nrnpy_nrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,27 @@
if (auto* pv = sec->prop->dparam[PROP_PY_INDEX].get<void*>(); pv) {
PyObject* cell_weakref = static_cast<NPySecObj*>(pv)->cell_weakref_;
if (cell_weakref) {
#if PY_VERSION_HEX >= 0x030D0000
PyObject* cell = nullptr;
int err = PyWeakref_GetRef(cell_weakref, &cell);
if (err == -1) {
PyErr_Print();
hoc_execerror("Error getting cell for", secname(sec));

Check warning on line 185 in src/nrnpython/nrnpy_nrn.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L184-L185

Added lines #L184 - L185 were not covered by tests
} else if (err == 0) {
return nullptr;

Check warning on line 187 in src/nrnpython/nrnpy_nrn.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L187

Added line #L187 was not covered by tests
}
auto ret = nrnpy_po2ho(cell);
Py_DECREF(cell);
return ret;
#else
PyObject* cell = PyWeakref_GetObject(cell_weakref);
if (!cell) {
PyErr_Print();
hoc_execerror("Error getting cell for", secname(sec));
} else if (cell != Py_None) {
return nrnpy_po2ho(cell);
}
#endif
}
}
return NULL;
Expand Down Expand Up @@ -215,12 +229,24 @@
if (auto* pv = sec->prop->dparam[PROP_PY_INDEX].get<void*>(); pv) {
PyObject* cell_weakref = static_cast<NPySecObj*>(pv)->cell_weakref_;
if (cell_weakref) {
#if PY_VERSION_HEX >= 0x030D0000
PyObject* cell = nullptr;
int err = PyWeakref_GetRef(cell_weakref, &cell);
if (err == -1) {
PyErr_Print();
hoc_execerror("Error getting cell for", secname(sec));

Check warning on line 237 in src/nrnpython/nrnpy_nrn.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L233-L237

Added lines #L233 - L237 were not covered by tests
}
auto ret = nrnpy_ho_eq_po(obj, cell);
Py_DECREF(cell);
return ret;

Check warning on line 241 in src/nrnpython/nrnpy_nrn.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L239-L241

Added lines #L239 - L241 were not covered by tests
#else
PyObject* cell = PyWeakref_GetObject(cell_weakref);
if (!cell) {
PyErr_Print();
hoc_execerror("Error getting cell for", secname(sec));
}
return nrnpy_ho_eq_po(obj, cell);
#endif
}
return nrnpy_ho_eq_po(obj, Py_None);
}
Expand Down Expand Up @@ -1212,7 +1238,17 @@
static PyObject* pysec2cell(NPySecObj* self) {
nb::object result;
if (self->cell_weakref_) {
#if PY_VERSION_HEX >= 0x030D0000
PyObject* cell = nullptr;
int ret = PyWeakref_GetRef(self->cell_weakref_, &cell);
if (ret > 0) {
result = nb::steal(cell);
} else {
result = nb::none();
}
#else
result = nb::borrow(PyWeakref_GetObject(self->cell_weakref_));
#endif
} else if (auto* o = self->sec_->prop->dparam[6].get<Object*>(); self->sec_->prop && o) {
result = nb::steal(nrnpy_ho2po(o));
} else {
Expand Down
Loading