Skip to content

Commit 546217f

Browse files
author
cxzhong
committed
Fix Python 3.14t free-threaded build: use _Py_REFCNT() instead of ob_refcnt
- Replace direct ob_refcnt access with _Py_REFCNT() macro from cpython.ref - Add NULL checks before calling _Py_REFCNT() to prevent null pointer dereference - This fixes compilation errors in Python 3.14t (free-threaded/nogil) build where ob_refcnt is not directly accessible in PyObject structure
1 parent 19c9434 commit 546217f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cysignals/signals.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ See ``tests.pyx`` for extensive tests.
2525

2626
from libc.signal cimport *
2727
from libc.stdio cimport freopen, stdin
28-
from cpython.ref cimport Py_XINCREF, Py_CLEAR
28+
from cpython.ref cimport Py_XINCREF, Py_CLEAR, _Py_REFCNT
2929
from cpython.exc cimport (PyErr_Occurred, PyErr_NormalizeException,
3030
PyErr_Fetch, PyErr_Restore)
3131
from cpython.version cimport PY_MAJOR_VERSION
@@ -361,7 +361,7 @@ cdef void verify_exc_value() noexcept:
361361
Check that ``cysigs.exc_value`` is still the exception being raised.
362362
Clear ``cysigs.exc_value`` if not.
363363
"""
364-
if cysigs.exc_value.ob_refcnt == 1:
364+
if cysigs.exc_value != NULL and _Py_REFCNT(cysigs.exc_value) == 1:
365365
# No other references => exception is certainly gone
366366
Py_CLEAR(cysigs.exc_value)
367367
return
@@ -409,5 +409,5 @@ cdef void verify_exc_value() noexcept:
409409
# Make sure we still have cysigs.exc_value at all; if this function was
410410
# called again during garbage collection it might have already been set
411411
# to NULL; see https://github.com/sagemath/cysignals/issues/126
412-
if cysigs.exc_value != NULL and cysigs.exc_value.ob_refcnt == 1:
412+
if cysigs.exc_value != NULL and _Py_REFCNT(cysigs.exc_value) == 1:
413413
Py_CLEAR(cysigs.exc_value)

0 commit comments

Comments
 (0)