[pypy-commit] pypy stmgc-c8-hashtable: hg merge stmgc-c7

arigo noreply at buildbot.pypy.org
Mon Mar 16 16:29:49 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c8-hashtable
Changeset: r76407:8afb97abf085
Date: 2015-03-16 16:29 +0100
http://bitbucket.org/pypy/pypy/changeset/8afb97abf085/

Log:	hg merge stmgc-c7

diff --git a/lib_pypy/pypy_test/test_transaction.py b/lib_pypy/pypy_test/test_transaction.py
--- a/lib_pypy/pypy_test/test_transaction.py
+++ b/lib_pypy/pypy_test/test_transaction.py
@@ -192,6 +192,39 @@
     assert d.setdefault(key2) is None
     assert d[key2] is None
 
+def test_stmdict():
+    d = transaction.stmdict()
+    d["abc"] = "def"
+    assert list(d.iterkeys()) == ["abc"]
+
+def test_stmset():
+    d = transaction.stmset()
+    d.add("abc")
+    assert list(d) == ["abc"]
+
+def test_time_clock():
+    assert isinstance(transaction.time(), float)
+    assert isinstance(transaction.clock(), float)
+
+def test_threadlocalproperty():
+    class Foo(object):
+        x = transaction.threadlocalproperty()
+        y = transaction.threadlocalproperty(dict)
+    foo = Foo()
+    py.test.raises(AttributeError, "foo.x")
+    d = foo.y
+    assert d == {}
+    assert d is foo.y
+    foo.y['bar'] = 'baz'
+    foo.x = 42
+    foo.y = 43
+    assert foo.x == 42
+    assert foo.y == 43
+    del foo.x
+    del foo.y
+    py.test.raises(AttributeError, "foo.x")
+    assert foo.y == {}
+
 
 def run_tests():
     for name in sorted(globals().keys()):
diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -37,24 +37,19 @@
     signals_enabled = _SignalsEnabled()
 
 try:
-    from pypystm import hint_commit_soon
+    from pypystm import hint_commit_soon, getsegmentlimit
+    from pypystm import hashtable, stmset, stmdict
+    from pypystm import local, time, clock
 except ImportError:
     # Not a STM-enabled PyPy.
     def hint_commit_soon():
         return None
-
-try:
-    from pypystm import getsegmentlimit
-except ImportError:
-    # Not a STM-enabled PyPy.
     def getsegmentlimit():
         return 1
-
-try:
-    from pypystm import hashtable
-except ImportError:
-    # Not a STM-enabled PyPy.
     hashtable = dict
+    stmset = set
+    stmdict = dict
+    from time import time, clock
 
 class stmidset(object):
     def __init__(self):
@@ -299,9 +294,9 @@
 
 
 class threadlocalproperty(object):
-    def __init__(self, *default):
-        self.tl_default = default
-        self.tl_name = intern(str(id(self)))
+    def __init__(self, default_factory=None):
+        self.tl_default_factory = default_factory
+        self.tl_name = intern('tlprop.%d' % id(self))
 
     def tl_get(self, obj):
         try:
@@ -313,7 +308,14 @@
     def __get__(self, obj, cls=None):
         if obj is None:
             return self
-        return getattr(self.tl_get(obj), self.tl_name, *self.tl_default)
+        try:
+            return getattr(self.tl_get(obj), self.tl_name)
+        except AttributeError:
+            if self.tl_default_factory is None:
+                raise
+            result = self.tl_default_factory()
+            setattr(self.tl_get(obj), self.tl_name, result)
+            return result
 
     def __set__(self, obj, value):
         setattr(self.tl_get(obj), self.tl_name, value)
diff --git a/pypy/module/pypystm/test_pypy_c/test_conflict.py b/pypy/module/pypystm/test_pypy_c/test_with_conflict.py
rename from pypy/module/pypystm/test_pypy_c/test_conflict.py
rename to pypy/module/pypystm/test_pypy_c/test_with_conflict.py
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -248,6 +248,7 @@
 
 _HASHTABLE_OBJ = lltype.GcStruct('HASHTABLE_OBJ',
                                  ('ll_raw_hashtable', _STM_HASHTABLE_P),
+                                 hints={'immutable': True},
                                  rtti=True,
                                  adtmeths={'get': _ll_hashtable_get,
                                            'set': _ll_hashtable_set,
@@ -286,8 +287,7 @@
         p = lltype.malloc(_STM_HASHTABLE_ENTRY)
     else:
         p = lltype.nullptr(_STM_HASHTABLE_ENTRY)
-    h = lltype.malloc(_HASHTABLE_OBJ)
-    h.ll_raw_hashtable = lltype.nullptr(_STM_HASHTABLE_P.TO)
+    h = lltype.malloc(_HASHTABLE_OBJ, zero=True)
     h.ll_raw_hashtable = llop.stm_hashtable_create(_STM_HASHTABLE_P, p)
     return h
 


More information about the pypy-commit mailing list