[pypy-svn] r45716 - in pypy/branch/pypy-more-rtti-inprogress/rpython/tool: . test

fijal at codespeak.net fijal at codespeak.net
Thu Aug 16 14:06:46 CEST 2007


Author: fijal
Date: Thu Aug 16 14:06:45 2007
New Revision: 45716

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rffi_platform.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rffi_platform.py
Log:
Most of tests are passing, although there are still some cases where
there are xxxs and so on.


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rffi_platform.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rffi_platform.py	Thu Aug 16 14:06:45 2007
@@ -384,6 +384,11 @@
 
 float_class = [rffi.DOUBLE]
 
+def _sizeof(tp):
+    if isinstance(tp, lltype.Struct):
+        return sum([_sizeof(i) for i in tp._flds.values()])
+    return rffi.sizeof(tp)
+
 class Field(object):
     def __init__(self, name, ctype):
         self.name = name
@@ -392,7 +397,7 @@
         return '<field %s: %s>' % (self.name, self.ctype)
 
 def layout_addfield(layout, offset, ctype, prefix):
-    size = rffi.sizeof(ctype)
+    size = _sizeof(ctype)
     name = prefix
     i = 0
     while name in layout:

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rffi_platform.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rffi_platform.py	Thu Aug 16 14:06:45 2007
@@ -81,34 +81,30 @@
     assert fields["c_d"] == rffi.DOUBLE
 
 def test_simple_type():
-    py.test.skip("Next to go")
-    ctype = ctypes_platform.getsimpletype('test_t',
-                                          'typedef unsigned short test_t;',
-                                          ctypes.c_int)
-    assert ctype == ctypes.c_ushort
+    ctype = rffi_platform.getsimpletype('test_t',
+                                        'typedef unsigned short test_t;',
+                                        rffi.INT)
+    assert ctype == rffi.USHORT
 
 def test_constant_integer():
-    py.test.skip("Next to go")
-    value = ctypes_platform.getconstantinteger('BLAH',
+    value = rffi_platform.getconstantinteger('BLAH',
                                                '#define BLAH (6*7)')
     assert value == 42
-    value = ctypes_platform.getconstantinteger('BLAH',
+    value = rffi_platform.getconstantinteger('BLAH',
                                                '#define BLAH (-2147483648LL)')
     assert value == -2147483648
-    value = ctypes_platform.getconstantinteger('BLAH',
+    value = rffi_platform.getconstantinteger('BLAH',
                                                '#define BLAH (3333333333ULL)')
     assert value == 3333333333
 
 def test_defined():
-    py.test.skip("Next to go")
-    res = ctypes_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE', '')
+    res = rffi_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE', '')
     assert not res
-    res = ctypes_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE',
+    res = rffi_platform.getdefined('ALFKJLKJFLKJFKLEJDLKEWMECEE',
                                      '#define ALFKJLKJFLKJFKLEJDLKEWMECEE')
     assert res
 
 def test_configure():
-    py.test.skip("Next to go")
     test_h = udir.join('test_ctypes_platform.h')
     test_h.write('#define XYZZY 42\n')
 
@@ -119,18 +115,17 @@
                    """
         _include_dirs_ = [str(udir)]
 
-        FILE = ctypes_platform.Struct('FILE', [])
-        ushort = ctypes_platform.SimpleType('unsigned short')
-        XYZZY = ctypes_platform.ConstantInteger('XYZZY')
+        FILE = rffi_platform.Struct('FILE', [])
+        ushort = rffi_platform.SimpleType('unsigned short')
+        XYZZY = rffi_platform.ConstantInteger('XYZZY')
 
-    res = ctypes_platform.configure(CConfig)
-    assert issubclass(res['FILE'], ctypes.Structure)
+    res = rffi_platform.configure(CConfig)
+    assert isinstance(res['FILE'], lltype.Struct)
     assert res == {'FILE': res['FILE'],
-                   'ushort': ctypes.c_ushort,
+                   'ushort': rffi.USHORT,
                    'XYZZY': 42}
 
 def test_ifdef():
-    py.test.skip("Next to go")
     class CConfig:
         _header_ = """ /* a C comment */
 #define XYZZY 42
@@ -141,22 +136,21 @@
 };
 """
 
-        s = ctypes_platform.Struct('struct s', [('i', ctypes.c_int)],
+        s = rffi_platform.Struct('struct s', [('i', rffi.INT)],
                                    ifdef='XYZZY')
-        z = ctypes_platform.Struct('struct z', [('i', ctypes.c_int)],
+        z = rffi_platform.Struct('struct z', [('i', rffi.INT)],
                                    ifdef='FOOBAR')
 
-        foo = ctypes_platform.SimpleType('foo', ifdef='XYZZY')
-        bar = ctypes_platform.SimpleType('bar', ifdef='FOOBAR')
+        foo = rffi_platform.SimpleType('foo', ifdef='XYZZY')
+        bar = rffi_platform.SimpleType('bar', ifdef='FOOBAR')
 
-    res = ctypes_platform.configure(CConfig)
+    res = rffi_platform.configure(CConfig)
     assert res['s'] is not None
     assert res['z'] is None
     assert res['foo'] is not None
     assert res['bar'] is None
 
 def test_nested_structs():
-    py.test.skip("Next to go")
     class CConfig:
         _header_ = """
 struct x {
@@ -168,20 +162,20 @@
     struct x x;
     };
 """
-        x = ctypes_platform.Struct("struct x", [("bar", ctypes.c_short)])
-        y = ctypes_platform.Struct("struct y", [("x", x)])
+        x = rffi_platform.Struct("struct x", [("bar", rffi.SHORT)])
+        y = rffi_platform.Struct("struct y", [("x", x)])
 
-    res = ctypes_platform.configure(CConfig)
+    res = rffi_platform.configure(CConfig)
     c_x = res["x"]
     c_y = res["y"]
-    c_y_fields = dict(c_y._fields_)
-    assert issubclass(c_x , ctypes.Structure)
-    assert issubclass(c_y, ctypes.Structure)
-    assert c_y_fields["x"] is c_x
+    c_y_fields = dict(c_y._flds)
+    assert isinstance(c_x , lltype.Struct)
+    assert isinstance(c_y, lltype.Struct)
+    assert c_y_fields["c_x"] is c_x
 
 def test_array():
     py.test.skip("Next to go")
-    dirent = ctypes_platform.getstruct("struct dirent",
+    dirent = rffi_platform.getstruct("struct dirent",
                                        """
            struct dirent  /* for this example only, not the exact dirent */
            {
@@ -191,5 +185,5 @@
                char d_name[32];
            };
                                        """,
-                                       [("d_name", ctypes.c_char * 0)])
+                                       [("d_name", rffi.CArray(rffi.CHAR).TO)])
     assert dirent.d_name.size == 32



More information about the Pypy-commit mailing list