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:
Tom Tromey
2017-02-09 13:16:36 -07:00
parent d4b0bb186e
commit 7780f18678
30 changed files with 260 additions and 234 deletions

View File

@ -134,19 +134,19 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
if (! args)
args = "";
gdbpy_ref argobj (PyUnicode_Decode (args, strlen (args), host_charset (),
NULL));
gdbpy_ref<> argobj (PyUnicode_Decode (args, strlen (args), host_charset (),
NULL));
if (argobj == NULL)
{
gdbpy_print_stack ();
error (_("Could not convert arguments to Python string."));
}
gdbpy_ref ttyobj (from_tty ? Py_True : Py_False);
gdbpy_ref<> ttyobj (from_tty ? Py_True : Py_False);
Py_INCREF (ttyobj.get ());
gdbpy_ref result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
argobj.get (), ttyobj.get (),
NULL));
gdbpy_ref<> result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
argobj.get (), ttyobj.get (),
NULL));
if (result == NULL)
{
@ -241,19 +241,19 @@ cmdpy_completer_helper (struct cmd_list_element *command,
return NULL;
}
gdbpy_ref textobj (PyUnicode_Decode (text, strlen (text), host_charset (),
NULL));
gdbpy_ref<> textobj (PyUnicode_Decode (text, strlen (text), host_charset (),
NULL));
if (textobj == NULL)
error (_("Could not convert argument to Python string."));
gdbpy_ref wordobj (PyUnicode_Decode (word, strlen (word), host_charset (),
NULL));
gdbpy_ref<> wordobj (PyUnicode_Decode (word, strlen (word), host_charset (),
NULL));
if (wordobj == NULL)
error (_("Could not convert argument to Python string."));
gdbpy_ref resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj,
complete_cst,
textobj.get (),
wordobj.get (), NULL));
gdbpy_ref<> resultobj (PyObject_CallMethodObjArgs ((PyObject *) obj,
complete_cst,
textobj.get (),
wordobj.get (), NULL));
if (resultobj == NULL)
{
/* Just swallow errors here. */
@ -276,7 +276,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command,
/* Calling our helper to obtain the PyObject of the Python
function. */
gdbpy_ref resultobj (cmdpy_completer_helper (command, text, word));
gdbpy_ref<> resultobj (cmdpy_completer_helper (command, text, word));
/* Check if there was an error. */
if (resultobj == NULL)
@ -317,7 +317,7 @@ cmdpy_completer (struct cmd_list_element *command,
/* Calling our helper to obtain the PyObject of the Python
function. */
gdbpy_ref resultobj (cmdpy_completer_helper (command, text, word));
gdbpy_ref<> resultobj (cmdpy_completer_helper (command, text, word));
/* If the result object of calling the Python function is NULL, it
means that there was an error. In this case, just give up and
@ -342,14 +342,14 @@ cmdpy_completer (struct cmd_list_element *command,
}
else
{
gdbpy_ref iter (PyObject_GetIter (resultobj.get ()));
gdbpy_ref<> iter (PyObject_GetIter (resultobj.get ()));
if (iter == NULL)
return NULL;
while (true)
{
gdbpy_ref elt (PyIter_Next (iter.get ()));
gdbpy_ref<> elt (PyIter_Next (iter.get ()));
if (elt == NULL)
break;
@ -569,7 +569,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
}
if (PyObject_HasAttr (self, gdbpy_doc_cst))
{
gdbpy_ref ds_obj (PyObject_GetAttr (self, gdbpy_doc_cst));
gdbpy_ref<> ds_obj (PyObject_GetAttr (self, gdbpy_doc_cst));
if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
{
@ -756,7 +756,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple (args, "s", &input))
return NULL;
gdbpy_ref py_argv (PyList_New (0));
gdbpy_ref<> py_argv (PyList_New (0));
if (py_argv == NULL)
return NULL;
@ -771,7 +771,7 @@ gdbpy_string_to_argv (PyObject *self, PyObject *args)
for (i = 0; c_argv[i] != NULL; ++i)
{
gdbpy_ref argp (PyString_FromString (c_argv[i]));
gdbpy_ref<> argp (PyString_FromString (c_argv[i]));
if (argp == NULL
|| PyList_Append (py_argv.get (), argp.get ()) < 0)