8000 gh-111178: fix UBSan failures in `Modules/_ctypes` by picnixz · Pull Request #129071 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_ctypes #129071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 21, 2025
Next Next commit
fix UBSan failures for DictRemoverObject
  • Loading branch information
picnixz committed Jan 20, 2025
commit 9c87ae156ba7923a0d079dc8f9afbc3b4eabc8db
12 changes: 8 additions & 4 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,22 @@ typedef struct {
PyObject *dict;
} DictRemoverObject;

#define _DictRemoverObject_CAST(op) ((DictRemoverObject *)(op))

static int
_DictRemover_traverse(DictRemoverObject *self, visitproc visit, void *arg)
_DictRemover_traverse(PyObject *myself, visitproc visit, void *arg)
{
DictRemoverObject *self = _DictRemoverObject_CAST(myself);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->key);
Py_VISIT(self->dict);
return 0;
}

static int
_DictRemover_clear(DictRemoverObject *self)
_DictRemover_clear(PyObject *myself)
{
DictRemoverObject *self = _DictRemoverObject_CAST(myself);
Py_CLEAR(self->key);
Py_CLEAR(self->dict);
return 0;
Expand All @@ -167,7 +171,7 @@ static void
_DictRemover_dealloc(PyObject *myself)
{
PyTypeObject *tp = Py_TYPE(myself);
DictRemoverObject *self = (DictRemoverObject *)myself;
DictRemoverObject *self = _DictRemoverObject_CAST(myself);
PyObject_GC_UnTrack(myself);
(void)_DictRemover_clear(self);
tp->tp_free(myself);
Expand All @@ -177,7 +181,7 @@ _DictRemover_dealloc(PyObject *myself)
static PyObject *
_DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
{
DictRemoverObject *self = (DictRemoverObject *)myself;
DictRemoverObject *self = _DictRemoverObject_CAST(myself);
if (self->key && self->dict) {
if (-1 == PyDict_DelItem(self->dict, self->key)) {
PyErr_FormatUnraisable("Exception ignored on calling _ctypes.DictRemover");
Expand Down
0