[pypy-svn] r72846 - in pypy/trunk/pypy/rpython: lltypesystem tool

arigo at codespeak.net arigo at codespeak.net
Thu Mar 25 20:19:18 CET 2010


Author: arigo
Date: Thu Mar 25 20:19:17 2010
New Revision: 72846

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/rffi.py
   pypy/trunk/pypy/rpython/tool/rfficache.py
Log:
Whack (maybe unneeded) to have one instead of about 15 calls to
the compiler to fint out the basic size of primitive integer types.


Modified: pypy/trunk/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rffi.py	Thu Mar 25 20:19:17 2010
@@ -356,10 +356,9 @@
     MODE_T = lltype.Signed
     PID_T = lltype.Signed
 
-def setup():
-    """ creates necessary c-level types
-    """
-    result = []
+def populate_inttypes():
+    names = []
+    populatelist = []
     for name in TYPES:
         c_name = name
         if name.startswith('unsigned'):
@@ -368,7 +367,18 @@
         else:
             signed = (name != 'size_t')
         name = name.replace(' ', '')
-        tp = platform.inttype(name.upper(), c_name, signed)
+        names.append(name)
+        populatelist.append((name.upper(), c_name, signed))
+    platform.populate_inttypes(populatelist)
+    return names
+
+def setup():
+    """ creates necessary c-level types
+    """
+    names = populate_inttypes()
+    result = []
+    for name in names:
+        tp = platform.types[name.upper()]
         globals()['r_' + name] = platform.numbertype_to_rclass[tp]
         globals()[name.upper()] = tp
         tpp = lltype.Ptr(lltype.Array(tp, hints={'nolength': True}))

Modified: pypy/trunk/pypy/rpython/tool/rfficache.py
==============================================================================
--- pypy/trunk/pypy/rpython/tool/rfficache.py	(original)
+++ pypy/trunk/pypy/rpython/tool/rfficache.py	Thu Mar 25 20:19:17 2010
@@ -34,12 +34,22 @@
     return build_executable_cache([c_file], eci)
 
 def sizeof_c_type(c_typename, **kwds):
-    question = 'printf("sizeof %s=%%ld", (long)sizeof(%s));' % (c_typename,
-                                                                c_typename)
-    answer = ask_gcc(question, **kwds).split('=')
-    assert answer[0] == "sizeof " + c_typename, "wrong program: " \
-           "sizeof %s expected, got %s" % (c_typename, answer[0])
-    return int(answer[1])
+    return sizeof_c_types([c_typename], **kwds)[0]
+
+def sizeof_c_types(typenames_c, **kwds):
+    lines = ['printf("sizeof %s=%%ld\\n", (long)sizeof(%s));' % (c_typename,
+                                                                 c_typename)
+             for c_typename in typenames_c]
+    question = '\n\t'.join(lines)
+    answer = ask_gcc(question, **kwds)
+    lines = answer.splitlines()
+    assert len(lines) == len(typenames_c)
+    result = []
+    for line, c_typename in zip(lines, typenames_c):
+        answer = line.split('=')
+        assert answer[0] == "sizeof " + c_typename
+        result.append(int(answer[1]))
+    return result
 
 class Platform:
     def __init__(self):
@@ -50,11 +60,28 @@
         try:
             return self.types[name]
         except KeyError:
-            bits = sizeof_c_type(c_name, **kwds) * 8
-            inttype = rarithmetic.build_int('r_' + name, signed, bits)
-            tp = lltype.build_number(name, inttype)
-            self.numbertype_to_rclass[tp] = inttype
-            self.types[name] = tp
-            return tp
+            size = sizeof_c_type(c_name, **kwds)
+            return self._make_type(name, signed, size)
+
+    def _make_type(self, name, signed, size):
+        inttype = rarithmetic.build_int('r_' + name, signed, size*8)
+        tp = lltype.build_number(name, inttype)
+        self.numbertype_to_rclass[tp] = inttype
+        self.types[name] = tp
+        return tp
+
+    def populate_inttypes(self, list, **kwds):
+        """'list' is a list of (name, c_name, signed)."""
+        missing = []
+        names_c = []
+        for name, c_name, signed in list:
+            if name not in self.types:
+                missing.append((name, signed))
+                names_c.append(c_name)
+        if names_c:
+            sizes = sizeof_c_types(names_c, **kwds)
+            assert len(sizes) == len(missing)
+            for (name, signed), size in zip(missing, sizes):
+                self._make_type(name, signed, size)
 
 platform = Platform()



More information about the Pypy-commit mailing list