https://github.com/python/cpython/commit/45191797d89bfb803f059b4dfca3823b645eb701
commit: 45191797d89bfb803f059b4dfca3823b645eb701
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2025-03-24T10:59:30+01:00
summary:
gh-111178: fix UBSan failures for `Modules/_testmultiphase.c` (#131615)
files:
M Modules/_testmultiphase.c
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
index 3f456e1f40da1f..bfec0678e2c669 100644
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -28,6 +28,8 @@ typedef struct {
PyObject *x_attr; /* Attributes dictionary */
} ExampleObject;
+#define ExampleObject_CAST(op) ((ExampleObject *)(op))
+
typedef struct {
PyObject *integer;
} testmultiphase_state;
@@ -39,20 +41,22 @@ typedef struct {
/* Example methods */
static int
-Example_traverse(ExampleObject *self, visitproc visit, void *arg)
+Example_traverse(PyObject *op, visitproc visit, void *arg)
{
+ ExampleObject *self = ExampleObject_CAST(op);
Py_VISIT(self->x_attr);
return 0;
}
static void
-Example_finalize(ExampleObject *self)
+Example_finalize(PyObject *op)
{
+ ExampleObject *self = ExampleObject_CAST(op);
Py_CLEAR(self->x_attr);
}
static PyObject *
-Example_demo(ExampleObject *self, PyObject *args)
+Example_demo(PyObject *op, PyObject *args)
{
PyObject *o = NULL;
if (!PyArg_ParseTuple(args, "|O:demo", &o))
@@ -66,14 +70,15 @@ Example_demo(ExampleObject *self, PyObject *args)
#include "clinic/_testmultiphase.c.h"
static PyMethodDef Example_methods[] = {
- {"demo", (PyCFunction)Example_demo, METH_VARARGS,
+ {"demo", Example_demo, METH_VARARGS,
PyDoc_STR("demo() -> None")},
{NULL, NULL} /* sentinel */
};
static PyObject *
-Example_getattro(ExampleObject *self, PyObject *name)
+Example_getattro(PyObject *op, PyObject *name)
{
+ ExampleObject *self = ExampleObject_CAST(op);
if (self->x_attr != NULL) {
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
@@ -87,8 +92,9 @@ Example_getattro(ExampleObject *self, PyObject *name)
}
static int
-Example_setattr(ExampleObject *self, const char *name, PyObject *v)
+Example_setattr(PyObject *op, char *name, PyObject *v)
{
+ ExampleObject *self = ExampleObject_CAST(op);
if (self->x_attr == NULL) {
self->x_attr = PyDict_New();
if (self->x_attr == NULL)
@@ -212,7 +218,7 @@ PyDoc_STRVAR(_StateAccessType_decrement_count__doc__,
// Intentionally does not use Argument Clinic
static PyObject *
-_StateAccessType_increment_count_noclinic(StateAccessTypeObject *self,
+_StateAccessType_increment_count_noclinic(PyObject *self,
PyTypeObject *defining_class,
PyObject *const *args,
Py_ssize_t nargs,
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]