@@ -25,7 +25,7 @@ See ``tests.pyx`` for extensive tests.
25
25
26
26
from libc.signal cimport *
27
27
from libc.stdio cimport freopen, stdin
28
- from cpython.ref cimport Py_XINCREF, Py_XDECREF
28
+ from cpython.ref cimport Py_XINCREF, Py_CLEAR
29
29
from cpython.exc cimport (PyErr_Occurred, PyErr_NormalizeException,
30
30
PyErr_Fetch, PyErr_Restore)
31
31
from cpython.version cimport PY_MAJOR_VERSION
@@ -204,7 +204,7 @@ cdef int sig_raise_exception "sig_raise_exception"(int sig, const char* msg) exc
204
204
PyErr_Fetch(& typ, & val, & tb)
205
205
PyErr_NormalizeException(& typ, & val, & tb)
206
206
Py_XINCREF(val)
207
- Py_XDECREF (cysigs.exc_value)
207
+ Py_CLEAR (cysigs.exc_value)
208
208
cysigs.exc_value = val
209
209
PyErr_Restore(typ, val, tb)
210
210
@@ -362,8 +362,7 @@ cdef void verify_exc_value() noexcept:
362
362
"""
363
363
if cysigs.exc_value.ob_refcnt == 1 :
364
364
# No other references => exception is certainly gone
365
- Py_XDECREF(cysigs.exc_value)
366
- cysigs.exc_value = NULL
365
+ Py_CLEAR(cysigs.exc_value)
367
366
return
368
367
369
368
if PyErr_Occurred() is not NULL :
@@ -394,8 +393,7 @@ cdef void verify_exc_value() noexcept:
394
393
pass
395
394
else :
396
395
if < PyObject* > handled is cysigs.exc_value:
397
- Py_XDECREF(cysigs.exc_value)
398
- cysigs.exc_value = NULL
396
+ Py_CLEAR(cysigs.exc_value)
399
397
return
400
398
401
399
# To be safe, we run the garbage collector because it may clear
@@ -411,5 +409,4 @@ cdef void verify_exc_value() noexcept:
411
409
# called again during garbage collection it might have already been set
412
410
# to NULL; see https://github.com/sagemath/cysignals/issues/126
413
411
if cysigs.exc_value != NULL and cysigs.exc_value.ob_refcnt == 1 :
414
- Py_XDECREF(cysigs.exc_value)
415
- cysigs.exc_value = NULL
412
+ Py_CLEAR(cysigs.exc_value)
0 commit comments