8000 fix UBSan failures for `legacy_tracing.c` · python/cpython@77b2576 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77b2576

Browse files
committed
fix UBSan failures for legacy_tracing.c
1 parent 49234c0 commit 77b2576

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

Python/legacy_tracing.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ typedef struct _PyLegacyEventHandler {
1616
int event;
1717
} _PyLegacyEventHandler;
1818

19+
#define _PyLegacyEventHandler_CAST(op) ((_PyLegacyEventHandler *)(op))
20+
1921
#ifdef Py_GIL_DISABLED
2022
#define LOCK_SETUP() PyMutex_Lock(&_PyRuntime.ceval.sys_trace_profile_mutex);
2123
#define UNLOCK_SETUP() PyMutex_Unlock(&_PyRuntime.ceval.sys_trace_profile_mutex);
@@ -54,51 +56,56 @@ call_profile_func(_PyLegacyEventHandler *self, PyObject *arg)
5456

5557
static PyObject *
5658
sys_profile_start(
57-
_PyLegacyEventHandler *self, PyObject *const *args,
59+
PyObject *op, PyObject *const *args,
5860
size_t nargsf, PyObject *kwnames
5961
) {
6062
assert(kwnames == NULL);
6163
assert(PyVectorcall_NARGS(nargsf) == 2);
64+
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
6265
return call_profile_func(self, Py_None);
6366
}
6467

6568
static PyObject *
6669
sys_profile_throw(
67-
_PyLegacyEventHandler *self, PyObject *const *args,
70+
PyObject *op, PyObject *const *args,
6871
size_t nargsf, PyObject *kwnames
6972
) {
7073
assert(kwnames == NULL);
7174
assert(PyVectorcall_NARGS(nargsf) == 3);
75+
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
7276
return call_profile_func(self, Py_None);
7377
}
7478

7579
static PyObject *
7680
sys_profile_return(
77-
_PyLegacyEventHandler *self, PyObject *const *args,
81+
PyObject *op, PyObject *const *args,
7882
size_t nargsf, PyObject *kwnames
7983
) {
8084
assert(kwnames == NULL);
8185
assert(PyVectorcall_NARGS(nargsf) == 3);
86+
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
8287
return call_profile_func(self, args[2]);
8388
}
8489

8590
static PyObject *
8691
sys_profile_unwind(
87-
_PyLegacyEventHandler *self, PyObject *const *args,
92+
PyObject *op, PyObject *const *args,
8893
size_t nargsf, PyObject *kwnames
8994
) {
9095
assert(kwnames == NULL);
9196
assert(PyVectorcall_NARGS(nargsf) == 3);
92-
return call_profile_func(self, NULL);
97+
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
98+
return call_profile_func(self, NULL);
9399
}
94100

95101
static PyObject *
96102
sys_profile_call_or_return(
97-
_PyLegacyEventHandler *self, PyObject *const *args,
103+
PyObject *op, PyObject *const *args,
98104
size_t nargsf, PyObject *kwnames
99105
) {
100106
assert(kwnames == NULL);
101107
assert(PyVectorcall_NARGS(nargsf) == 4);
108+
_PyLegacyEventHandler *self = _PyLegacyEventHandler_CAST(op);
102109
PyObject *callable = args[2];
103110
if (PyCFunction_Check(callable)) {
104111
return call_profile_func(self, callable);
@@ -428,38 +435,38 @@ setup_profile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg, PyObject
428435
if (!tstate->interp->sys_profile_initialized) {
429436
tstate->interp->sys_profile_initialized = true;
430437
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
431-
(vectorcallfunc)sys_profile_start, PyTrace_CALL,
432-
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
438+
sys_profile_start, PyTrace_CALL,
439+
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
433440
return -1;
434441
}
435442
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
436-
(vectorcallfunc)sys_profile_throw, PyTrace_CALL,
437-
PY_MONITORING_EVENT_PY_THROW, -1)) {
443+
sys_profile_throw, PyTrace_CALL,
444+
PY_MONITORING_EVENT_PY_THROW, -1)) {
438445
return -1;
439446
}
440447
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
441-
(vectorcallfunc)sys_profile_return, PyTrace_RETURN,
442-
PY_MONITORING_EVENT_PY_RETURN, PY_MONITORING_EVENT_PY_YIELD)) {
448+
sys_profile_return, PyTrace_RETURN,
449+
PY_MONITORING_EVENT_PY_RETURN, PY_MONITORING_EVENT_PY_YIELD)) {
443450
return -1;
444451
}
445452
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
446-
(vectorcallfunc)sys_profile_unwind, PyTrace_RETURN,
447-
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
453+
sys_profile_unwind, PyTrace_RETURN,
454+
PY_MONITORING_EVENT_PY_UNWIND, -1)) {
448455
return -1;
449456
}
450457
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
451-
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_CALL,
452-
PY_MONITORING_EVENT_CALL, -1)) {
458+
sys_profile_call_or_return, PyTrace_C_CALL,
459+
PY_MONITORING_EVENT_CALL, -1)) {
453460
return -1;
454461
}
455462
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
456-
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_RETURN,
457-
PY_MONITORING_EVENT_C_RETURN, -1)) {
463+
sys_profile_call_or_return, PyTrace_C_RETURN,
464+
PY_MONITORING_EVENT_C_RETURN, -1)) {
458465
return -1;
459466
}
460467
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
461-
(vectorcallfunc)sys_profile_call_or_return, PyTrace_C_EXCEPTION,
462-
PY_MONITORING_EVENT_C_RAISE, -1)) {
468+
sys_profile_call_or_return, PyTrace_C_EXCEPTION,
469+
PY_MONITORING_EVENT_C_RAISE, -1)) {
463470
return -1;
464471
}
465472
}

0 commit comments

Comments
 (0)
0