summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2025-03-24 09:58:33 (GMT)
committerGitHub <noreply@github.com>2025-03-24 09:58:33 (GMT)
commit43fde78bef4635a84bdbea3d0efda26d9f6a203f (patch)
treeaaf5ebf0a0c62b16f0dd1a7cf7adb962922721fa /Python
parent27f81e82df2083d9430a3084aee1860b0d5ef441 (diff)
downloadcpython-43fde78bef4635a84bdbea3d0efda26d9f6a203f.zip
cpython-43fde78bef4635a84bdbea3d0efda26d9f6a203f.tar.gz
cpython-43fde78bef4635a84bdbea3d0efda26d9f6a203f.tar.bz2
gh-111178: fix UBSan failures for `Python/instrumentation.c` (#131608)
Diffstat (limited to 'Python')
-rw-r--r--Python/instrumentation.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/Python/instrumentation.c b/Python/instrumentation.c
index 9bf0fc4..bcf7267 100644
--- a/Python/instrumentation.c
+++ b/Python/instrumentation.c
@@ -2916,18 +2916,21 @@ typedef struct _PyLegacyBranchEventHandler {
int tool_id;
} _PyLegacyBranchEventHandler;
+#define _PyLegacyBranchEventHandler_CAST(op) ((_PyLegacyBranchEventHandler *)(op))
+
static void
-dealloc_branch_handler(_PyLegacyBranchEventHandler *self)
+dealloc_branch_handler(PyObject *op)
{
+ _PyLegacyBranchEventHandler *self = _PyLegacyBranchEventHandler_CAST(op);
Py_CLEAR(self->handler);
- PyObject_Free((PyObject *)self);
+ PyObject_Free(self);
}
static PyTypeObject _PyLegacyBranchEventHandler_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"sys.monitoring.branch_event_handler",
sizeof(_PyLegacyBranchEventHandler),
- .tp_dealloc = (destructor)dealloc_branch_handler,
+ .tp_dealloc = dealloc_branch_handler,
.tp_vectorcall_offset = offsetof(_PyLegacyBranchEventHandler, vectorcall),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_VECTORCALL | Py_TPFLAGS_DISALLOW_INSTANTIATION,
@@ -2936,10 +2939,11 @@ static PyTypeObject _PyLegacyBranchEventHandler_Type = {
static PyObject *
-branch_handler(
- _PyLegacyBranchEventHandler *self, PyObject *const *args,
+branch_handler_vectorcall(
+ PyObject *op, PyObject *const *args,
size_t nargsf, PyObject *kwnames
) {
+ _PyLegacyBranchEventHandler *self = _PyLegacyBranchEventHandler_CAST(op);
// Find the other instrumented instruction and remove tool
// The spec (PEP 669) allows spurious events after a DISABLE,
// so a best effort is good enough.
@@ -3000,7 +3004,7 @@ static PyObject *make_branch_handler(int tool_id, PyObject *handler, bool right)
if (callback == NULL) {
return NULL;
}
- callback->vectorcall = (vectorcallfunc)branch_handler;
+ callback->vectorcall = branch_handler_vectorcall;
callback->handler = Py_NewRef(handler);
callback->right = right;
callback->tool_id = tool_id;
@@ -3062,6 +3066,8 @@ typedef struct {
int bi_offset;
} branchesiterator;
+#define branchesiterator_CAST(op) ((branchesiterator *)(op))
+
static PyObject *
int_triple(int a, int b, int c) {
PyObject *obja = PyLong_FromLong(a);
@@ -3088,8 +3094,9 @@ error:
}
static PyObject *
-branchesiter_next(branchesiterator *bi)
+branchesiter_next(PyObject *op)
{
+ branchesiterator *bi = branchesiterator_CAST(op);
int offset = bi->bi_offset;
int oparg = 0;
while (offset < Py_SIZE(bi->bi_code)) {
@@ -3130,8 +3137,9 @@ branchesiter_next(branchesiterator *bi)
}
static void
-branchesiter_dealloc(branchesiterator *bi)
+branchesiter_dealloc(PyObject *op)
{
+ branchesiterator *bi = branchesiterator_CAST(op);
Py_DECREF(bi->bi_code);
PyObject_Free(bi);
}
@@ -3142,10 +3150,10 @@ static PyTypeObject _PyBranchesIterator = {
sizeof(branchesiterator), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- .tp_dealloc = (destructor)branchesiter_dealloc,
+ .tp_dealloc = branchesiter_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_iter = PyObject_SelfIter,
- .tp_iternext = (iternextfunc)branchesiter_next,
+ .tp_iternext = branchesiter_next,
.tp_free = PyObject_Del,
};