Ignore:
Timestamp:
03/25/06 16:21:54 (9 years ago)
Author:
xi
Message:

Fix a leak in _syckmodule.c (thanks, jbj)

Change the production status to Stable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pysyck/trunk/tests/test_parser.py

    r23 r123  
    44import _syck 
    55 
    6 import StringIO, gc 
     6import StringIO, gc, sys 
    77 
    88EXAMPLE = """ 
     
    174174""" 
    175175 
     176LEAKS = """ 
     177- mere scalar 
     178- [ sequence, may, leak, too] 
     179- {"it's": mapping, with: many, potential: leaks} 
     180- {sequence: [], mapping: {}} 
     181""" 
     182 
    176183class TestAttributes(unittest.TestCase): 
    177184 
     
    372379        self.assert_(node.value[0] is node.value[1]) 
    373380 
     381class TestLeaks(unittest.TestCase): 
     382 
     383    def testLeaks(self): 
     384        parser = _syck.Parser(LEAKS) 
     385        node = parser.parse() 
     386        dummy = [] 
     387        self.checkLeaks(node, dummy) 
     388 
     389    def checkLeaks(self, node, dummy): 
     390        self.assertEqual(sys.getrefcount(node), sys.getrefcount(dummy)) 
     391        self.assertEqual(sys.getrefcount(node.value), 2) 
     392        dummy = [] 
     393        container = [dummy] 
     394        if isinstance(node, _syck.Seq): 
     395            for item in node.value: 
     396                self.checkLeaks(item, dummy) 
     397        elif isinstance(node, _syck.Map): 
     398            for key in node.value: 
     399                self.checkLeaks(key, dummy) 
     400                value = node.value[key] 
     401                self.checkLeaks(value, dummy) 
     402 
Note: See TracChangeset for help on using the changeset viewer.