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
|
@ -273,7 +273,7 @@ eval_python_command (const char *command)
|
|||
d = PyModule_GetDict (m);
|
||||
if (d == NULL)
|
||||
return -1;
|
||||
gdbpy_ref v (PyRun_StringFlags (command, Py_single_input, d, d, NULL));
|
||||
gdbpy_ref<> v (PyRun_StringFlags (command, Py_single_input, d, d, NULL));
|
||||
if (v == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -351,7 +351,7 @@ python_run_simple_file (FILE *file, const char *filename)
|
|||
/* Because we have a string for a filename, and are using Python to
|
||||
open the file, we need to expand any tilde in the path first. */
|
||||
gdb::unique_xmalloc_ptr<char> full_path (tilde_expand (filename));
|
||||
gdbpy_ref python_file (PyFile_FromString (full_path.get (), "r"));
|
||||
gdbpy_ref<> python_file (PyFile_FromString (full_path.get (), "r"));
|
||||
if (python_file == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -669,8 +669,8 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
|
|||
struct symtab_and_line sal;
|
||||
char *arg = NULL;
|
||||
struct cleanup *cleanups;
|
||||
gdbpy_ref result;
|
||||
gdbpy_ref unparsed;
|
||||
gdbpy_ref<> result;
|
||||
gdbpy_ref<> unparsed;
|
||||
struct event_location *location = NULL;
|
||||
|
||||
if (! PyArg_ParseTuple (args, "|s", &arg))
|
||||
|
@ -745,7 +745,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
|
|||
Py_INCREF (Py_None);
|
||||
}
|
||||
|
||||
gdbpy_ref return_result (PyTuple_New (2));
|
||||
gdbpy_ref<> return_result (PyTuple_New (2));
|
||||
if (return_result == NULL)
|
||||
{
|
||||
do_cleanups (cleanups);
|
||||
|
@ -897,7 +897,7 @@ gdbpy_run_events (int error, gdb_client_data client_data)
|
|||
gdbpy_event_list_end = &gdbpy_event_list;
|
||||
|
||||
/* Ignore errors. */
|
||||
gdbpy_ref call_result (PyObject_CallObject (item->event, NULL));
|
||||
gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL));
|
||||
if (call_result == NULL)
|
||||
PyErr_Clear ();
|
||||
|
||||
|
@ -972,8 +972,8 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
|
|||
if (gdb_python_module
|
||||
&& PyObject_HasAttrString (gdb_python_module, "prompt_hook"))
|
||||
{
|
||||
gdbpy_ref hook (PyObject_GetAttrString (gdb_python_module,
|
||||
"prompt_hook"));
|
||||
gdbpy_ref<> hook (PyObject_GetAttrString (gdb_python_module,
|
||||
"prompt_hook"));
|
||||
if (hook == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -982,16 +982,16 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
|
|||
|
||||
if (PyCallable_Check (hook.get ()))
|
||||
{
|
||||
gdbpy_ref current_prompt (PyString_FromString (current_gdb_prompt));
|
||||
gdbpy_ref<> current_prompt (PyString_FromString (current_gdb_prompt));
|
||||
if (current_prompt == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref result (PyObject_CallFunctionObjArgs (hook.get (),
|
||||
current_prompt.get (),
|
||||
NULL));
|
||||
gdbpy_ref<> result
|
||||
(PyObject_CallFunctionObjArgs (hook.get (), current_prompt.get (),
|
||||
NULL));
|
||||
if (result == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -1206,7 +1206,7 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
|
|||
{
|
||||
struct program_space *ps;
|
||||
|
||||
gdbpy_ref list (PyList_New (0));
|
||||
gdbpy_ref<> list (PyList_New (0));
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -1296,7 +1296,7 @@ gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
|
|||
{
|
||||
struct objfile *objf;
|
||||
|
||||
gdbpy_ref list (PyList_New (0));
|
||||
gdbpy_ref<> list (PyList_New (0));
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -1327,15 +1327,15 @@ gdbpy_start_type_printers (const struct extension_language_defn *extlang,
|
|||
|
||||
gdbpy_enter enter_py (get_current_arch (), current_language);
|
||||
|
||||
gdbpy_ref type_module (PyImport_ImportModule ("gdb.types"));
|
||||
gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
|
||||
if (type_module == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return;
|
||||
}
|
||||
|
||||
gdbpy_ref func (PyObject_GetAttrString (type_module.get (),
|
||||
"get_type_recognizers"));
|
||||
gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
|
||||
"get_type_recognizers"));
|
||||
if (func == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -1372,31 +1372,32 @@ gdbpy_apply_type_printers (const struct extension_language_defn *extlang,
|
|||
|
||||
gdbpy_enter enter_py (get_current_arch (), current_language);
|
||||
|
||||
gdbpy_ref type_obj (type_to_type_object (type));
|
||||
gdbpy_ref<> type_obj (type_to_type_object (type));
|
||||
if (type_obj == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref type_module (PyImport_ImportModule ("gdb.types"));
|
||||
gdbpy_ref<> type_module (PyImport_ImportModule ("gdb.types"));
|
||||
if (type_module == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref func (PyObject_GetAttrString (type_module.get (),
|
||||
"apply_type_recognizers"));
|
||||
gdbpy_ref<> func (PyObject_GetAttrString (type_module.get (),
|
||||
"apply_type_recognizers"));
|
||||
if (func == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
return EXT_LANG_RC_ERROR;
|
||||
}
|
||||
|
||||
gdbpy_ref result_obj (PyObject_CallFunctionObjArgs (func.get (), printers_obj,
|
||||
type_obj.get (),
|
||||
(char *) NULL));
|
||||
gdbpy_ref<> result_obj (PyObject_CallFunctionObjArgs (func.get (),
|
||||
printers_obj,
|
||||
type_obj.get (),
|
||||
(char *) NULL));
|
||||
if (result_obj == NULL)
|
||||
{
|
||||
gdbpy_print_stack ();
|
||||
|
@ -1798,7 +1799,7 @@ do_finish_initialization (const struct extension_language_defn *extlang)
|
|||
}
|
||||
if (sys_path && PyList_Check (sys_path))
|
||||
{
|
||||
gdbpy_ref pythondir (PyString_FromString (gdb_pythondir.c_str ()));
|
||||
gdbpy_ref<> pythondir (PyString_FromString (gdb_pythondir.c_str ()));
|
||||
if (pythondir == NULL || PyList_Insert (sys_path, 0, pythondir.get ()))
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue