[pypy-svn] r22631 - in pypy/dist/pypy/rpython/lltypesystem: . test

mwh at codespeak.net mwh at codespeak.net
Wed Jan 25 11:15:08 CET 2006


Author: mwh
Date: Wed Jan 25 11:15:05 2006
New Revision: 22631

Modified:
   pypy/dist/pypy/rpython/lltypesystem/llmemory.py
   pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
Log:
small fixes and tests to llmemory.


Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py	Wed Jan 25 11:15:05 2006
@@ -17,6 +17,8 @@
         return lltype.Signed
 
     def __add__(self, other):
+        if not isinstance(other, AddressOffset):
+            return NotImplemented
         return CompositeOffset(self, other)
 
 
@@ -93,9 +95,9 @@
         assert not TYPE._is_varsize()
         return ItemOffset(TYPE)
     else:
-        if isinstance(TYPE, Array):
+        if isinstance(TYPE, lltype.Array):
             return itemoffsetof(TYPE, n)
-        elif isinstance(TYPE, Struct):
+        elif isinstance(TYPE, lltype.Struct):
             return FieldOffset(TYPE, TYPE._arrayfld) + \
                    itemoffsetof(TYPE._flds[TYPE._arrayfld], n)
         else:

Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py	Wed Jan 25 11:15:05 2006
@@ -1,4 +1,6 @@
 from pypy.rpython.lltypesystem.llmemory import *
+from pypy.rpython.lltypesystem import lltype
+import py
 
 def test_simple():
     class C:
@@ -33,3 +35,20 @@
     b.set(14)
     assert x[3] == 14
     
+def test_dont_mix_offsets_and_ints():
+    o = AddressOffset()
+    py.test.raises(TypeError, "1 + o")
+    py.test.raises(TypeError, "o + 1")
+    
+def test_sizeof():
+    # this is mostly an "assert not raises" sort of test
+    array = lltype.Array(lltype.Signed)
+    struct = lltype.Struct("S", ('x', lltype.Signed))
+    varstruct = lltype.Struct("S", ('x', lltype.Signed), ('y', array))
+    sizeof(struct)
+    sizeof(lltype.Signed)
+    py.test.raises(AssertionError, "sizeof(array)")
+    py.test.raises(AssertionError, "sizeof(varstruct)")
+    sizeof(array, 1)
+    sizeof(varstruct, 2)
+    



More information about the Pypy-commit mailing list