invoke_xmethod & array_view
This replaces more pointer+length with gdb::array_view. This time, around invoke_xmethod, and then propagating the fallout around, which inevitably leaks to the overload resolution code. There are several places in the code that want to grab a slice of an array, by advancing the array pointer, and decreasing the length pointer. This patch introduces a pair of new gdb::array_view::slice(...) methods to make that convenient and clear. Unit test included. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * common/array-view.h (array_view::splice(size_type, size_t)): New. (array_view::splice(size_type)): New. * eval.c (eval_call, evaluate_funcall): Adjust to use array_view. * extension.c (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. * extension.h: Include "common/array-view.h". (xmethod_worker::invoke): Adjust to use gdb::array_view. (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. (xmethod_worker::do_get_arg_types): Adjust to use std::vector. (xmethod_worker::do_get_result_type): Adjust to use gdb::array_view. * gdbtypes.c (rank_function): Adjust to use gdb::array_view. * gdbtypes.h: Include "common/array-view.h". (rank_function): Adjust to use gdb::array_view. * python/py-xmethods.c (python_xmethod_worker::invoke) (python_xmethod_worker::do_get_arg_types) (python_xmethod_worker::do_get_result_type) (python_xmethod_worker::invoke): Adjust to new interfaces. * valarith.c (value_user_defined_cpp_op, value_user_defined_op) (value_x_binop, value_x_unop): Adjust to use gdb::array_view. * valops.c (find_overload_match, find_oload_champ_namespace) (find_oload_champ_namespace_loop, find_oload_champ): Adjust to use gdb:array_view and the new xmethod_worker interfaces. * value.c (result_type_of_xmethod, call_xmethod): Adjust to use gdb::array_view. * value.h (find_overload_match, result_type_of_xmethod) (call_xmethod): Adjust to use gdb::array_view. * unittests/array-view-selftests.c: Add slicing tests.
This commit is contained in:
parent
e71585ffe2
commit
6b1747cd13
13 changed files with 212 additions and 151 deletions
|
@ -46,11 +46,11 @@ struct python_xmethod_worker : xmethod_worker
|
|||
|
||||
/* Implementation of xmethod_worker::invoke for Python. */
|
||||
|
||||
value *invoke (value *obj, value **args, int nargs) override;
|
||||
value *invoke (value *obj, gdb::array_view<value *> args) override;
|
||||
|
||||
/* Implementation of xmethod_worker::do_get_arg_types for Python. */
|
||||
|
||||
ext_lang_rc do_get_arg_types (int *nargs, type ***arg_types) override;
|
||||
ext_lang_rc do_get_arg_types (std::vector<type *> *type_args) override;
|
||||
|
||||
/* Implementation of xmethod_worker::do_get_result_type for Python.
|
||||
|
||||
|
@ -58,7 +58,7 @@ struct python_xmethod_worker : xmethod_worker
|
|||
result type, if the get_result_type operation is not provided by WORKER
|
||||
then EXT_LANG_RC_OK is returned and NULL is returned in *RESULT_TYPE. */
|
||||
|
||||
ext_lang_rc do_get_result_type (value *obj, value **args, int nargs,
|
||||
ext_lang_rc do_get_result_type (value *obj, gdb::array_view<value *> args,
|
||||
type **result_type_ptr) override;
|
||||
|
||||
private:
|
||||
|
@ -293,7 +293,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
/* See declaration. */
|
||||
|
||||
ext_lang_rc
|
||||
python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
||||
python_xmethod_worker::do_get_arg_types (std::vector<type *> *arg_types)
|
||||
{
|
||||
/* The gdbpy_enter object needs to be placed first, so that it's the last to
|
||||
be destroyed. */
|
||||
|
@ -302,10 +302,6 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
int i = 1, arg_count;
|
||||
gdbpy_ref<> list_iter;
|
||||
|
||||
/* Set nargs to -1 so that any premature return from this function returns
|
||||
an invalid/unusable number of arg types. */
|
||||
*nargs = -1;
|
||||
|
||||
gdbpy_ref<> get_arg_types_method
|
||||
(PyObject_GetAttrString (m_py_worker, get_arg_types_method_name));
|
||||
if (get_arg_types_method == NULL)
|
||||
|
@ -345,8 +341,7 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
arg_count = 1;
|
||||
|
||||
/* Include the 'this' argument in the size. */
|
||||
gdb::unique_xmalloc_ptr<struct type *> type_array
|
||||
(XCNEWVEC (struct type *, arg_count + 1));
|
||||
arg_types->resize (arg_count + 1);
|
||||
i = 1;
|
||||
if (list_iter != NULL)
|
||||
{
|
||||
|
@ -373,7 +368,7 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
(type_array.get ())[i] = arg_type;
|
||||
(*arg_types)[i] = arg_type;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -393,7 +388,7 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
}
|
||||
else
|
||||
{
|
||||
(type_array.get ())[i] = arg_type;
|
||||
(*arg_types)[i] = arg_type;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -402,10 +397,8 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
be a 'const' value. Hence, create a 'const' variant of the 'this' pointer
|
||||
type. */
|
||||
obj_type = type_object_to_type (m_this_type);
|
||||
(type_array.get ())[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type),
|
||||
NULL);
|
||||
*nargs = i;
|
||||
*arg_types = type_array.release ();
|
||||
(*arg_types)[0] = make_cv_type (1, 0, lookup_pointer_type (obj_type),
|
||||
NULL);
|
||||
|
||||
return EXT_LANG_RC_OK;
|
||||
}
|
||||
|
@ -413,7 +406,8 @@ python_xmethod_worker::do_get_arg_types (int *nargs, type ***arg_types)
|
|||
/* See declaration. */
|
||||
|
||||
ext_lang_rc
|
||||
python_xmethod_worker::do_get_result_type (value *obj, value **args, int nargs,
|
||||
python_xmethod_worker::do_get_result_type (value *obj,
|
||||
gdb::array_view<value *> args,
|
||||
type **result_type_ptr)
|
||||
{
|
||||
struct type *obj_type, *this_type;
|
||||
|
@ -461,7 +455,7 @@ python_xmethod_worker::do_get_result_type (value *obj, value **args, int nargs,
|
|||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
|
||||
if (py_arg_tuple == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -472,7 +466,7 @@ python_xmethod_worker::do_get_result_type (value *obj, value **args, int nargs,
|
|||
release. */
|
||||
PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
for (i = 0; i < args.size (); i++)
|
||||
{
|
||||
PyObject *py_value_arg = value_to_value_object (args[i]);
|
||||
|
||||
|
@ -508,8 +502,8 @@ python_xmethod_worker::do_get_result_type (value *obj, value **args, int nargs,
|
|||
/* See declaration. */
|
||||
|
||||
struct value *
|
||||
python_xmethod_worker::invoke (struct value *obj, struct value **args,
|
||||
int nargs)
|
||||
python_xmethod_worker::invoke (struct value *obj,
|
||||
gdb::array_view<value *> args)
|
||||
{
|
||||
gdbpy_enter enter_py (get_current_arch (), current_language);
|
||||
|
||||
|
@ -546,7 +540,7 @@ python_xmethod_worker::invoke (struct value *obj, struct value **args,
|
|||
error (_("Error while executing Python code."));
|
||||
}
|
||||
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (args.size () + 1));
|
||||
if (py_arg_tuple == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -557,7 +551,7 @@ python_xmethod_worker::invoke (struct value *obj, struct value **args,
|
|||
release. */
|
||||
PyTuple_SET_ITEM (py_arg_tuple.get (), 0, py_value_obj.release ());
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
for (i = 0; i < args.size (); i++)
|
||||
{
|
||||
PyObject *py_value_arg = value_to_value_object (args[i]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue