From b47567017eb6fe449a411ef73e51281649899266 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Thu, 30 May 2024 16:16:48 -0700 Subject: [PATCH] libdrgn: python: don't construct unnecessary tuple for add_object_finder() We can get the Program object from the return drgn_object, so we don't need a tuple. Signed-off-by: Omar Sandoval --- libdrgn/python/program.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libdrgn/python/program.c b/libdrgn/python/program.c index 5ed3873a..bf822558 100644 --- a/libdrgn/python/program.c +++ b/libdrgn/python/program.c @@ -477,9 +477,9 @@ static struct drgn_error *py_object_find_fn(const char *name, size_t name_len, if (!flags_obj) return drgn_error_from_python(); _cleanup_pydecref_ PyObject *obj = - PyObject_CallFunction(PyTuple_GET_ITEM(arg, 1), "OOOs", - PyTuple_GET_ITEM(arg, 0), name_obj, - flags_obj, filename); + PyObject_CallFunction(arg, "OOOs", + container_of(drgn_object_program(ret), Program, prog), + name_obj, flags_obj, filename); if (!obj) return drgn_error_from_python(); if (obj == Py_None) @@ -573,14 +573,11 @@ static PyObject *Program_add_object_finder(Program *self, PyObject *args, return NULL; } - _cleanup_pydecref_ PyObject *arg = Py_BuildValue("OO", self, fn); - if (!arg) - return NULL; - if (Program_hold_object(self, arg)) + if (Program_hold_object(self, fn)) return NULL; err = drgn_program_add_object_finder(&self->prog, py_object_find_fn, - arg); + fn); if (err) return set_drgn_error(err); Py_RETURN_NONE;