Use gdbpy_enter in cmdpy_function
This changes cmdpy_function to use gdbpy_enter and gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-cmd.c (cmdpy_function): Use gdbpy_enter, gdbpy_ref.
This commit is contained in:
parent
788f258604
commit
12a5cedd4f
2 changed files with 14 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* python/py-cmd.c (cmdpy_function): Use gdbpy_enter, gdbpy_ref.
|
||||||
|
|
||||||
2017-01-10 Tom Tromey <tom@tromey.com>
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* python/py-varobj.c (py_varobj_iter_dtor, py_varobj_iter_next):
|
* python/py-varobj.c (py_varobj_iter_dtor, py_varobj_iter_next):
|
||||||
|
|
|
@ -117,10 +117,8 @@ static void
|
||||||
cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
||||||
{
|
{
|
||||||
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
|
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
|
||||||
PyObject *argobj, *ttyobj, *result;
|
|
||||||
struct cleanup *cleanup;
|
|
||||||
|
|
||||||
cleanup = ensure_python_env (get_current_arch (), current_language);
|
gdbpy_enter enter_py (get_current_arch (), current_language);
|
||||||
|
|
||||||
if (! obj)
|
if (! obj)
|
||||||
error (_("Invalid invocation of Python command object."));
|
error (_("Invalid invocation of Python command object."));
|
||||||
|
@ -129,7 +127,6 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
||||||
if (obj->command->prefixname)
|
if (obj->command->prefixname)
|
||||||
{
|
{
|
||||||
/* A prefix command does not need an invoke method. */
|
/* A prefix command does not need an invoke method. */
|
||||||
do_cleanups (cleanup);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error (_("Python command object missing 'invoke' method."));
|
error (_("Python command object missing 'invoke' method."));
|
||||||
|
@ -137,21 +134,21 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
||||||
|
|
||||||
if (! args)
|
if (! args)
|
||||||
args = "";
|
args = "";
|
||||||
argobj = PyUnicode_Decode (args, strlen (args), host_charset (), NULL);
|
gdbpy_ref argobj (PyUnicode_Decode (args, strlen (args), host_charset (),
|
||||||
if (! argobj)
|
NULL));
|
||||||
|
if (argobj == NULL)
|
||||||
{
|
{
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
error (_("Could not convert arguments to Python string."));
|
error (_("Could not convert arguments to Python string."));
|
||||||
}
|
}
|
||||||
|
|
||||||
ttyobj = from_tty ? Py_True : Py_False;
|
gdbpy_ref ttyobj (from_tty ? Py_True : Py_False);
|
||||||
Py_INCREF (ttyobj);
|
Py_INCREF (ttyobj.get ());
|
||||||
result = PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst, argobj,
|
gdbpy_ref result (PyObject_CallMethodObjArgs ((PyObject *) obj, invoke_cst,
|
||||||
ttyobj, NULL);
|
argobj.get (), ttyobj.get (),
|
||||||
Py_DECREF (argobj);
|
NULL));
|
||||||
Py_DECREF (ttyobj);
|
|
||||||
|
|
||||||
if (! result)
|
if (result == NULL)
|
||||||
{
|
{
|
||||||
PyObject *ptype, *pvalue, *ptraceback;
|
PyObject *ptype, *pvalue, *ptraceback;
|
||||||
|
|
||||||
|
@ -199,9 +196,6 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty)
|
||||||
error ("%s", msg.get ());
|
error ("%s", msg.get ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF (result);
|
|
||||||
do_cleanups (cleanup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for the Python command completers (both "pure"
|
/* Helper function for the Python command completers (both "pure"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue