From: Mark Florisson Date: Tue, 28 Dec 2010 21:02:35 +0000 (+0100) Subject: Take first Cython step into function before reading variable in test X-Git-Tag: 0.14.1rc0~12^2~5 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=76567d05e320a3fb6c0ba89edcabed93f6bc4416;p=cython.git Take first Cython step into function before reading variable in test --- 76567d05e320a3fb6c0ba89edcabed93f6bc4416 diff --cc Cython/Compiler/ParseTreeTransforms.py index ce9d53fd,b982fc08..59c9a2cd --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@@ -1609,17 -1610,9 +1609,16 @@@ class DebugTransform(CythonTransform) # serialize functions self.tb.start('Functions') + # First, serialize functions normally... self.visitchildren(node) + + # ... then, serialize nested functions for nested_funcdef in self.nested_funcdefs: self.visit_FuncDefNode(nested_funcdef) + + self.register_stepinto = True + self.serialize_modulenode_as_function(node) + self.register_stepinto = False - self.tb.end('Functions') # 2.3 compatibility. Serialize global variables diff --cc Cython/Debugger/Tests/codefile index 6bbae82b,95279818..4a251e89 --- a/Cython/Debugger/Tests/codefile +++ b/Cython/Debugger/Tests/codefile @@@ -36,19 -36,7 +36,19 @@@ def closure() a = 1 def inner(): b = 2 + # access closed over variables + print a, b return inner +def closure_without_closing_variables(): + a = 1 + def inner2(): + b = 2 + print b + return inner2 + +closure()() +closure_without_closing_variables()() + spam() --print "bye!" ++print "bye!" diff --cc Cython/Debugger/Tests/test_libcython_in_gdb.py index 6af4183d,b68d36c7..8fe1cb6e --- a/Cython/Debugger/Tests/test_libcython_in_gdb.py +++ b/Cython/Debugger/Tests/test_libcython_in_gdb.py @@@ -351,19 -341,6 +351,22 @@@ class TestExec(DebugTestCase) gdb.execute('cy exec some_random_var = 14') self.assertEqual('14', self.eval_command('some_random_var')) +class TestClosure(DebugTestCase): + + def test_cython_closure(self): + self.break_and_run('def inner():') + ++ # Allow the Cython-generated code to initialize the scope variable ++ gdb.execute('cy step') ++ + self.assertEqual(str(self.read_var('a')), '1') + print_result = gdb.execute('cy print a', to_string=True).strip() + self.assertEqual(print_result, 'a = 1') + + def test_cython_closure_no_closing_variables(self): + self.break_and_run('def inner2():') + self.assertEqual(gdb.execute('cy locals', to_string=True), '') + _do_debug = os.environ.get('GDB_DEBUG') if _do_debug: