Return gdbpy_ref<> from gdbpy_call_method

This changes gdbpy_call_method to return a gdbpy_ref<>.  This is
slightly safer because it makes it simpler to correctly handle
reference counts.

Reviewed-By: Tom de Vries <tdevries@suse.de>
This commit is contained in:
Tom Tromey
2024-06-11 14:10:08 -06:00
parent 54904469f7
commit 7c03e522d4
6 changed files with 29 additions and 29 deletions

View File

@@ -176,14 +176,14 @@ gdbpy_make_fmt ()
This variant accepts no arguments. */
static inline PyObject *
static inline gdbpy_ref<>
gdbpy_call_method (PyObject *o, const char *method)
{
/* PyObject_CallMethod's 'method' and 'format' parameters were missing the
'const' qualifier before Python 3.4. */
return PyObject_CallMethod (o,
const_cast<char *> (method),
nullptr);
return gdbpy_ref<> (PyObject_CallMethod (o,
const_cast<char *> (method),
nullptr));
}
/* Typesafe wrapper around PyObject_CallMethod.
@@ -193,7 +193,7 @@ gdbpy_call_method (PyObject *o, const char *method)
mismatches are impossible. */
template<typename Arg, typename... Args>
static inline PyObject *
static inline gdbpy_ref<>
gdbpy_call_method (PyObject *o, const char *method,
Arg arg, Args... args)
{
@@ -201,10 +201,10 @@ gdbpy_call_method (PyObject *o, const char *method,
/* PyObject_CallMethod's 'method' and 'format' parameters were missing the
'const' qualifier before Python 3.4. */
return PyObject_CallMethod (o,
const_cast<char *> (method),
const_cast<char *> (fmt.data ()),
arg, args...);
return gdbpy_ref<> (PyObject_CallMethod (o,
const_cast<char *> (method),
const_cast<char *> (fmt.data ()),
arg, args...));
}
/* Poison PyObject_CallMethod. The typesafe wrapper gdbpy_call_method should be