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

Use PyBool_FromLong instead of macros #3305

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
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
25 changes: 6 additions & 19 deletions src/nrnpython/nrnpy_hoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
return NULL;
}
bool b = hoc_valid_stmt(cmd, 0);
return b ? Py_True : Py_False;
return PyBool_FromLong(b);
}

static PyObject* nrnexec_safe(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -2386,10 +2386,7 @@
result = self_ptr >= other_ptr;
break;
}
if (result) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(result);
}

// TODO: unfortunately, this duplicates code from hocobj_same; consolidate?
Expand Down Expand Up @@ -2440,20 +2437,14 @@
break;
}
if (self->nindex_ != pyhoc_other->nindex_ || self->sym_ != pyhoc_other->sym_) {
if (op == Py_NE) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(op == Py_NE);

Check warning on line 2440 in src/nrnpython/nrnpy_hoc.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_hoc.cpp#L2440

Added line #L2440 was not covered by tests
}
for (int i = 0; i < self->nindex_; i++) {
if (self->indices_[i] != pyhoc_other->indices_[i]) {
are_equal = false;
}
}
if (are_equal == (op == Py_EQ)) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(are_equal == (op == Py_EQ));

Check warning on line 2447 in src/nrnpython/nrnpy_hoc.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_hoc.cpp#L2447

Added line #L2447 was not covered by tests
default:
other_ptr = pyhoc_other->ho_;
}
Expand All @@ -2474,12 +2465,8 @@
static PyObject* hocobj_same(PyHocObject* pself, PyObject* args) {
PyObject* po;
if (PyArg_ParseTuple(args, "O", &po)) {
if (PyObject_TypeCheck(po, hocobject_type)) {
if (((PyHocObject*) po)->ho_ == pself->ho_) {
Py_RETURN_TRUE;
}
}
Py_RETURN_FALSE;
return PyBool_FromLong(PyObject_TypeCheck(po, hocobject_type) &&
((PyHocObject*) po)->ho_ == pself->ho_);

Check warning on line 2469 in src/nrnpython/nrnpy_hoc.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_hoc.cpp#L2468-L2469

Added lines #L2468 - L2469 were not covered by tests
}
return NULL;
}
Expand Down
35 changes: 9 additions & 26 deletions src/nrnpython/nrnpy_nrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,7 @@
return NULL;
}
}

if (sec->logical_connection) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(sec->logical_connection != nullptr);
}

static PyObject* NPySecObj_pt3dstyle_safe(NPySecObj* self, PyObject* args) {
Expand Down Expand Up @@ -956,10 +952,7 @@
if (pt3d == NULL) {
return NULL;
}
if (pt3d->d < 0) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(pt3d->d < 0);

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L955

Added line #L955 was not covered by tests
}

static PyObject* NPySecObj_spine3d_safe(NPySecObj* self, PyObject* args) {
Expand Down Expand Up @@ -1044,10 +1037,8 @@

static PyObject* is_pysec(NPySecObj* self) {
CHECK_SEC_INVALID(self->sec_);
if (self->sec_->prop && self->sec_->prop->dparam[PROP_PY_INDEX].get<void*>()) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(self->sec_->prop &&
self->sec_->prop->dparam[PROP_PY_INDEX].get<void*>());

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L1040-L1041

Added lines #L1040 - L1041 were not covered by tests
}

static PyObject* is_pysec_safe(NPySecObj* self) {
Expand Down Expand Up @@ -1316,14 +1307,9 @@

static PyObject* pysec_same(NPySecObj* self, PyObject* args) {
PyObject* pysec;
if (PyArg_ParseTuple(args, "O", &pysec)) {
if (PyObject_TypeCheck(pysec, psection_type)) {
if (((NPySecObj*) pysec)->sec_ == self->sec_) {
Py_RETURN_TRUE;
}
}
}
Py_RETURN_FALSE;
return PyBool_FromLong(PyArg_ParseTuple(args, "O", &pysec) &&
PyObject_TypeCheck(pysec, psection_type) &&
((NPySecObj*) pysec)->sec_ == self->sec_);

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L1310-L1312

Added lines #L1310 - L1312 were not covered by tests
}

static PyObject* pysec_same_safe(NPySecObj* self, PyObject* args) {
Expand Down Expand Up @@ -1391,10 +1377,7 @@

static PyObject* NPyMechObj_is_ion(NPyMechObj* self) {
CHECK_PROP_INVALID(self->prop_id_);
if (nrn_is_ion(self->type_)) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
return PyBool_FromLong(nrn_is_ion(self->type_));

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

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_nrn.cpp#L1380

Added line #L1380 was not covered by tests
}

static PyObject* NPyMechObj_is_ion_safe(NPyMechObj* self) {
Expand Down Expand Up @@ -1607,7 +1590,7 @@
if (!PyArg_ParseTuple(args, "s", &mechanism_name)) {
return NULL;
}
result = has_membrane(mechanism_name, self->sec_) ? Py_True : Py_False;
result = PyBool_FromLong(has_membrane(mechanism_name, self->sec_));
Py_XINCREF(result);
return result;
}
Expand Down
Loading