Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Include/internal/pycore_object_deferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ extern "C" {
// counting should be tracked by the GC so that they are eventually collected.
extern void _PyObject_SetDeferredRefcount(PyObject *op);

#ifdef Py_GIL_DISABLED
static inline int
_PyObject_HasDeferredRefcount(PyObject *op)
{
#ifdef Py_GIL_DISABLED
return _PyObject_HAS_GC_BITS(op, _PyGC_BITS_DEFERRED);
}
#else
static inline int
_PyObject_HasDeferredRefcount(PyObject *Py_UNUSED(op))
{
return 0;
#endif
}
#endif


#ifdef __cplusplus
}
Expand Down
30 changes: 24 additions & 6 deletions Include/internal/pycore_stackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,16 +782,22 @@ PyStackRef_LongCheck(_PyStackRef stackref)
return PyLong_Check(PyStackRef_AsPyObjectBorrow(stackref));
}

#ifdef Py_GIL_DISABLED
static inline void
_PyThreadState_PushCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
{
#ifdef Py_GIL_DISABLED
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
ref->next = tstate_impl->c_stack_refs;
tstate_impl->c_stack_refs = ref;
#endif
ref->ref = PyStackRef_NULL;
}
#else
static inline void
_PyThreadState_PushCStackRef(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
{
ref->ref = PyStackRef_NULL;
}
#endif

static inline void
_PyThreadState_PushCStackRefNew(PyThreadState *tstate, _PyCStackRef *ref, PyObject *obj)
Expand All @@ -800,27 +806,39 @@ _PyThreadState_PushCStackRefNew(PyThreadState *tstate, _PyCStackRef *ref, PyObje
ref->ref = PyStackRef_FromPyObjectNew(obj);
}


#ifdef Py_GIL_DISABLED
static inline void
_PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
{
#ifdef Py_GIL_DISABLED
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
assert(tstate_impl->c_stack_refs == ref);
tstate_impl->c_stack_refs = ref->next;
#endif
PyStackRef_XCLOSE(ref->ref);
}

static inline _PyStackRef
_PyThreadState_PopCStackRefSteal(PyThreadState *tstate, _PyCStackRef *ref)
{
#ifdef Py_GIL_DISABLED
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
assert(tstate_impl->c_stack_refs == ref);
tstate_impl->c_stack_refs = ref->next;
#endif
return ref->ref;
}
#else
static inline void
_PyThreadState_PopCStackRef(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
{
PyStackRef_XCLOSE(ref->ref);
}

static inline _PyStackRef
_PyThreadState_PopCStackRefSteal(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
{
return ref->ref;
}
#endif


#ifdef Py_GIL_DISABLED

Expand Down
2 changes: 1 addition & 1 deletion Include/slots.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct PySlot {
#define PySlot_STATIC_DATA(NAME, VALUE) \
{.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)}

#define PySlot_END {0}
#define PySlot_END {0, 0, {0}, {0}}


// Macros without designated initializers (for C++11 and below):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_cext/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
if not MSVC:
# C compiler flags for GCC and clang
BASE_CFLAGS = [
'-Wall',
'-Wextra',
# The purpose of test_cext extension is to check that building a C
# extension using the Python C API does not emit C compiler warnings.
'-Werror',
Expand Down Expand Up @@ -71,6 +73,8 @@
if not MSVC:
# C++ compiler flags for GCC and clang
CPPFLAGS = [
'-Wall',
'-Wextra',
# gh-91321: The purpose of _testcppext extension is to check that building
# a C++ extension using the Python C API does not emit C++ compiler
# warnings
Expand Down
Loading