[pypy-svn] r47604 - in pypy/dist/pypy/rpython/tool: . test

fijal at codespeak.net fijal at codespeak.net
Fri Oct 19 18:53:18 CEST 2007


Author: fijal
Date: Fri Oct 19 18:53:18 2007
New Revision: 47604

Modified:
   pypy/dist/pypy/rpython/tool/rffi_platform.py
   pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
Log:
Implement rffi_platform.SizeOf


Modified: pypy/dist/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/rffi_platform.py	(original)
+++ pypy/dist/pypy/rpython/tool/rffi_platform.py	Fri Oct 19 18:53:18 2007
@@ -42,6 +42,14 @@
         HAS = Has(name)
     return configure(CConfig)['HAS']
 
+def sizeof(name, c_header_source, **kwds):
+    class CConfig:
+        _header_ = c_header_source
+        SIZE = SizeOf(name)
+    for k, v in kwds.items():
+        setattr(CConfig, k, v)
+    return configure(CConfig)['SIZE']
+
 # ____________________________________________________________
 #
 # General interface
@@ -270,6 +278,19 @@
         kwds = {'hints': hints}
         return rffi.CStruct(name, *fields, **kwds)
 
+class SizeOf(CConfigEntry):
+    """An entry in a CConfig class that stands for sizeof
+    of some external opaque type
+    """
+    def __init__(self, name):
+        self.name = name
+
+    def prepare_code(self):
+        yield 'dump("size",  sizeof(%s));' % self.name
+
+    def build_result(self, info, config_result):
+        return info['size']
+
 class SimpleType(CConfigEntry):
     """An entry in a CConfig class that stands for an externally
     defined simple numeric type.

Modified: pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py	(original)
+++ pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py	Fri Oct 19 18:53:18 2007
@@ -191,3 +191,6 @@
     assert not rffi_platform.has("x", "")
     # has() should also not crash if it is given an invalid #include
     assert not rffi_platform.has("x", "#include <some/path/which/cannot/exist>")
+
+def test_sizeof():
+    assert rffi_platform.sizeof("char", "") == 1



More information about the Pypy-commit mailing list