Fix Py_DECREF being executed without holding the GIL
[binutils-gdb.git] / gdb / python / py-xmethods.c
index c3ca75a644b1570578f13c3429730ee21242e1d9..6505d066e745a87e2e704eb1aaa862b6a7f5c772 100644 (file)
@@ -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)