Author: Armin Rigo <[email protected]>
Branch: stmgc-c8
Changeset: r80929:cd51c596c3f9
Date: 2015-11-25 09:36 +0100
http://bitbucket.org/pypy/pypy/changeset/cd51c596c3f9/
Log: Test (and fix in the untranslated emulation) for hashtable iteration
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -432,7 +432,10 @@
self.iterator = iterator
def next(self):
- return next(self.iterator)
+ while 1:
+ entry = next(self.iterator)
+ if entry._obj:
+ return entry
# ____________________________________________________________
diff --git a/rpython/translator/stm/test/test_ztranslated.py
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -769,3 +769,33 @@
t, cbuilder = self.compile(main)
data = cbuilder.cmdexec('')
assert 'ok!\n' in data
+
+ def test_hashtable(self):
+ # minimal test
+ FOO = lltype.GcStruct('FOO')
+
+ def main(argv):
+ h = rstm.create_hashtable()
+ assert h.list()[1] == 0
+ foo = lltype.malloc(FOO)
+ h.set(123, lltype.cast_opaque_ptr(llmemory.GCREF, foo))
+ assert h.list()[1] == 1
+ assert h.get(123) == lltype.cast_opaque_ptr(llmemory.GCREF, foo)
+ assert h.get(234) == lltype.nullptr(llmemory.GCREF.TO)
+ hiter = h.iterentries()
+ entry = hiter.next()
+ try:
+ hiter.next()
+ except StopIteration:
+ pass
+ else:
+ print "hiter.next() should return only once here"
+ assert 0
+ assert entry.index == 123
+ print "ok!"
+ return 0
+
+ main([])
+ t, cbuilder = self.compile(main)
+ data = cbuilder.cmdexec('')
+ assert 'ok!\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit