]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/python] Add typesafe wrapper around PyObject_CallMethod
authorTom Tromey <tom@tromey.com>
Wed, 12 Jun 2024 16:58:49 +0000 (18:58 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 12 Jun 2024 16:58:49 +0000 (18:58 +0200)
commit764af878259768bb70c65bdf3f3285c2d6409bbd
treebf3bc2a132a945048a154717a02f7f1f9b19048d
parent72476aca8f585a026a54cf71ccdf7bed26db1903
[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>
gdb/python/py-breakpoint.c
gdb/python/py-disasm.c
gdb/python/py-finishbreakpoint.c
gdb/python/py-framefilter.c
gdb/python/py-tui.c
gdb/python/python-internal.h