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 <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2024-05-30 16:16:48 -07:00
parent 551851b03d
commit b47567017e

View File

@ -477,9 +477,9 @@ static struct drgn_error *py_object_find_fn(const char *name, size_t name_len,
if (!flags_obj) if (!flags_obj)
return drgn_error_from_python(); return drgn_error_from_python();
_cleanup_pydecref_ PyObject *obj = _cleanup_pydecref_ PyObject *obj =
PyObject_CallFunction(PyTuple_GET_ITEM(arg, 1), "OOOs", PyObject_CallFunction(arg, "OOOs",
PyTuple_GET_ITEM(arg, 0), name_obj, container_of(drgn_object_program(ret), Program, prog),
flags_obj, filename); name_obj, flags_obj, filename);
if (!obj) if (!obj)
return drgn_error_from_python(); return drgn_error_from_python();
if (obj == Py_None) if (obj == Py_None)
@ -573,14 +573,11 @@ static PyObject *Program_add_object_finder(Program *self, PyObject *args,
return NULL; return NULL;
} }
_cleanup_pydecref_ PyObject *arg = Py_BuildValue("OO", self, fn); if (Program_hold_object(self, fn))
if (!arg)
return NULL;
if (Program_hold_object(self, arg))
return NULL; return NULL;
err = drgn_program_add_object_finder(&self->prog, py_object_find_fn, err = drgn_program_add_object_finder(&self->prog, py_object_find_fn,
arg); fn);
if (err) if (err)
return set_drgn_error(err); return set_drgn_error(err);
Py_RETURN_NONE; Py_RETURN_NONE;