This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] Acquire GIL when necessary for convenience functions.


Hi,

This patch fixes a crash when trying to invoke a python-defined
convenience function. The problem was that the GIL wasn't being
acquired.
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


2008-11-22  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* python/python-function.c (fnpy_call, fnpy_destroy): Acquire GIL.

diff --git a/gdb/python/python-function.c b/gdb/python/python-function.c
index 8bff712..840c17e 100644
--- a/gdb/python/python-function.c
+++ b/gdb/python/python-function.c
@@ -59,6 +59,11 @@ fnpy_call (void *cookie, int argc, struct value **argv)
   struct value *value = NULL;
   PyObject *result, *callable, *args;
   volatile struct gdb_exception except;
+  struct cleanup *cleanup;
+  PyGILState_STATE state;
+
+  state = PyGILState_Ensure ();
+  cleanup = make_cleanup_py_restore_gil (&state);
 
   args = convert_values_to_python (argc, argv);
 
@@ -74,7 +79,10 @@ fnpy_call (void *cookie, int argc, struct value **argv)
   Py_DECREF (args);
 
   if (!result)
-    return NULL;
+    {
+      gdbpy_print_stack ();
+      error(_("Error while executing Python code."));
+    }
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
@@ -88,6 +96,7 @@ fnpy_call (void *cookie, int argc, struct value **argv)
     }
 
   Py_DECREF (result);
+  do_cleanups (cleanup);
   
   return value;
 }
@@ -97,7 +106,12 @@ fnpy_call (void *cookie, int argc, struct value **argv)
 static void
 fnpy_destroy (void *cookie)
 {
+  PyGILState_STATE state;
+
+  state = PyGILState_Ensure ();
   Py_DECREF ((PyObject *) cookie);
+  PyGILState_Release (state);
+
 }
 
 /* Initializer for a Function object.  It takes one argument, the name
-- 
1.5.6.5



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]