[pypy-svn] r46344 - in pypy/dist/pypy: rpython/lltypesystem translator/c translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed Sep 5 14:50:37 CEST 2007


Author: arigo
Date: Wed Sep  5 14:50:35 2007
New Revision: 46344

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/dist/pypy/translator/c/primitive.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
Log:
A test for prebuilt integers of various types in genc.
The fix is to make it pass even when ctypes is not installed,
and removing a dependency on the rctypes package.


Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py	Wed Sep  5 14:50:35 2007
@@ -107,6 +107,7 @@
 def setup():
     """ creates necessary c-level types
     """
+    result = []
     for name in TYPES:
         c_name = name
         if name.startswith('unsigned'):
@@ -118,8 +119,10 @@
         tp = platform.inttype(name.upper(), c_name, signed)
         globals()['r_' + name] = platform.numbertype_to_rclass[tp]
         globals()[name.upper()] = tp
+        result.append(tp)
+    return result
 
-setup()
+NUMBER_TYPES = setup()
 platform.numbertype_to_rclass[lltype.Signed] = int     # avoid "r_long" for common cases
 # ^^^ this creates at least the following names:
 # --------------------------------------------------------------------

Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py	(original)
+++ pypy/dist/pypy/translator/c/primitive.py	Wed Sep  5 14:50:35 2007
@@ -2,6 +2,7 @@
 from pypy.rlib.objectmodel import Symbolic, ComputedIntSymbolic
 from pypy.rlib.objectmodel import CDefinedIntSymbolic
 from pypy.rpython.lltypesystem.lltype import *
+from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.lltypesystem.llmemory import Address, \
      AddressOffset, ItemOffset, ArrayItemsOffset, FieldOffset, \
      CompositeOffset, ArrayLengthOffset, WeakGcAddress, fakeweakaddress, \
@@ -175,20 +176,14 @@
     PrimitiveType[ll_type] = '%s @'% c_name
     PrimitiveErrorValue[ll_type] = '((%s) -1)'% c_name
     
-try:
-    import ctypes
-except ImportError:
-    pass
-else:
-    from pypy.rpython.rctypes import rcarithmetic as rcarith
-    for ll_type, c_name in [(rcarith.CByte, 'signed char'),
-                            (rcarith.CUByte, 'unsigned char'),
-                            (rcarith.CShort, 'short'),
-                            (rcarith.CUShort, 'unsigned short'),
-                            (rcarith.CInt, 'int'),
-                            (rcarith.CUInt, 'unsigned int'),
-                            (rcarith.CLong, 'long'),
-                            (rcarith.CULong, 'unsigned long'),
-                            (rcarith.CLonglong, 'long long'),
-                            (rcarith.CULonglong, 'unsigned long long')]:
-        define_c_primitive(ll_type, c_name)
+for ll_type, c_name in [(rffi.SIGNEDCHAR, 'signed char'),
+                        (rffi.UCHAR, 'unsigned char'),
+                        (rffi.SHORT, 'short'),
+                        (rffi.USHORT, 'unsigned short'),
+                        (rffi.INT, 'int'),
+                        (rffi.UINT, 'unsigned int'),
+                        (rffi.LONG, 'long'),
+                        (rffi.ULONG, 'unsigned long'),
+                        (rffi.LONGLONG, 'long long'),
+                        (rffi.ULONGLONG, 'unsigned long long')]:
+    define_c_primitive(ll_type, c_name)

Modified: pypy/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py	Wed Sep  5 14:50:35 2007
@@ -318,3 +318,25 @@
         fn = self.getcompiled(f, [int])
         res = fn(14)
         assert res == -1789569707
+
+    def test_prebuilt_integers(self):
+        from pypy.rlib.unroll import unrolling_iterable
+        from pypy.rpython.lltypesystem import rffi
+        class Prebuilt:
+            pass
+        p = Prebuilt()
+        NUMBER_TYPES = rffi.NUMBER_TYPES
+        names = unrolling_iterable([TYPE.__name__ for TYPE in NUMBER_TYPES])
+        for name, TYPE in zip(names, NUMBER_TYPES):
+            value = cast_primitive(TYPE, 1)
+            setattr(p, name, value)
+
+        def f(x):
+            total = x
+            for name in names:
+                total += rffi.cast(Signed, getattr(p, name))
+            return total
+
+        fn = self.getcompiled(f, [int])
+        res = fn(100)
+        assert res == 100 + len(list(names))


More information about the pypy-svn mailing list