[pypy-commit] pypy stm-gc: Enum, with a callback.
arigo
noreply at buildbot.pypy.org
Sat Feb 4 20:46:59 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52097:5d548e00c813
Date: 2012-02-04 18:48 +0100
http://bitbucket.org/pypy/pypy/changeset/5d548e00c813/
Log: Enum, with a callback.
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -878,4 +878,15 @@
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 */
diff --git a/pypy/translator/stm/src_stm/et.h b/pypy/translator/stm/src_stm/et.h
--- a/pypy/translator/stm/src_stm/et.h
+++ b/pypy/translator/stm/src_stm/et.h
@@ -18,6 +18,7 @@
void *stm_tldict_lookup(void *);
void stm_tldict_add(void *, void *);
+void stm_tlidct_enum(void(*)(void*, void*));
diff --git a/pypy/translator/stm/stmgcintf.py b/pypy/translator/stm/stmgcintf.py
--- a/pypy/translator/stm/stmgcintf.py
+++ b/pypy/translator/stm/stmgcintf.py
@@ -5,6 +5,8 @@
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):
@@ -19,14 +21,7 @@
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],
diff --git a/pypy/translator/stm/test/test_stmgcintf.py b/pypy/translator/stm/test/test_stmgcintf.py
--- a/pypy/translator/stm/test/test_stmgcintf.py
+++ b/pypy/translator/stm/test/test_stmgcintf.py
@@ -1,6 +1,7 @@
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()
@@ -62,3 +63,16 @@
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 == []
More information about the pypy-commit
mailing list