Skip to content

Commit

Permalink
Modernize DECREF in nrnpyerr_str (traceback).
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 14, 2024
1 parent e5af1e1 commit f8a396f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/nrnpython/nrnpy_p2h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,24 +612,24 @@ static char* nrnpyerr_str() {

auto type = nb::steal(ptype);
auto value = nb::steal(pvalue);
auto traceback = nb::steal(ptraceback);

// try for full backtrace
nb::object py_str;
char* cmes = NULL;

// Since traceback.format_exception returns list of strings, wrap
// in neuron.format_exception that returns a string.
if (!ptraceback) {
ptraceback = Py_None;
Py_INCREF(ptraceback);
if (!traceback) {
traceback = nb::none();

Check warning on line 624 in src/nrnpython/nrnpy_p2h.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnpython/nrnpy_p2h.cpp#L624

Added line #L624 was not covered by tests
}
auto pyth_module = nb::steal(PyImport_ImportModule("neuron"));
if (pyth_module) {
auto pyth_func = nb::steal(
PyObject_GetAttrString(pyth_module.ptr(), "format_exception"));
if (pyth_func) {
py_str = nb::steal(PyObject_CallFunctionObjArgs(
pyth_func.ptr(), type.ptr(), value.ptr(), ptraceback, NULL));
pyth_func.ptr(), type.ptr(), value.ptr(), traceback.ptr(), NULL));
}
}
if (py_str) {
Expand All @@ -649,8 +649,6 @@ static char* nrnpyerr_str() {
Fprintf(stderr, "nrnpyerr_str failed\n");
}

Py_XDECREF(ptraceback);

return cmes;
}
return NULL;
Expand Down

0 comments on commit f8a396f

Please sign in to comment.