Skip to content

Commit

Permalink
fix double finalization of static
Browse files Browse the repository at this point in the history
closes #1663
  • Loading branch information
t-kalinowski committed Sep 8, 2024
1 parent 1fc95e6 commit 26c1c22
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ PyObject* pandas_arrays () {
}

bool is_pandas_na_like(PyObject* x) {
const static PyObjectPtr np_nan(PyObject_GetAttrString(numpy(), "nan"));
const static PyObject* np_nan = PyObject_GetAttrString(numpy(), "nan");
return is_pandas_na(x) || (x == Py_None) || (x == (PyObject*)np_nan);
}

Expand Down Expand Up @@ -1203,11 +1203,16 @@ bool py_is_callable(PyObjectRef x) {

// caches np.nditer function so we don't need to obtain it everytime we want to
// cast numpy string arrays into R objects.
PyObject* get_np_nditer () {
const static PyObjectPtr np_nditer(PyObject_GetAttrString(numpy(), "nditer"));
if (np_nditer.is_null()) {
throw PythonException(py_fetch_error());
}
PyObject* get_np_nditer() {
static PyObject* np_nditer = []() -> PyObject* {
PyObject* np_nditer = PyObject_GetAttrString(numpy(), "nditer");
if (np_nditer == NULL) {
throw PythonException(py_fetch_error());
}
return np_nditer;
}();

// Return the static np_nditer
return np_nditer;
}

Expand Down

0 comments on commit 26c1c22

Please sign in to comment.