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

Modernize DECREF (part 1). #3203

Merged
merged 4 commits into from
Nov 15, 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
48 changes: 21 additions & 27 deletions src/nrnpython/nrnpy_nrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,12 @@
if (cell) {
// include cellname in name so nrnpy_pysecname2sec_remove can determine

cell = PyObject_Str(cell);
if (cell == NULL) {
auto cell_str = nb::steal(PyObject_Str(cell));
if (!cell_str) {
Py_XDECREF(self->cell_weakref_);
return -1;
}
Py2NRNString str(cell);
Py_DECREF(cell);
Py2NRNString str(cell_str.ptr());
nrnhines marked this conversation as resolved.
Show resolved Hide resolved
if (str.err()) {
str.set_pyerr(PyExc_TypeError, "cell name contains non ascii character");
return -1;
Expand Down Expand Up @@ -453,33 +452,29 @@
}

PyObject* NPySecObj_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
NPySecObj* self;
self = (NPySecObj*) type->tp_alloc(type, 0);
// printf("NPySecObj_new %p\n", self);
if (self != NULL) {
if (NPySecObj_init(self, args, kwds) != 0) {
Py_DECREF(self);
return NULL;
auto self = nb::steal(type->tp_alloc(type, 0));
// printf("NPySecObj_new %p\n", self.ptr());
if (self) {
1uc marked this conversation as resolved.
Show resolved Hide resolved
if (NPySecObj_init((NPySecObj*) self.ptr(), args, kwds) != 0) {
return nullptr;
}
}
return (PyObject*) self;
return self.release().ptr();
}

PyObject* NPySecObj_new_safe(PyTypeObject* type, PyObject* args, PyObject* kwds) {
return nrn::convert_cxx_exceptions(NPySecObj_new, type, args, kwds);
}

PyObject* NPyAllSegOfSecIter_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
NPyAllSegOfSecIter* self;
self = (NPyAllSegOfSecIter*) type->tp_alloc(type, 0);
// printf("NPyAllSegOfSecIter_new %p\n", self);
if (self != NULL) {
if (NPyAllSegOfSecIter_init(self, args, kwds) != 0) {
Py_DECREF(self);
return NULL;
auto self = nb::steal(type->tp_alloc(type, 0));

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L470

Added line #L470 was not covered by tests
// printf("NPyAllSegOfSecIter_new %p\n", self.ptr());
if (self) {
if (NPyAllSegOfSecIter_init((NPyAllSegOfSecIter*) self.ptr(), args, kwds) != 0) {
return nullptr;

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L472-L474

Added lines #L472 - L474 were not covered by tests
}
}
return (PyObject*) self;
return self.release().ptr();

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L477

Added line #L477 was not covered by tests
}

PyObject* NPyAllSegOfSecIter_new_safe(PyTypeObject* type, PyObject* args, PyObject* kwds) {
Expand Down Expand Up @@ -1860,17 +1855,16 @@
CHECK_SEC_INVALID(sec)
Node* nd = node_exact(sec, self->x_);
Prop* p = mech_of_segment_prop(nd->prop);
NPyMechOfSegIter* mi = PyObject_New(NPyMechOfSegIter, pmech_of_seg_iter_generic_type);
auto mi = nb::steal((PyObject*) PyObject_New(NPyMechOfSegIter, pmech_of_seg_iter_generic_type));
if (!mi) {
return NULL;
return nullptr;

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L1860

Added line #L1860 was not covered by tests
}
NPyMechObj* m = new_pymechobj(self, p);
auto m = nb::steal((PyObject*) new_pymechobj(self, p));
if (!m) {
Py_XDECREF(mi);
return NULL;
return nullptr;

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L1864

Added line #L1864 was not covered by tests
}
mi->pymech_ = m;
return (PyObject*) mi;
((NPyMechOfSegIter*) mi.ptr())->pymech_ = (NPyMechObj*) m.release().ptr();
return mi.release().ptr();
}

static PyObject* mech_of_segment_iter_safe(NPySegObj* self) {
Expand Down
Loading