diff options
author | Tom Tromey <tom@tromey.com> | 2024-06-12 18:58:49 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-06-12 18:58:49 +0200 |
commit | 764af878259768bb70c65bdf3f3285c2d6409bbd (patch) | |
tree | bf3bc2a132a945048a154717a02f7f1f9b19048d /gdb/python/py-disasm.c | |
parent | 72476aca8f585a026a54cf71ccdf7bed26db1903 (diff) | |
download | binutils-764af878259768bb70c65bdf3f3285c2d6409bbd.zip binutils-764af878259768bb70c65bdf3f3285c2d6409bbd.tar.gz binutils-764af878259768bb70c65bdf3f3285c2d6409bbd.tar.bz2 |
[gdb/python] Add typesafe wrapper around PyObject_CallMethod
In gdb/python/py-tui.c we have code like this:
...
gdbpy_ref<> result (PyObject_CallMethod (m_window.get(), "hscroll",
"i", num_to_scroll, nullptr));
...
The nullptr is superfluous, the format string already indicates that there's
only one method argument.
OTOH, passing no method args does use a nullptr:
...
gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "render",
nullptr));
...
Furthermore, choosing the right format string chars can be tricky.
Add a typesafe wrapper around PyObject_CallMethod that hides these
details, such that we can use the more intuitive:
...
gdbpy_ref<> result (gdbpy_call_method (m_window.get(), "hscroll",
num_to_scroll));
...
and:
...
gdbpy_ref<> result (gdbpy_call_method (m_window.get (), "render"));
...
Tested on x86_64-linux.
Co-Authored-By: Tom de Vries <tdevries@suse.de>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/py-disasm.c')
-rw-r--r-- | gdb/python/py-disasm.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c index 9337514..5206c76 100644 --- a/gdb/python/py-disasm.c +++ b/gdb/python/py-disasm.c @@ -855,9 +855,8 @@ gdbpy_disassembler::read_memory_func (bfd_vma memaddr, gdb_byte *buff, /* Now call the DisassembleInfo.read_memory method. This might have been overridden by the user. */ - gdbpy_ref<> result_obj (PyObject_CallMethod ((PyObject *) obj, - "read_memory", - "I" GDB_PY_LL_ARG, len, offset)); + gdbpy_ref<> result_obj (gdbpy_call_method ((PyObject *) obj, "read_memory", + len, offset)); /* Handle any exceptions. */ if (result_obj == nullptr) |