Commits

Armin Rigo committed 5d548e0

Enum, with a callback.

  • Participants
  • Parent commits 92d4a43
  • Branches stm-gc

Comments (0)

Files changed (4)

File pypy/translator/stm/src_stm/et.c

   redolog_insert(&d->redolog, key, value);
 }
 
+void stm_tldict_enum(void(*callback)(void*, void*))
+{
+  struct tx_descriptor *d = thread_descriptor;
+  wlog_t *item;
+
+  REDOLOG_LOOP_FORWARD(d->redolog, item)
+    {
+      callback(item->addr, item->val);
+    } REDOLOG_LOOP_END;
+}
+
 #endif  /* PYPY_NOT_MAIN_FILE */

File pypy/translator/stm/src_stm/et.h

 
 void *stm_tldict_lookup(void *);
 void stm_tldict_add(void *, void *);
+void stm_tlidct_enum(void(*)(void*, void*));
 
 
 

File pypy/translator/stm/stmgcintf.py

 def smexternal(name, args, result):
     return staticmethod(_rffi_stm.llexternal(name, args, result))
 
+CALLBACK = lltype.Ptr(lltype.FuncType([llmemory.Address] * 2, lltype.Void))
+
 
 class StmOperations(object):
 
                                llmemory.Address)
     tldict_add = smexternal('stm_tldict_add', [llmemory.Address] * 2,
                             lltype.Void)
-
-    enum_tldict_start = smexternal('stm_enum_tldict_start', [], lltype.Void)
-    enum_tldict_find_next = smexternal('stm_enum_tldict_find_next', [],
-                                       lltype.Signed)
-    enum_tldict_globalobj = smexternal('stm_enum_tldict_globalobj', [],
-                                       llmemory.Address)
-    enum_tldict_localobj  = smexternal('stm_enum_tldict_localobj', [],
-                                       llmemory.Address)
+    tldict_enum = smexternal('stm_tldict_enum', [CALLBACK], lltype.Void)
 
     stm_read_word = smexternal('stm_read_word',
                                [llmemory.Address, lltype.Signed],

File pypy/translator/stm/test/test_stmgcintf.py

 import random
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
-from pypy.translator.stm.stmgcintf import StmOperations
+from pypy.rpython.annlowlevel import llhelper
+from pypy.translator.stm.stmgcintf import StmOperations, CALLBACK
 
 stm_operations = StmOperations()
 
                 a2 = rffi.cast(llmemory.Address, random.randrange(2000, 9999))
                 stm_operations.tldict_add(a1, a2)
                 content[key] = a2
+        return content
+
+    def get_callback(self):
+        def callback(key, value):
+            seen.append((key, value))
+        seen = []
+        p_callback = llhelper(CALLBACK, callback)
+        return p_callback, seen
+
+    def test_enum_tldict_empty(self):
+        p_callback, seen = self.get_callback()
+        stm_operations.tldict_enum(p_callback)
+        assert seen == []