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

One more set of RAII related modernizations. #3270

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
182bb4e
Simplify NPySecObj_name
1uc Nov 22, 2024
6ef39c8
nullptr
1uc Nov 22, 2024
72c0ef9
Use {fmt} in pyseg_repr.
1uc Nov 22, 2024
bd1168d
Use `std::vector<char>` for `buf`.
1uc Nov 22, 2024
476f7f3
Use std::vector<char> for `buf`.
1uc Nov 22, 2024
d971d99
Make `nrnpyerr_str`.
1uc Nov 22, 2024
a1122a3
unique_cstr with default ctor.
1uc Nov 27, 2024
aa23985
replace with unique_cstr.
1uc Nov 27, 2024
5f5914e
Modernize DECREF in `nrnpy_ho2po`.
1uc Nov 27, 2024
ddfafbf
Use fmt in `hoc_internal_name`.
1uc Nov 27, 2024
e00e2f4
Modernize reference counting in `NPyMechFunc_call`.
1uc Nov 27, 2024
639fe7e
Return without intermediary.
1uc Nov 27, 2024
00f5cec
Modernize reference counting in `section_getattro`.
1uc Nov 27, 2024
3d87165
Cleanup a NULL
1uc Nov 27, 2024
f41474c
Modernize reference counting in `fcall` (result).
1uc Nov 27, 2024
8b0f7e8
modernize nullptr
1uc Nov 27, 2024
4abe532
Modernize reference counting in `hocobj_call`.
1uc Nov 27, 2024
70b7d38
Modernize reference counting in `nrn_hocobj_handle`.
1uc Nov 27, 2024
6251274
modernize nullptr
1uc Nov 27, 2024
55e8fb7
Modernize reference counting in `toplevel_get`.
1uc Nov 27, 2024
17424b1
Modernize reference counting in `hocobj_getattr`.
1uc Nov 27, 2024
409a28a
Modernize reference counting in `hocobj_getattr`.
1uc Nov 27, 2024
f54a684
Modernize reference counting in `hocobj_getattro`.
1uc Nov 27, 2024
623c0e0
Modernize reference counting in `nrnpy_forall`.
1uc Nov 27, 2024
a0ce354
Localize variables.
1uc Nov 27, 2024
fbfecb2
modernize nullptr
1uc Nov 27, 2024
a7d777a
Merge branch 'master' into 1uc/modernize-something
JCGoran Jan 15, 2025
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
Prev Previous commit
Next Next commit
Return without intermediary.
1uc committed Dec 4, 2024
commit 639fe7e3a6b43f9915711e04fd20d8396d7bf1bf
27 changes: 13 additions & 14 deletions src/nrnpython/nrnpy_nrn.cpp
Original file line number Diff line number Diff line change
@@ -1699,18 +1699,19 @@ static PyObject* seg_point_processes_safe(NPySegObj* self) {
return nrn::convert_cxx_exceptions(seg_point_processes, self);
}

// Returns a new reference.
static PyObject* node_index1(NPySegObj* self) {
Section* sec = self->pysec_->sec_;
CHECK_SEC_INVALID(sec);
Node* nd = node_exact(sec, self->x_);
PyObject* result = Py_BuildValue("i", nd->v_node_index);
return result;
return Py_BuildValue("i", nd->v_node_index);
}

static PyObject* node_index1_safe(NPySegObj* self) {
return nrn::convert_cxx_exceptions(node_index1, self);
}

// Returns a new reference.
static PyObject* seg_area(NPySegObj* self) {
Section* sec = self->pysec_->sec_;
CHECK_SEC_INVALID(sec);
@@ -1723,8 +1724,7 @@ static PyObject* seg_area(NPySegObj* self) {
Node* nd = node_exact(sec, x);
a = NODEAREA(nd);
}
PyObject* result = Py_BuildValue("d", a);
return result;
return Py_BuildValue("d", a);
}

static PyObject* seg_area_safe(NPySegObj* self) {
@@ -1763,6 +1763,7 @@ static int arg_bisect_arc3d(Section* sec, int npt3d, double x) {
return left;
}

// Returns a new reference.
static PyObject* seg_volume(NPySegObj* self) {
Section* sec = self->pysec_->sec_;
CHECK_SEC_INVALID(sec);
@@ -1814,14 +1815,14 @@ static PyObject* seg_volume(NPySegObj* self) {
}
}
}
PyObject* result = Py_BuildValue("d", a);
return result;
return Py_BuildValue("d", a);
}

static PyObject* seg_volume_safe(NPySegObj* self) {
return nrn::convert_cxx_exceptions(seg_volume, self);
}

// Returns a new reference.
static PyObject* seg_ri(NPySegObj* self) {
Section* sec = self->pysec_->sec_;
CHECK_SEC_INVALID(sec);
@@ -1833,8 +1834,7 @@ static PyObject* seg_ri(NPySegObj* self) {
if (NODERINV(nd)) {
ri = 1. / NODERINV(nd);
}
PyObject* result = Py_BuildValue("d", ri);
return result;
return Py_BuildValue("d", ri);
}

static PyObject* seg_ri_safe(NPySegObj* self) {
@@ -2652,15 +2652,15 @@ static Py_ssize_t rv_len_safe(PyObject* self) {
return nrn::convert_cxx_exceptions(rv_len, self);
}

// Returns a new reference.
static PyObject* rv_getitem(PyObject* self, Py_ssize_t ix) {
NPyRangeVar* r = (NPyRangeVar*) self;
Section* sec = r->pymech_->pyseg_->pysec_->sec_;
CHECK_SEC_INVALID(sec)

PyObject* result = NULL;
if (ix < 0 || ix >= rv_len(self)) {
PyErr_SetString(PyExc_IndexError, r->sym_->name);
return NULL;
return nullptr;
}
if (is_array(*r->sym_)) {
assert(r->sym_->arayinfo->nsub == 1);
@@ -2677,14 +2677,13 @@ static PyObject* rv_getitem(PyObject* self, Py_ssize_t ix) {
auto const d = nrnpy_rangepointer(sec, r->sym_, r->pymech_->pyseg_->x_, &err, ix);
if (d.is_invalid_handle()) {
rv_noexist(sec, r->sym_->name, r->pymech_->pyseg_->x_, err);
return NULL;
return nullptr;
}
if (r->isptr_) {
result = nrn_hocobj_handle(neuron::container::data_handle<double>(d));
return nrn_hocobj_handle(neuron::container::data_handle<double>(d));
} else {
result = build_python_value(d);
return build_python_value(d);
}
return result;
}

static PyObject* rv_getitem_safe(PyObject* self, Py_ssize_t ix) {
4 changes: 2 additions & 2 deletions src/nrnpython/nrnpy_p2h.cpp
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ static int pysame(Object* o1, Object* o2) {
return 0;
}

// Returns a borrowed reference.
PyObject* nrnpy_hoc2pyobject(Object* ho) {
PyObject* po = ((Py2Nrn*) ho->u.this_pointer)->po_;
if (!po) {
@@ -534,8 +535,7 @@ static std::vector<char> pickle(PyObject* p) {
static std::vector<char> po2pickle(Object* ho) {
setpickle();
if (ho && ho->ctemplate->sym == nrnpy_pyobj_sym_) {
PyObject* po = nrnpy_hoc2pyobject(ho);
return pickle(po);
return pickle(nrnpy_hoc2pyobject(ho));
} else {
return {};
}