Skip to content

Commit 7ce1d7e

Browse files
committed
gh-149044: Build test_cext with -Wall -Wextra
Fix "unused parameter" warning/error in pycore_object_deferred.h and pycore_stackref.h. Fix PySlot_END on C++: initialize all members.
1 parent 72f821f commit 7ce1d7e

4 files changed

Lines changed: 36 additions & 9 deletions

File tree

‎Include/internal/pycore_object_deferred.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ extern "C" {
1616
// counting should be tracked by the GC so that they are eventually collected.
1717
extern void _PyObject_SetDeferredRefcount(PyObject *op);
1818

19+
#ifdef Py_GIL_DISABLED
1920
static inline int
2021
_PyObject_HasDeferredRefcount(PyObject *op)
2122
{
22-
#ifdef Py_GIL_DISABLED
2323
return _PyObject_HAS_GC_BITS(op, _PyGC_BITS_DEFERRED);
24+
}
2425
#else
26+
static inline int
27+
_PyObject_HasDeferredRefcount(PyObject *Py_UNUSED(op))
28+
{
2529
return 0;
26-
#endif
2730
}
31+
#endif
32+
2833

2934
#ifdef __cplusplus
3035
}

‎Include/internal/pycore_stackref.h‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,22 @@ PyStackRef_LongCheck(_PyStackRef stackref)
782782
return PyLong_Check(PyStackRef_AsPyObjectBorrow(stackref));
783783
}
784784

785+
#ifdef Py_GIL_DISABLED
785786
static inline void
786787
_PyThreadState_PushCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
787788
{
788-
#ifdef Py_GIL_DISABLED
789789
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
790790
ref->next = tstate_impl->c_stack_refs;
791791
tstate_impl->c_stack_refs = ref;
792-
#endif
793792
ref->ref = PyStackRef_NULL;
794793
}
794+
#else
795+
static inline void
796+
_PyThreadState_PushCStackRef(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
797+
{
798+
ref->ref = PyStackRef_NULL;
799+
}
800+
#endif
795801

796802
static inline void
797803
_PyThreadState_PushCStackRefNew(PyThreadState *tstate, _PyCStackRef *ref, PyObject *obj)
@@ -800,27 +806,39 @@ _PyThreadState_PushCStackRefNew(PyThreadState *tstate, _PyCStackRef *ref, PyObje
800806
ref->ref = PyStackRef_FromPyObjectNew(obj);
801807
}
802808

809+
810+
#ifdef Py_GIL_DISABLED
803811
static inline void
804812
_PyThreadState_PopCStackRef(PyThreadState *tstate, _PyCStackRef *ref)
805813
{
806-
#ifdef Py_GIL_DISABLED
807814
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
808815
assert(tstate_impl->c_stack_refs == ref);
809816
tstate_impl->c_stack_refs = ref->next;
810-
#endif
811817
PyStackRef_XCLOSE(ref->ref);
812818
}
813819

814820
static inline _PyStackRef
815821
_PyThreadState_PopCStackRefSteal(PyThreadState *tstate, _PyCStackRef *ref)
816822
{
817-
#ifdef Py_GIL_DISABLED
818823
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
819824
assert(tstate_impl->c_stack_refs == ref);
820825
tstate_impl->c_stack_refs = ref->next;
821-
#endif
822826
return ref->ref;
823827
}
828+
#else
829+
static inline void
830+
_PyThreadState_PopCStackRef(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
831+
{
832+
PyStackRef_XCLOSE(ref->ref);
833+
}
834+
835+
static inline _PyStackRef
836+
_PyThreadState_PopCStackRefSteal(PyThreadState *Py_UNUSED(tstate), _PyCStackRef *ref)
837+
{
838+
return ref->ref;
839+
}
840+
#endif
841+
824842

825843
#ifdef Py_GIL_DISABLED
826844

‎Include/slots.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct PySlot {
4242
#define PySlot_STATIC_DATA(NAME, VALUE) \
4343
{.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)}
4444

45-
#define PySlot_END {0}
45+
#define PySlot_END {0, 0, {0}, {0}}
4646

4747

4848
// Macros without designated initializers (for C++11 and below):

‎Lib/test/test_cext/setup.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
if not MSVC:
2222
# C compiler flags for GCC and clang
2323
BASE_CFLAGS = [
24+
'-Wall',
25+
'-Wextra',
2426
# The purpose of test_cext extension is to check that building a C
2527
# extension using the Python C API does not emit C compiler warnings.
2628
'-Werror',
@@ -71,6 +73,8 @@
7173
if not MSVC:
7274
# C++ compiler flags for GCC and clang
7375
CPPFLAGS = [
76+
'-Wall',
77+
'-Wextra',
7478
# gh-91321: The purpose of _testcppext extension is to check that building
7579
# a C++ extension using the Python C API does not emit C++ compiler
7680
# warnings

0 commit comments

Comments
 (0)