From c5c6295616b421d7858c69049635649113d8c3fa Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 24 Mar 2025 13:48:42 +0100 Subject: [PATCH 1/2] gh-111178: Fix function signatures for test_capi --- Modules/_ctypes/_ctypes.c | 3 +- Modules/_testcapi/heaptype.c | 41 ++++++++++++-------- Modules/_testcapimodule.c | 3 +- Modules/_testlimitedcapi/heaptype_relative.c | 4 +- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index cc06759f2d0d59..df803c2917b17b 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -3801,8 +3801,9 @@ _validate_paramflags(ctypes_state *st, PyTypeObject *type, PyObject *paramflags) } static int -_get_name(PyObject *obj, const char **pname) +_get_name(PyObject *obj, void *arg) { + const char **pname = (const char **)arg; #ifdef MS_WIN32 if (PyLong_Check(obj)) { /* We have to use MAKEINTRESOURCEA for Windows CE. diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c index cc88147dfcd7fb..71071c07a8bcbb 100644 --- a/Modules/_testcapi/heaptype.c +++ b/Modules/_testcapi/heaptype.c @@ -605,15 +605,17 @@ heapctype_init(PyObject *self, PyObject *args, PyObject *kwargs) } static int -heapgcctype_traverse(HeapCTypeObject *self, visitproc visit, void *arg) +heapgcctype_traverse(PyObject *op, visitproc visit, void *arg) { + HeapCTypeObject *self = (HeapCTypeObject*)op; Py_VISIT(Py_TYPE(self)); return 0; } static void -heapgcctype_dealloc(HeapCTypeObject *self) +heapgcctype_dealloc(PyObject *op) { + HeapCTypeObject *self = (HeapCTypeObject*)op; PyTypeObject *tp = Py_TYPE(self); PyObject_GC_UnTrack(self); PyObject_GC_Del(self); @@ -642,8 +644,9 @@ PyDoc_STRVAR(heapctype__doc__, "The 'value' attribute is set to 10 in __init__."); static void -heapctype_dealloc(HeapCTypeObject *self) +heapctype_dealloc(PyObject *op) { + HeapCTypeObject *self = (HeapCTypeObject *)op; PyTypeObject *tp = Py_TYPE(self); PyObject_Free(self); Py_DECREF(tp); @@ -716,8 +719,9 @@ typedef struct { } HeapCTypeWithBufferObject; static int -heapctypewithbuffer_getbuffer(HeapCTypeWithBufferObject *self, Py_buffer *view, int flags) +heapctypewithbuffer_getbuffer(PyObject *op, Py_buffer *view, int flags) { + HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject *)op; self->buffer[0] = '1'; self->buffer[1] = '2'; self->buffer[2] = '3'; @@ -727,8 +731,9 @@ heapctypewithbuffer_getbuffer(HeapCTypeWithBufferObject *self, Py_buffer *view, } static void -heapctypewithbuffer_releasebuffer(HeapCTypeWithBufferObject *self, Py_buffer *view) +heapctypewithbuffer_releasebuffer(PyObject *op, Py_buffer *view) { + HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject *)op; assert(view->obj == (void*) self); } @@ -873,9 +878,9 @@ typedef struct { } HeapCTypeWithDictObject; static void -heapctypewithdict_dealloc(HeapCTypeWithDictObject* self) +heapctypewithdict_dealloc(PyObject *op) { - + HeapCTypeWithDictObject *self = (HeapCTypeWithDictObject*)op; PyTypeObject *tp = Py_TYPE(self); Py_XDECREF(self->dict); PyObject_Free(self); @@ -917,22 +922,23 @@ static PyType_Spec HeapCTypeWithDict2_spec = { }; static int -heapmanaged_traverse(HeapCTypeObject *self, visitproc visit, void *arg) +heapmanaged_traverse(PyObject *self, visitproc visit, void *arg) { Py_VISIT(Py_TYPE(self)); return PyObject_VisitManagedDict((PyObject *)self, visit, arg); } static int -heapmanaged_clear(HeapCTypeObject *self) +heapmanaged_clear(PyObject *self) { - PyObject_ClearManagedDict((PyObject *)self); + PyObject_ClearManagedDict(self); return 0; } static void -heapmanaged_dealloc(HeapCTypeObject *self) +heapmanaged_dealloc(PyObject *op) { + HeapCTypeObject *self = (HeapCTypeObject*)op; PyTypeObject *tp = Py_TYPE(self); PyObject_ClearManagedDict((PyObject *)self); PyObject_GC_UnTrack(self); @@ -1016,9 +1022,9 @@ static struct PyMemberDef heapctypewithweakref_members[] = { }; static void -heapctypewithweakref_dealloc(HeapCTypeWithWeakrefObject* self) +heapctypewithweakref_dealloc(PyObject *op) { - + HeapCTypeWithWeakrefObject *self = (HeapCTypeWithWeakrefObject*)op; PyTypeObject *tp = Py_TYPE(self); if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) self); @@ -1071,16 +1077,18 @@ heapctypesetattr_init(PyObject *self, PyObject *args, PyObject *kwargs) } static void -heapctypesetattr_dealloc(HeapCTypeSetattrObject *self) +heapctypesetattr_dealloc(PyObject *op) { + HeapCTypeSetattrObject *self = (HeapCTypeSetattrObject*)op; PyTypeObject *tp = Py_TYPE(self); PyObject_Free(self); Py_DECREF(tp); } static int -heapctypesetattr_setattro(HeapCTypeSetattrObject *self, PyObject *attr, PyObject *value) +heapctypesetattr_setattro(PyObject *op, PyObject *attr, PyObject *value) { + HeapCTypeSetattrObject *self = (HeapCTypeSetattrObject*)op; PyObject *svalue = PyUnicode_FromString("value"); if (svalue == NULL) return -1; @@ -1237,8 +1245,9 @@ HeapCCollection_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) } static Py_ssize_t -HeapCCollection_length(PyVarObject *self) +HeapCCollection_length(PyObject *op) { + PyVarObject *self = (PyVarObject *)op; return Py_SIZE(self); } diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index caaf83f578fc0f..fa5f58bb2a055d 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2871,8 +2871,9 @@ MyList_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } void -MyList_dealloc(MyListObject* op) +MyList_dealloc(PyObject *self) { + MyListObject *op = (MyListObject*)self; if (op->deallocated) { /* We cannot raise exceptions here but we still want the testsuite * to fail when we hit this */ diff --git a/Modules/_testlimitedcapi/heaptype_relative.c b/Modules/_testlimitedcapi/heaptype_relative.c index 45d65ee47349f9..5145c86853a6fa 100644 --- a/Modules/_testlimitedcapi/heaptype_relative.c +++ b/Modules/_testlimitedcapi/heaptype_relative.c @@ -77,7 +77,7 @@ make_sized_heaptypes(PyObject *module, PyObject *args) static PyObject * var_heaptype_set_data_to_3s( PyObject *self, PyTypeObject *defining_class, - PyObject **args, Py_ssize_t nargs, PyObject *kwnames) + PyObject * const *args, Py_ssize_t nargs, PyObject *kwnames) { void *data_ptr = PyObject_GetTypeData(self, defining_class); if (!data_ptr) { @@ -93,7 +93,7 @@ var_heaptype_set_data_to_3s( static PyObject * var_heaptype_get_data(PyObject *self, PyTypeObject *defining_class, - PyObject **args, Py_ssize_t nargs, PyObject *kwnames) + PyObject * const *args, Py_ssize_t nargs, PyObject *kwnames) { void *data_ptr = PyObject_GetTypeData(self, defining_class); if (!data_ptr) { From e5e7b2e6e54c9bde2049637d5bee435f8116a911 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 24 Mar 2025 14:33:37 +0100 Subject: [PATCH 2/2] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Modules/_testcapi/heaptype.c | 8 ++++---- Modules/_testlimitedcapi/heaptype_relative.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c index 71071c07a8bcbb..fd061f2d23a47c 100644 --- a/Modules/_testcapi/heaptype.c +++ b/Modules/_testcapi/heaptype.c @@ -646,7 +646,7 @@ PyDoc_STRVAR(heapctype__doc__, static void heapctype_dealloc(PyObject *op) { - HeapCTypeObject *self = (HeapCTypeObject *)op; + HeapCTypeObject *self = (HeapCTypeObject*)op; PyTypeObject *tp = Py_TYPE(self); PyObject_Free(self); Py_DECREF(tp); @@ -721,7 +721,7 @@ typedef struct { static int heapctypewithbuffer_getbuffer(PyObject *op, Py_buffer *view, int flags) { - HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject *)op; + HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject*)op; self->buffer[0] = '1'; self->buffer[1] = '2'; self->buffer[2] = '3'; @@ -733,7 +733,7 @@ heapctypewithbuffer_getbuffer(PyObject *op, Py_buffer *view, int flags) static void heapctypewithbuffer_releasebuffer(PyObject *op, Py_buffer *view) { - HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject *)op; + HeapCTypeWithBufferObject *self = (HeapCTypeWithBufferObject*)op; assert(view->obj == (void*) self); } @@ -1247,7 +1247,7 @@ HeapCCollection_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) static Py_ssize_t HeapCCollection_length(PyObject *op) { - PyVarObject *self = (PyVarObject *)op; + PyVarObject *self = (PyVarObject*)op; return Py_SIZE(self); } diff --git a/Modules/_testlimitedcapi/heaptype_relative.c b/Modules/_testlimitedcapi/heaptype_relative.c index 5145c86853a6fa..fc278a70b77d31 100644 --- a/Modules/_testlimitedcapi/heaptype_relative.c +++ b/Modules/_testlimitedcapi/heaptype_relative.c @@ -77,7 +77,7 @@ make_sized_heaptypes(PyObject *module, PyObject *args) static PyObject * var_heaptype_set_data_to_3s( PyObject *self, PyTypeObject *defining_class, - PyObject * const *args, Py_ssize_t nargs, PyObject *kwnames) + PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { void *data_ptr = PyObject_GetTypeData(self, defining_class); if (!data_ptr) { @@ -93,7 +93,7 @@ var_heaptype_set_data_to_3s( static PyObject * var_heaptype_get_data(PyObject *self, PyTypeObject *defining_class, - PyObject * const *args, Py_ssize_t nargs, PyObject *kwnames) + PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { void *data_ptr = PyObject_GetTypeData(self, defining_class); if (!data_ptr) {