Take first Cython step into function before reading variable in test
authorMark Florisson <markflorisson88@gmail.com>
Tue, 28 Dec 2010 21:02:35 +0000 (22:02 +0100)
committerMark Florisson <markflorisson88@gmail.com>
Tue, 28 Dec 2010 21:02:35 +0000 (22:02 +0100)
1  2 
Cython/Compiler/ParseTreeTransforms.py
Cython/Debugger/Tests/codefile
Cython/Debugger/Tests/test_libcython_in_gdb.py

index ce9d53fd8070f909f174786172023335fe1216db,b982fc08fa7f5ff67bf761878391c3a2f44acc8f..59c9a2cd0ce8104b385247cf727b7016e891ef05
@@@ -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
index 6bbae82b97b53e110a960e9c5ca5db46d0b4c359,95279818dd6c1284c15b2a85b92120809222df35..4a251e898df5a46b95379fca2f5aece3ec51d305
@@@ -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!"
index 6af4183dc119791a508713afda3fb013c2d8751d,b68d36c746385bc3acdb8428473dbf9f9272c401..8fe1cb6e37b13e840f281dcdc9f5c8bb4883198a
@@@ -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: