diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6311d91a0b..6bd0a23258 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2017-01-20 Simon Marchi + + * python/py-function.c (fnpy_call): Reorder declarations to have + the gdbpy_enter object declared first. + * python/py-xmethods.c (gdbpy_get_xmethod_arg_types): Likewise. + 2017-01-20 Simon Marchi PR python/21068 diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index 13c7a11485..6762a6d56e 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -59,14 +59,13 @@ static struct value * fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language, void *cookie, int argc, struct value **argv) { - struct value *value = NULL; - /* 'result' must be set to NULL, this initially indicates whether - the function was called, or not. */ - gdbpy_ref result; - + /* The gdbpy_enter object needs to be placed first, so that it's the last to + be destroyed. */ gdbpy_enter enter_py (gdbarch, language); - + struct value *value; + gdbpy_ref result; gdbpy_ref args (convert_values_to_python (argc, argv)); + /* convert_values_to_python can return NULL on error. If we encounter this, do not call the function, but allow the Python -> error code conversion below to deal with the Python exception. diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index c3ca75a644..6505d066e7 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -308,6 +308,9 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang, struct xmethod_worker *worker, int *nargs, struct type ***arg_types) { + /* The gdbpy_enter object needs to be placed first, so that it's the last to + be destroyed. */ + gdbpy_enter enter_py (get_current_arch (), current_language); struct gdbpy_worker_data *worker_data = (struct gdbpy_worker_data *) worker->data; PyObject *py_worker = worker_data->worker; @@ -319,8 +322,6 @@ gdbpy_get_xmethod_arg_types (const struct extension_language_defn *extlang, an invalid/unusable number of arg types. */ *nargs = -1; - gdbpy_enter enter_py (get_current_arch (), current_language); - gdbpy_ref get_arg_types_method (PyObject_GetAttrString (py_worker, get_arg_types_method_name)); if (get_arg_types_method == NULL)