Turn gdbpy_ref into a template
This turns gdbpy_ref into a template class, so that it can be used to wrap subclasses of PyObject. The default argument remains PyObject; and this necessitated renaming uses of "gdbpy_ref" to "gdbpy_ref<>". gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/py-ref.h (gdbpy_ref_policy): Now a template. (gdbpy_ref): Now a template; allow subclasses of PyObject to be used. * python/py-arch.c, python/py-bpevent.c, python/py-breakpoint.c, python/py-cmd.c, python/py-continueevent.c, python/py-event.c, python/py-exitedevent.c, python/py-finishbreakpoint.c, python/py-framefilter.c, python/py-function.c, python/py-inferior.c, python/py-infevents.c, python/py-linetable.c, python/py-newobjfileevent.c, python/py-param.c, python/py-prettyprint.c, python/py-ref.h, python/py-signalevent.c, python/py-stopevent.c, python/py-symbol.c, python/py-threadevent.c, python/py-type.c, python/py-unwind.c, python/py-utils.c, python/py-value.c, python/py-varobj.c, python/py-xmethods.c, python/python.c, varobj.c: Change gdbpy_ref to gdbpy_ref<>.
This commit is contained in:
parent
d4b0bb186e
commit
7780f18678
30 changed files with 260 additions and 234 deletions
|
@ -96,8 +96,8 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
|
|||
{
|
||||
int enabled;
|
||||
|
||||
gdbpy_ref enabled_field (PyObject_GetAttrString (matcher,
|
||||
enabled_field_name));
|
||||
gdbpy_ref<> enabled_field (PyObject_GetAttrString (matcher,
|
||||
enabled_field_name));
|
||||
if (enabled_field == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -110,11 +110,12 @@ invoke_match_method (PyObject *matcher, PyObject *py_obj_type,
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
gdbpy_ref match_method (PyObject_GetAttrString (matcher, match_method_name));
|
||||
gdbpy_ref<> match_method (PyObject_GetAttrString (matcher,
|
||||
match_method_name));
|
||||
if (match_method == NULL)
|
||||
return NULL;
|
||||
|
||||
gdbpy_ref py_xmethod_name (PyString_FromString (xmethod_name));
|
||||
gdbpy_ref<> py_xmethod_name (PyString_FromString (xmethod_name));
|
||||
if (py_xmethod_name == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -139,7 +140,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
|
||||
gdbpy_enter enter_py (get_current_arch (), current_language);
|
||||
|
||||
gdbpy_ref py_type (type_to_type_object (obj_type));
|
||||
gdbpy_ref<> py_type (type_to_type_object (obj_type));
|
||||
if (py_type == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -147,7 +148,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
}
|
||||
|
||||
/* Create an empty list of debug methods. */
|
||||
gdbpy_ref py_xmethod_matcher_list (PyList_New (0));
|
||||
gdbpy_ref<> py_xmethod_matcher_list (PyList_New (0));
|
||||
if (py_xmethod_matcher_list == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -167,9 +168,9 @@ gdbpy_get_matching_xmethod_workers
|
|||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref objfile_matchers (objfpy_get_xmethods (py_objfile, NULL));
|
||||
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
objfile_matchers.get ()));
|
||||
gdbpy_ref<> objfile_matchers (objfpy_get_xmethods (py_objfile, NULL));
|
||||
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
objfile_matchers.get ()));
|
||||
if (temp == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -184,10 +185,10 @@ gdbpy_get_matching_xmethod_workers
|
|||
py_progspace = pspace_to_pspace_object (current_program_space);
|
||||
if (py_progspace != NULL)
|
||||
{
|
||||
gdbpy_ref pspace_matchers (pspy_get_xmethods (py_progspace, NULL));
|
||||
gdbpy_ref<> pspace_matchers (pspy_get_xmethods (py_progspace, NULL));
|
||||
|
||||
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
pspace_matchers.get ()));
|
||||
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
pspace_matchers.get ()));
|
||||
if (temp == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -206,12 +207,12 @@ gdbpy_get_matching_xmethod_workers
|
|||
if (gdb_python_module != NULL
|
||||
&& PyObject_HasAttrString (gdb_python_module, matchers_attr_str))
|
||||
{
|
||||
gdbpy_ref gdb_matchers (PyObject_GetAttrString (gdb_python_module,
|
||||
matchers_attr_str));
|
||||
gdbpy_ref<> gdb_matchers (PyObject_GetAttrString (gdb_python_module,
|
||||
matchers_attr_str));
|
||||
if (gdb_matchers != NULL)
|
||||
{
|
||||
gdbpy_ref temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
gdb_matchers.get ()));
|
||||
gdbpy_ref<> temp (PySequence_Concat (py_xmethod_matcher_list.get (),
|
||||
gdb_matchers.get ()));
|
||||
if (temp == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -227,7 +228,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
}
|
||||
}
|
||||
|
||||
gdbpy_ref list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ()));
|
||||
gdbpy_ref<> list_iter (PyObject_GetIter (py_xmethod_matcher_list.get ()));
|
||||
if (list_iter == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -235,7 +236,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
}
|
||||
while (true)
|
||||
{
|
||||
gdbpy_ref matcher (PyIter_Next (list_iter.get ()));
|
||||
gdbpy_ref<> matcher (PyIter_Next (list_iter.get ()));
|
||||
if (matcher == NULL)
|
||||
{
|
||||
if (PyErr_Occurred ())
|
||||
|
@ -246,9 +247,9 @@ gdbpy_get_matching_xmethod_workers
|
|||
break;
|
||||
}
|
||||
|
||||
gdbpy_ref match_result (invoke_match_method (matcher.get (),
|
||||
py_type.get (),
|
||||
method_name));
|
||||
gdbpy_ref<> match_result (invoke_match_method (matcher.get (),
|
||||
py_type.get (),
|
||||
method_name));
|
||||
|
||||
if (match_result == NULL)
|
||||
{
|
||||
|
@ -259,7 +260,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
; /* This means there was no match. */
|
||||
else if (PySequence_Check (match_result.get ()))
|
||||
{
|
||||
gdbpy_ref iter (PyObject_GetIter (match_result.get ()));
|
||||
gdbpy_ref<> iter (PyObject_GetIter (match_result.get ()));
|
||||
|
||||
if (iter == NULL)
|
||||
{
|
||||
|
@ -270,7 +271,7 @@ gdbpy_get_matching_xmethod_workers
|
|||
{
|
||||
struct xmethod_worker *worker;
|
||||
|
||||
gdbpy_ref py_worker (PyIter_Next (iter.get ()));
|
||||
gdbpy_ref<> py_worker (PyIter_Next (iter.get ()));
|
||||
if (py_worker == NULL)
|
||||
{
|
||||
if (PyErr_Occurred ())
|
||||
|
@ -316,13 +317,13 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
|
|||
PyObject *py_worker = worker_data->worker;
|
||||
struct type *obj_type;
|
||||
int i = 1, arg_count;
|
||||
gdbpy_ref list_iter;
|
||||
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
|
||||
gdbpy_ref<> get_arg_types_method
|
||||
(PyObject_GetAttrString (py_worker, get_arg_types_method_name));
|
||||
if (get_arg_types_method == NULL)
|
||||
{
|
||||
|
@ -330,7 +331,7 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
|
|||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref py_argtype_list
|
||||
gdbpy_ref<> py_argtype_list
|
||||
(PyObject_CallMethodObjArgs (py_worker, py_get_arg_types_method_name,
|
||||
NULL));
|
||||
if (py_argtype_list == NULL)
|
||||
|
@ -368,7 +369,7 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang,
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
gdbpy_ref item (PyIter_Next (list_iter.get ()));
|
||||
gdbpy_ref<> item (PyIter_Next (list_iter.get ()));
|
||||
if (item == NULL)
|
||||
{
|
||||
if (PyErr_Occurred ())
|
||||
|
@ -445,7 +446,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
|
|||
|
||||
/* First see if there is a get_result_type method.
|
||||
If not this could be an old xmethod (pre 7.9.1). */
|
||||
gdbpy_ref get_result_type_method
|
||||
gdbpy_ref<> get_result_type_method
|
||||
(PyObject_GetAttrString (py_worker, get_result_type_method_name));
|
||||
if (get_result_type_method == NULL)
|
||||
{
|
||||
|
@ -475,14 +476,14 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
|
|||
if (!types_equal (obj_type, this_type))
|
||||
obj = value_cast (this_type, obj);
|
||||
}
|
||||
gdbpy_ref py_value_obj (value_to_value_object (obj));
|
||||
gdbpy_ref<> py_value_obj (value_to_value_object (obj));
|
||||
if (py_value_obj == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
if (py_arg_tuple == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -505,7 +506,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
|
|||
PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
|
||||
}
|
||||
|
||||
gdbpy_ref py_result_type
|
||||
gdbpy_ref<> py_result_type
|
||||
(PyObject_CallObject (get_result_type_method.get (), py_arg_tuple.get ()));
|
||||
if (py_result_type == NULL)
|
||||
{
|
||||
|
@ -563,14 +564,14 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
|
|||
if (!types_equal (obj_type, this_type))
|
||||
obj = value_cast (this_type, obj);
|
||||
}
|
||||
gdbpy_ref py_value_obj (value_to_value_object (obj));
|
||||
gdbpy_ref<> py_value_obj (value_to_value_object (obj));
|
||||
if (py_value_obj == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
error (_("Error while executing Python code."));
|
||||
}
|
||||
|
||||
gdbpy_ref py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
gdbpy_ref<> py_arg_tuple (PyTuple_New (nargs + 1));
|
||||
if (py_arg_tuple == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -594,8 +595,8 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
|
|||
PyTuple_SET_ITEM (py_arg_tuple.get (), i + 1, py_value_arg);
|
||||
}
|
||||
|
||||
gdbpy_ref py_result (PyObject_CallObject (xmethod_worker,
|
||||
py_arg_tuple.get ()));
|
||||
gdbpy_ref<> py_result (PyObject_CallObject (xmethod_worker,
|
||||
py_arg_tuple.get ()));
|
||||
if (py_result == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue