Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r75619:054d5d592ec4
Date: 2015-02-01 11:10 +0100
http://bitbucket.org/pypy/pypy/changeset/054d5d592ec4/

Log:    _ll_hashtable_len

diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -182,6 +182,7 @@
                                        ('index', lltype.Unsigned),
                                        ('object', llmemory.GCREF))
 _STM_HASHTABLE_ENTRY_P = lltype.Ptr(_STM_HASHTABLE_ENTRY)
+_STM_HASHTABLE_ENTRY_ARRAY = rffi.CArray(_STM_HASHTABLE_ENTRY_P)
 
 @dont_look_inside
 def _ll_hashtable_get(h, key):
@@ -193,6 +194,11 @@
     llop.stm_hashtable_write(lltype.Void, h, h.ll_raw_hashtable, key, value)
 
 @dont_look_inside
+def _ll_hashtable_len(h):
+    return llop.stm_hashtable_list(lltype.Signed, h, h.ll_raw_hashtable,
+                                   lltype.nullptr(_STM_HASHTABLE_ENTRY_ARRAY))
+
+@dont_look_inside
 def _ll_hashtable_lookup(h, key):
     return llop.stm_hashtable_lookup(_STM_HASHTABLE_ENTRY_P,
                                      h, h.ll_raw_hashtable, key)
@@ -202,6 +208,7 @@
                                  rtti=True,
                                  adtmeths={'get': _ll_hashtable_get,
                                            'set': _ll_hashtable_set,
+                                           'len': _ll_hashtable_len,
                                         'lookup': _ll_hashtable_lookup})
 NULL_HASHTABLE = lltype.nullptr(_HASHTABLE_OBJ)
 
@@ -262,6 +269,9 @@
             except KeyError:
                 pass
 
+    def len(self):
+        return len(self._content)
+
     def lookup(self, key):
         assert type(key) is int
         return EntryObjectForTest(self, key)
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -465,6 +465,7 @@
     'stm_hashtable_read':     LLOp(),
     'stm_hashtable_write':    LLOp(),
     'stm_hashtable_lookup':   LLOp(),
+    'stm_hashtable_list'  :   LLOp(),
     'stm_hashtable_tracefn':  LLOp(),
 
     # __________ address operations __________
diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -320,6 +320,14 @@
     return '%s = stm_hashtable_lookup((object_t *)%s, %s, %s);' % (
         result, arg0, arg1, arg2)
 
+def stm_hashtable_list(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    arg1 = funcgen.expr(op.args[1])
+    arg2 = funcgen.expr(op.args[2])
+    result = funcgen.expr(op.result)
+    return '%s = stm_hashtable_list((object_t *)%s, %s, %s);' % (
+        result, arg0, arg1, arg2)
+
 def stm_hashtable_tracefn(funcgen, op):
     arg0 = funcgen.expr(op.args[0])
     arg1 = funcgen.expr(op.args[1])
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
@@ -575,6 +575,14 @@
             x2 = cast_gcref_to_instance(X, p2)
             assert x2 is x1
             #
+            entry = h.lookup(-1234)
+            assert cast_gcref_to_instance(X, entry.object) is x1
+            assert h.len() == 1
+            #
+            entry = h.lookup(4242)
+            assert cast_gcref_to_instance(X, entry.object) is None
+            assert h.len() == 1
+            #
             print "ok!"
             return 0
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to