mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
gh-111178: fix UBSan failures in Modules/_lsprof.c
(GH-129782)
Fix UBSan failures for `ProfilerObject` Suppress unused return value
This commit is contained in:
parent
31ad8b6d08
commit
a1d4b1c447
1 changed files with 15 additions and 11 deletions
|
@ -56,6 +56,8 @@ typedef struct {
|
||||||
PyObject* missing;
|
PyObject* missing;
|
||||||
} ProfilerObject;
|
} ProfilerObject;
|
||||||
|
|
||||||
|
#define ProfilerObject_CAST(op) ((ProfilerObject *)(op))
|
||||||
|
|
||||||
#define POF_ENABLED 0x001
|
#define POF_ENABLED 0x001
|
||||||
#define POF_SUBCALLS 0x002
|
#define POF_SUBCALLS 0x002
|
||||||
#define POF_BUILTINS 0x004
|
#define POF_BUILTINS 0x004
|
||||||
|
@ -921,18 +923,20 @@ _lsprof_Profiler_clear_impl(ProfilerObject *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
profiler_traverse(ProfilerObject *op, visitproc visit, void *arg)
|
profiler_traverse(PyObject *op, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
|
ProfilerObject *self = ProfilerObject_CAST(op);
|
||||||
Py_VISIT(Py_TYPE(op));
|
Py_VISIT(Py_TYPE(op));
|
||||||
Py_VISIT(op->externalTimer);
|
Py_VISIT(self->externalTimer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
profiler_dealloc(ProfilerObject *op)
|
profiler_dealloc(PyObject *op)
|
||||||
{
|
{
|
||||||
PyObject_GC_UnTrack(op);
|
ProfilerObject *self = ProfilerObject_CAST(op);
|
||||||
if (op->flags & POF_ENABLED) {
|
PyObject_GC_UnTrack(self);
|
||||||
|
if (self->flags & POF_ENABLED) {
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
|
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
|
||||||
PyErr_FormatUnraisable("Exception ignored while "
|
PyErr_FormatUnraisable("Exception ignored while "
|
||||||
|
@ -940,11 +944,11 @@ profiler_dealloc(ProfilerObject *op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_unmatched(op);
|
flush_unmatched(self);
|
||||||
clearEntries(op);
|
clearEntries(self);
|
||||||
Py_XDECREF(op->externalTimer);
|
Py_XDECREF(self->externalTimer);
|
||||||
PyTypeObject *tp = Py_TYPE(op);
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
tp->tp_free(op);
|
tp->tp_free(self);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,7 +1049,7 @@ _lsprof_clear(PyObject *module)
|
||||||
static void
|
static void
|
||||||
_lsprof_free(void *module)
|
_lsprof_free(void *module)
|
||||||
{
|
{
|
||||||
_lsprof_clear((PyObject *)module);
|
(void)_lsprof_clear((PyObject *)module);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue