From 83a0cd0e82f7695b1bb43aa6d86261d7a4594f2c Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 16 Aug 2022 08:25:38 +0200 Subject: [PATCH 1/2] gh-96017: Fix some compiler warnings - "comparison of integers of different signs" in typeobject.c - only define static_builtin_index_is_set in DEBUG builds - unset NDEBUG before including assert.h - only define recreate_gil with ifdef HAVE_FORK --- Modules/_testcapi/parts.h | 8 +++++--- Objects/typeobject.c | 4 +++- Python/ceval_gil.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h index a76ddd93c0efb9..39f561b8381a78 100644 --- a/Modules/_testcapi/parts.h +++ b/Modules/_testcapi/parts.h @@ -1,7 +1,9 @@ -#include "Python.h" - /* Always enable assertions */ -#undef NDEBUG +#ifdef NDEBUG +# undef NDEBUG +#endif + +#include "Python.h" int _PyTestCapi_Init_Vectorcall(PyObject *module); int _PyTestCapi_Init_VectorcallLimited(PyObject *module); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 67dfc6f8483d5f..d59e0268c9cb90 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -70,11 +70,13 @@ static inline PyTypeObject * subclass_from_ref(PyObject *ref); /* helpers for for static builtin types */ +#ifndef NDEBUG static inline int static_builtin_index_is_set(PyTypeObject *self) { return self->tp_subclasses != NULL; } +#endif static inline size_t static_builtin_index_get(PyTypeObject *self) @@ -6802,7 +6804,7 @@ type_ready_post_checks(PyTypeObject *type) return -1; } } - else if (type->tp_dictoffset < sizeof(PyObject)) { + else if (type->tp_dictoffset < (Py_ssize_t)sizeof(PyObject)) { if (type->tp_dictoffset + type->tp_basicsize <= 0) { PyErr_Format(PyExc_SystemError, "type %s has a tp_dictoffset that is too small"); diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h index 1b2dc7f8e1dc31..4c71edd682bf62 100644 --- a/Python/ceval_gil.h +++ b/Python/ceval_gil.h @@ -133,12 +133,14 @@ static void destroy_gil(struct _gil_runtime_state *gil) _Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked); } +#ifdef HAVE_FORK static void recreate_gil(struct _gil_runtime_state *gil) { _Py_ANNOTATE_RWLOCK_DESTROY(&gil->locked); /* XXX should we destroy the old OS resources here? */ create_gil(gil); } +#endif static void drop_gil(struct _ceval_runtime_state *ceval, struct _ceval_state *ceval2, From 2388df19f197e248dd34d8bc3ed2510ed41895d2 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 16 Aug 2022 13:19:03 +0200 Subject: [PATCH 2/2] Unpatch parts.h --- Modules/_testcapi/parts.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h index 39f561b8381a78..a76ddd93c0efb9 100644 --- a/Modules/_testcapi/parts.h +++ b/Modules/_testcapi/parts.h @@ -1,10 +1,8 @@ -/* Always enable assertions */ -#ifdef NDEBUG -# undef NDEBUG -#endif - #include "Python.h" +/* Always enable assertions */ +#undef NDEBUG + int _PyTestCapi_Init_Vectorcall(PyObject *module); int _PyTestCapi_Init_VectorcallLimited(PyObject *module); int _PyTestCapi_Init_Heaptype(PyObject *module);