[pypy-svn] r76835 - in pypy/branch/no-_immutable_/pypy/rpython/lltypesystem: . test

arigo at codespeak.net arigo at codespeak.net
Thu Sep 2 14:59:33 CEST 2010


Author: arigo
Date: Thu Sep  2 14:59:29 2010
New Revision: 76835

Modified:
   pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lltype.py
Log:
Create an interface to immutable / immutable_fields.


Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/lltype.py	Thu Sep  2 14:59:29 2010
@@ -297,6 +297,15 @@
             n = 1
         return _struct(self, n, initialization='example')
 
+    def _immutable_field(self, field):
+        if 'immutable_fields' in self._hints:
+            try:
+                s = self._hints['immutable_fields'].fields[field]
+                return s or True
+            except KeyError:
+                pass
+        return self._hints.get('immutable', False)
+
 class RttiStruct(Struct):
     _runtime_type_info = None
 

Modified: pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/branch/no-_immutable_/pypy/rpython/lltypesystem/test/test_lltype.py	Thu Sep  2 14:59:29 2010
@@ -781,6 +781,28 @@
     p = cast_opaque_ptr(llmemory.GCREF, a)
     assert hash1 == identityhash(p)
 
+def test_immutable_hint():
+    S = GcStruct('S', ('x', lltype.Signed))
+    assert S._immutable_field('x') == False
+    #
+    S = GcStruct('S', ('x', lltype.Signed), hints={'immutable': True})
+    assert S._immutable_field('x') == True
+    #
+    class FieldListAccessor(object):
+        def __init__(self, fields):
+            self.fields = fields
+    S = GcStruct('S', ('x', lltype.Signed),
+                 hints={'immutable_fields': FieldListAccessor({'x':''})})
+    assert S._immutable_field('x') == True
+    #
+    class FieldListAccessor(object):
+        def __init__(self, fields):
+            self.fields = fields
+    S = GcStruct('S', ('x', lltype.Signed),
+                 hints={'immutable_fields': FieldListAccessor({'x':'[*]'})})
+    assert S._immutable_field('x') == '[*]'
+
+
 class TestTrackAllocation:
     def setup_method(self, func):
         start_tracking_allocations()



More information about the Pypy-commit mailing list