Esempio n. 1
0
    def test_foreach(self):
        AddressDeque = get_address_deque(10)
        ll = AddressDeque()
        for num_entries in range(30, -1, -1):
            addrs = [
                raw_malloc(llmemory.sizeof(lltype.Signed))
                for i in range(num_entries)
            ]
            for a in addrs:
                ll.append(a)

            seen = []

            def callback(addr, fortytwo):
                assert fortytwo == 42
                seen.append(addr)

            ll.foreach(callback, 42)
            assert seen == addrs
            seen = []
            ll.foreach(callback, 42, step=2)
            assert seen == addrs[::2]

            for a in addrs:
                b = ll.popleft()
                assert a == b
            assert not ll.non_empty()
Esempio n. 2
0
 def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE, translated_to_c=True):
     self.gcheaderbuilder = GCHeaderBuilder(self.HDR)
     self.AddressStack = get_address_stack(chunk_size)
     self.AddressDeque = get_address_deque(chunk_size)
     self.AddressDict = AddressDict
     self.null_address_dict = null_address_dict
     self.config = config
     assert isinstance(translated_to_c, bool)
     self.translated_to_c = translated_to_c
Esempio n. 3
0
 def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
              translated_to_c=True):
     self.gcheaderbuilder = GCHeaderBuilder(self.HDR)
     self.AddressStack = get_address_stack(chunk_size)
     self.AddressDeque = get_address_deque(chunk_size)
     self.AddressDict = AddressDict
     self.null_address_dict = null_address_dict
     self.config = config
     assert isinstance(translated_to_c, bool)
     self.translated_to_c = translated_to_c
Esempio n. 4
0
File: base.py Progetto: Mu-L/pypy
 def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
              translated_to_c=True, hooks=None):
     self.gcheaderbuilder = GCHeaderBuilder(self.HDR)
     self.AddressStack = get_address_stack(chunk_size)
     self.AddressDeque = get_address_deque(chunk_size)
     self.AddressDict = AddressDict
     self.null_address_dict = null_address_dict
     self.config = config
     assert isinstance(translated_to_c, bool)
     self.translated_to_c = translated_to_c
     if hooks is None:
         hooks = GcHooks() # the default hooks are empty
     self.hooks = hooks
Esempio n. 5
0
 def test_big_access(self):
     import random
     AddressDeque = get_address_deque(10)
     deque = AddressDeque()
     expected = []
     for i in range(3000):
         assert deque.non_empty() == (len(expected) > 0)
         r = random.random()
         if r < 0.51 and expected:
             x = deque.popleft()
             y = expected.pop(0)
             assert x == y
         else:
             x = raw_malloc(llmemory.sizeof(lltype.Signed))
             deque.append(x)
             expected.append(x)
Esempio n. 6
0
 def test_big_access(self):
     import random
     AddressDeque = get_address_deque(10)
     deque = AddressDeque()
     expected = []
     for i in range(3000):
         assert deque.non_empty() == (len(expected) > 0)
         r = random.random()
         if r < 0.51 and expected:
             x = deque.popleft()
             y = expected.pop(0)
             assert x == y
         else:
             x = raw_malloc(llmemory.sizeof(lltype.Signed))
             deque.append(x)
             expected.append(x)
Esempio n. 7
0
    def test_foreach(self):
        AddressDeque = get_address_deque(10)
        ll = AddressDeque()
        for num_entries in range(30, -1, -1):
            addrs = [raw_malloc(llmemory.sizeof(lltype.Signed))
                     for i in range(num_entries)]
            for a in addrs:
                ll.append(a)

            seen = []
            def callback(addr, fortytwo):
                assert fortytwo == 42
                seen.append(addr)

            ll.foreach(callback, 42)
            assert seen == addrs
            for a in addrs:
                b = ll.popleft()
                assert a == b
            assert not ll.non_empty()