numpy/numpy-user-dtypes

Two minor exception handling bugs

peytondmurray opened this issue · 2 comments

Posting these here before I forget about them:

  1. Here PyErr_Occurred() is called without first calling PyGilState_Ensure. According to the docs, the caller must hold the GIL.
  2. In add_promoter, the call to PyCapsule_New can fail. I think we need to check whether the result is NULL and whether the error indicator is set, then DECREF stuff appropriately.

Here PyErr_Occurred() is called without first calling PyGilState_Ensure

PyErr_Occurred has an assert for that in the implementation here. Also there are several other C API functions that get called in that function that need the GIL. Right now get_value is only used by setitem, which does not release the GIL on the numpy side, so I think we're safe. We could certainly add a documentation note saying that get_value needs the GIL.

In add_promoter, the call to PyCapsule_New can fail. I think we need to check whether the result is NULL and whether the error indicator is set, then DECREF stuff appropriately.

Good point, PR incoming.

The first is fine, getitem/setitem always hold the GIL, second is fixed, closing.