Fetch and restore error for Cython locals dict building
authorMark Florisson <markflorisson88@gmail.com>
Wed, 8 Dec 2010 00:18:13 +0000 (01:18 +0100)
committerMark Florisson <markflorisson88@gmail.com>
Wed, 8 Dec 2010 00:18:13 +0000 (01:18 +0100)
Cython/Debugger/libcython.py

index 8c49bdd84b38f067336384f5cb86bc8f4340bc2a..54d09b3f8765cf63aa6ff70f43f129ffe109856e 100644 (file)
@@ -1200,19 +1200,21 @@ class CyExec(CythonCommand, libpython.PyExec):
         expr, input_type = self.readcode(expr)
         executor = libpython.PythonCodeExecutor()
         
-        # get the dict of Cython globals and construct a dict in the inferior
-        # with Cython locals
-        global_dict = gdb.parse_and_eval(
-            '(PyObject *) PyModule_GetDict(__pyx_m)')
-        local_dict = gdb.parse_and_eval('(PyObject *) PyDict_New()')
-        
-        cython_function = self.get_cython_function()
-        
-        try:
-            self._fill_locals_dict(executor, libpython.pointervalue(local_dict))
-            executor.evalcode(expr, input_type, global_dict, local_dict)
-        finally:
-            executor.decref(libpython.pointervalue(local_dict))
+        with libpython.FetchAndRestoreError():
+            # get the dict of Cython globals and construct a dict in the 
+            # inferior with Cython locals
+            global_dict = gdb.parse_and_eval(
+                '(PyObject *) PyModule_GetDict(__pyx_m)')
+            local_dict = gdb.parse_and_eval('(PyObject *) PyDict_New()')
+            
+            cython_function = self.get_cython_function()
+            
+            try:
+                self._fill_locals_dict(executor, 
+                                       libpython.pointervalue(local_dict))
+                executor.evalcode(expr, input_type, global_dict, local_dict)
+            finally:
+                executor.decref(libpython.pointervalue(local_dict))
 
 
 # Functions