[pypy-svn] r55394 - in pypy/dist/pypy: rlib rlib/rstruct rpython/lltypesystem rpython/module rpython/tool rpython/tool/test translator/tool translator/tool/test

arigo at codespeak.net arigo at codespeak.net
Thu May 29 15:35:23 CEST 2008


Author: arigo
Date: Thu May 29 15:35:20 2008
New Revision: 55394

Modified:
   pypy/dist/pypy/rlib/_rsocket_rffi.py
   pypy/dist/pypy/rlib/libffi.py
   pypy/dist/pypy/rlib/rmmap.py
   pypy/dist/pypy/rlib/rstruct/nativefmttable.py
   pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/rpython/module/ll_os_stat.py
   pypy/dist/pypy/rpython/tool/rffi_platform.py
   pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
   pypy/dist/pypy/translator/tool/cbuild.py
   pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
Rename "pre/post_include_lines" to "pre/post_include_bits".
This is now supposed to be not a list of lines, but a list
of pieces of source.  Duplicate pieces are removed.  Should
fix the fact that in a pypy-c translation each module_#.c
contains dozens of copies of the same declarations...


Modified: pypy/dist/pypy/rlib/_rsocket_rffi.py
==============================================================================
--- pypy/dist/pypy/rlib/_rsocket_rffi.py	(original)
+++ pypy/dist/pypy/rlib/_rsocket_rffi.py	Thu May 29 15:35:20 2008
@@ -53,7 +53,7 @@
 constants = {}
 
 eci = ExternalCompilationInfo(
-    pre_include_lines = (HEADER + COND_HEADER).split("\n"),
+    post_include_bits = [HEADER, COND_HEADER],
     includes = includes,
     libraries = libraries,
 )

Modified: pypy/dist/pypy/rlib/libffi.py
==============================================================================
--- pypy/dist/pypy/rlib/libffi.py	(original)
+++ pypy/dist/pypy/rlib/libffi.py	Thu May 29 15:35:20 2008
@@ -37,7 +37,7 @@
 else:
     libffidir = py.path.local(pypydir).join('translator', 'c', 'src', 'libffi_msvc')
     eci = ExternalCompilationInfo(
-        pre_include_lines = ['#define _WIN32_WINNT 0x501'],
+        pre_include_bits = ['#define _WIN32_WINNT 0x501'],
         includes = ['ffi.h', 'windows.h'],
         libraries = ['kernel32'],
         include_dirs = [libffidir],

Modified: pypy/dist/pypy/rlib/rmmap.py
==============================================================================
--- pypy/dist/pypy/rlib/rmmap.py	(original)
+++ pypy/dist/pypy/rlib/rmmap.py	Thu May 29 15:35:20 2008
@@ -31,9 +31,9 @@
 class CConfig:
     _compilation_info_ = ExternalCompilationInfo(
         includes=includes,
-        pre_include_lines=['#ifndef _GNU_SOURCE',
-                           '#define _GNU_SOURCE',
-                           '#endif']
+        pre_include_bits=['#ifndef _GNU_SOURCE\n' +
+                          '#define _GNU_SOURCE\n' +
+                          '#endif']
     )
     size_t = rffi_platform.SimpleType("size_t", rffi.LONG)
     off_t = rffi_platform.SimpleType("off_t", rffi.LONG)

Modified: pypy/dist/pypy/rlib/rstruct/nativefmttable.py
==============================================================================
--- pypy/dist/pypy/rlib/rstruct/nativefmttable.py	(original)
+++ pypy/dist/pypy/rlib/rstruct/nativefmttable.py	Thu May 29 15:35:20 2008
@@ -79,18 +79,18 @@
                'd': 'double',
                }
 
-    pre_include_lines = []
+    pre_include_bits = []
     for fmtchar, ctype in INSPECT.items():
-        pre_include_lines += ("""
+        pre_include_bits.append("""
             struct about_%s {
                 char pad;
                 %s field;
             };
-        """ % (fmtchar, ctype)).split("\n")
+        """ % (fmtchar, ctype))
 
     class CConfig:
         _compilation_info_ = ExternalCompilationInfo(
-            pre_include_lines = pre_include_lines
+            pre_include_bits = pre_include_bits
         )
 
     for fmtchar, ctype in INSPECT.items():

Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py	Thu May 29 15:35:20 2008
@@ -425,7 +425,7 @@
     sources = ('\n'.join(lines),)
     new_eci = eci.merge(ExternalCompilationInfo(
         separate_module_sources = sources,
-        post_include_lines = [getter_prototype, setter_prototype],
+        post_include_bits = [getter_prototype, setter_prototype],
         export_symbols = [getter_name, setter_name],
     ))
 

Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os.py	Thu May 29 15:35:20 2008
@@ -97,14 +97,13 @@
             defs = []
             for name in self.w_star:
                 data = {'ret_type': 'int', 'name': name}
-                decls.append(decl_snippet % data)
-                defs.append(def_snippet % data)
-            h_source = decls + defs
+                decls.append((decl_snippet % data).strip())
+                defs.append((def_snippet % data).strip())
 
             self.compilation_info = self.compilation_info.merge(
                 ExternalCompilationInfo(
-                post_include_lines = decls,
-                separate_module_sources = ["\n".join(h_source)]
+                post_include_bits = decls,
+                separate_module_sources = ["\n".join(defs)]
             ))
 
     # a simple, yet usefull factory

Modified: pypy/dist/pypy/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os_stat.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os_stat.py	Thu May 29 15:35:20 2008
@@ -146,7 +146,7 @@
     INCLUDES = ['sys/types.h', 'sys/stat.h', 'unistd.h']
 
 compilation_info = ExternalCompilationInfo(
-    pre_include_lines = ['#define _FILE_OFFSET_BITS 64'],
+    pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
     includes = INCLUDES
 )
 

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	Thu May 29 15:35:20 2008
@@ -16,7 +16,7 @@
 
 def eci_from_header(c_header_source):
     return ExternalCompilationInfo(
-        pre_include_lines=c_header_source.split("\n")
+        pre_include_bits=[c_header_source]
     )
 
 def getstruct(name, c_header_source, interesting_fields):

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	Thu May 29 15:35:20 2008
@@ -111,9 +111,9 @@
 
     class CConfig:
         _compilation_info_ = ExternalCompilationInfo(
-            pre_include_lines = ["/* a C comment */",
-                                 "#include <stdio.h>",
-                                 "#include <test_ctypes_platform.h>"],
+            pre_include_bits = ["/* a C comment */",
+                                "#include <stdio.h>",
+                                "#include <test_ctypes_platform.h>"],
             include_dirs = [str(udir)]
         )
 
@@ -130,13 +130,15 @@
 def test_ifdef():
     class CConfig:
         _compilation_info_ = ExternalCompilationInfo(
-            post_include_lines = ['/* a C comment */',
-                                  '#define XYZZY 42',
-                                  'typedef int foo;',
-                                  'struct s {',
-                                  'int i;',
-                                  'double f;'
-                                  '};'])
+            post_include_bits = ['/* a C comment */',
+                                 '#define XYZZY 42',
+                                 'typedef int foo;',
+                                 '''
+                                 struct s {
+                                   int i;
+                                   double f;
+                                 };
+                                 '''])
 
         s = rffi_platform.Struct('struct s', [('i', rffi.INT)],
                                    ifdef='XYZZY')
@@ -155,7 +157,7 @@
 def test_nested_structs():
     class CConfig:
         _compilation_info_ = ExternalCompilationInfo(
-            post_include_lines="""
+            post_include_bits=["""
             struct x {
             int foo;
             unsigned long bar;
@@ -164,7 +166,7 @@
             char c;
             struct x x;
             };
-            """.split("\n"))
+            """])
         x = rffi_platform.Struct("struct x", [("bar", rffi.SHORT)])
         y = rffi_platform.Struct("struct y", [("x", x)])
 
@@ -178,7 +180,7 @@
 def test_nested_structs_in_the_opposite_order():
     class CConfig:
         _compilation_info_ = ExternalCompilationInfo(
-            post_include_lines="""
+            post_include_bits=["""
             struct y {
             int foo;
             unsigned long bar;
@@ -187,7 +189,7 @@
             char c;
             struct y y;
             };
-            """.split("\n"))
+            """])
         y = rffi_platform.Struct("struct y", [("bar", rffi.SHORT)])
         x = rffi_platform.Struct("struct x", [("y", y)])
 

Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Thu May 29 15:35:20 2008
@@ -14,18 +14,17 @@
 
 class ExternalCompilationInfo(object):
 
-    _ATTRIBUTES = ['pre_include_lines', 'includes', 'include_dirs',
-                   'post_include_lines', 'libraries', 'library_dirs',
+    _ATTRIBUTES = ['pre_include_bits', 'includes', 'include_dirs',
+                   'post_include_bits', 'libraries', 'library_dirs',
                    'separate_module_sources', 'separate_module_files',
                    'export_symbols', 'compile_extra', 'link_extra', 'frameworks']
-    _AVOID_DUPLICATES = ['separate_module_files', 'libraries', 'includes',
-                         'include_dirs', 'library_dirs', 'separate_module_sources']
+    _DUPLICATES_OK = ['compile_extra', 'link_extra']
 
     def __init__(self,
-                 pre_include_lines       = [],
+                 pre_include_bits        = [],
                  includes                = [],
                  include_dirs            = [],
-                 post_include_lines      = [],
+                 post_include_bits       = [],
                  libraries               = [],
                  library_dirs            = [],
                  separate_module_sources = [],
@@ -35,17 +34,18 @@
                  link_extra              = [],
                  frameworks              = []):
         """
-        pre_include_lines: list of lines that should be put at the top
+        pre_include_bits: list of pieces of text that should be put at the top
         of the generated .c files, before any #include.  They shouldn't
-        contain an #include themselves.
+        contain an #include themselves.  (Duplicate pieces are removed.)
 
         includes: list of .h file names to be #include'd from the
         generated .c files.
 
         include_dirs: list of dir names that is passed to the C compiler
 
-        post_include_lines: list of lines that should be put at the top
-        of the generated .c files, after the #includes.
+        post_include_bits: list of pieces of text that should be put at the top
+        of the generated .c files, after the #includes.  (Duplicate pieces are
+        removed.)
 
         libraries: list of library names that is passed to the linker
 
@@ -54,7 +54,7 @@
         separate_module_sources: list of multiline strings that are
         each written to a .c file and compiled separately and linked
         later on.  (If function prototypes are needed for other .c files
-        to access this, they can be put in post_include_lines.)
+        to access this, they can be put in post_include_bits.)
 
         separate_module_files: list of .c file names that are compiled
         separately and linked later on.  (If an .h file is needed for
@@ -83,7 +83,7 @@
         """Returns a new ExternalCompilationInfo instance by parsing
         the string 'flags', which is in the typical Unix compiler flags
         format."""
-        pre_include_lines = []
+        pre_include_bits = []
         include_dirs = []
         compile_extra = []
         for arg in flags.split():
@@ -95,13 +95,13 @@
                     macro, value = macro.split('=')
                 else:
                     value = '1'
-                pre_include_lines.append('#define %s %s' % (macro, value))
+                pre_include_bits.append('#define %s %s' % (macro, value))
             elif arg.startswith('-L') or arg.startswith('-l'):
                 raise ValueError('linker flag found in compiler options: %r'
                                  % (arg,))
             else:
                 compile_extra.append(arg)
-        return cls(pre_include_lines=pre_include_lines,
+        return cls(pre_include_bits=pre_include_bits,
                    include_dirs=include_dirs,
                    compile_extra=compile_extra)
     from_compiler_flags = classmethod(from_compiler_flags)
@@ -176,7 +176,7 @@
 
         attrs = {}
         for name in self._ATTRIBUTES:
-            if name not in self._AVOID_DUPLICATES:
+            if name in self._DUPLICATES_OK:
                 s = []
                 for i in [self] + others:
                     s += getattr(i, name)
@@ -193,12 +193,12 @@
         return ExternalCompilationInfo(**attrs)
 
     def write_c_header(self, fileobj):
-        for line in self.pre_include_lines:
-            print >> fileobj, line
+        for piece in self.pre_include_bits:
+            print >> fileobj, piece
         for path in self.includes:
             print >> fileobj, '#include <%s>' % (path,)
-        for line in self.post_include_lines:
-            print >> fileobj, line
+        for piece in self.post_include_bits:
+            print >> fileobj, piece
 
     def _copy_attributes(self):
         d = {}

Modified: pypy/dist/pypy/translator/tool/test/test_cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/test/test_cbuild.py	Thu May 29 15:35:20 2008
@@ -58,38 +58,38 @@
     
     def test_merge(self):
         e1 = ExternalCompilationInfo(
-            pre_include_lines  = ['1'],
+            pre_include_bits   = ['1'],
             includes           = ['x.h'],
-            post_include_lines = ['p1']
+            post_include_bits  = ['p1']
         )
         e2 = ExternalCompilationInfo(
-            pre_include_lines  = ['2'],
+            pre_include_bits   = ['2'],
             includes           = ['x.h', 'y.h'],
-            post_include_lines = ['p2'],
+            post_include_bits  = ['p2'],
         )
         e3 = ExternalCompilationInfo(
-            pre_include_lines  = ['3'],
+            pre_include_bits   = ['3'],
             includes           = ['y.h', 'z.h'],
-            post_include_lines = ['p3']
+            post_include_bits  = ['p1', 'p3']
         )
         e = e1.merge(e2, e3)
-        assert e.pre_include_lines == ('1', '2', '3')
+        assert e.pre_include_bits == ('1', '2', '3')
         assert e.includes == ('x.h', 'y.h', 'z.h')
-        assert e.post_include_lines == ('p1', 'p2', 'p3')
+        assert e.post_include_bits == ('p1', 'p2', 'p3')
 
     def test_merge2(self):
         e1 = ExternalCompilationInfo(
-            pre_include_lines  = ['1'],
+            pre_include_bits  = ['1'],
         )
         e2 = ExternalCompilationInfo(
-            pre_include_lines  = ['2'],
+            pre_include_bits  = ['2'],
         )
         e3 = ExternalCompilationInfo(
-            pre_include_lines  = ['3'],
+            pre_include_bits  = ['3'],
         )
         e = e1.merge(e2)
         e = e.merge(e3, e3)
-        assert e.pre_include_lines == ('1', '2', '3')
+        assert e.pre_include_bits == ('1', '2', '3')
 
     def test_convert_sources_to_c_files(self):
         eci = ExternalCompilationInfo(
@@ -129,8 +129,8 @@
         flags = ('-I/some/include/path -I/other/include/path '
                  '-DMACRO1 -D_MACRO2=baz -?1 -!2')
         eci = ExternalCompilationInfo.from_compiler_flags(flags)
-        assert eci.pre_include_lines == ('#define MACRO1 1',
-                                         '#define _MACRO2 baz')
+        assert eci.pre_include_bits == ('#define MACRO1 1',
+                                        '#define _MACRO2 baz')
         assert eci.includes == ()
         assert eci.include_dirs == ('/some/include/path',
                                     '/other/include/path')



More information about the Pypy-commit mailing list