[pypy-svn] r49080 - in pypy/branch/rewrite-compilation-logic/pypy: rpython rpython/module rpython/module/test translator/c

fijal at codespeak.net fijal at codespeak.net
Sun Nov 25 15:20:58 CET 2007


Author: fijal
Date: Sun Nov 25 15:20:55 2007
New Revision: 49080

Modified:
   pypy/branch/rewrite-compilation-logic/pypy/rpython/extfunc.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_environ.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_stat.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_time.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/module/test/test_posix.py
   pypy/branch/rewrite-compilation-logic/pypy/rpython/rtyper.py
   pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py
   pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py
Log:
* Make most test run (besides llvm)
* Fix genc to really wrap with exceptions cpython api calls
* make gencapicall use extern='CPython' instead of extern='C'


Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/extfunc.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/extfunc.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/extfunc.py	Sun Nov 25 15:20:55 2007
@@ -107,7 +107,7 @@
         from pypy.rpython.lltypesystem import rffi
 
         if 'compilation_info' in kwds:
-            kwds['compilation_info'] = self._compilation_info_.merge(
+            kwds['compilation_info'] = self.compilation_info.merge(
                 kwds['compilation_info'])
         else:
             kwds['compilation_info'] = self.compilation_info

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os.py	Sun Nov 25 15:20:55 2007
@@ -90,9 +90,13 @@
             data = {'ret_type': 'int', 'name': name}
             decls.append(decl_snippet % data)
             defs.append(def_snippet % data)
-        h_source = ['#include "sys/wait.h"'] + decls + ["#ifndef PYPY_NOT_MAIN_FILE"] + defs + ["#endif", ""]
-        h_file = udir.join("pypy_os_macros.h")
-        h_file.write("\n".join(h_source))
+        h_source = ['#include "sys/wait.h"'] + decls + defs
+
+        self.compilation_info = self.compilation_info.merge(
+            ExternalCompilationInfo(
+            post_include_lines = decls,
+            separate_module_sources = ["\n".join(h_source)]
+        ))
 
     # a simple, yet usefull factory
     def extdef_for_os_function_returning_int(self, name, **kwds):
@@ -184,21 +188,24 @@
         os_utime = self.llexternal('utime', [rffi.CCHARP, UTIMBUFP], rffi.INT)
 
         class CConfig:
-            _includes_ = ['sys/time.h']
+            _compilation_info_ = ExternalCompilationInfo(
+                includes=['sys/time.h']
+            )
             HAVE_UTIMES = platform.Has('utimes')
         config = platform.configure(CConfig)
 
         if config['HAVE_UTIMES']:
             class CConfig:
-                _includes_ = ['sys/time.h']
+                _compilation_info_ = ExternalCompilationInfo(
+                    includes = ['sys/time.h']
+                )
                 TIMEVAL = platform.Struct('struct timeval', [('tv_sec', rffi.LONG),
                                                              ('tv_usec', rffi.LONG)])
             config = platform.configure(CConfig)
             TIMEVAL = config['TIMEVAL']
             TIMEVAL2P = rffi.CArrayPtr(TIMEVAL)
             os_utimes = self.llexternal('utimes', [rffi.CCHARP, TIMEVAL2P],
-                                        rffi.INT,
-                                        includes=['sys/time.h'])
+                                        rffi.INT, compilation_info=CConfig._compilation_info_)
 
             def os_utime_platform(path, actime, modtime):
                 import math
@@ -344,7 +351,9 @@
     def register_os_uname(self):
         CHARARRAY = lltype.FixedSizeArray(lltype.Char, 1)
         class CConfig:
-            _includes_ = ['sys/utsname.h']
+            _compilation_info_ = ExternalCompilationInfo(
+                includes = ['sys/utsname.h']
+            )
             UTSNAME = platform.Struct('struct utsname', [
                 ('sysname',  CHARARRAY),
                 ('nodename', CHARARRAY),
@@ -355,7 +364,7 @@
         UTSNAMEP = lltype.Ptr(config['UTSNAME'])
 
         os_uname = self.llexternal('uname', [UTSNAMEP], rffi.INT,
-                                   includes=CConfig._includes_)
+                                   compilation_info=CConfig._compilation_info_)
 
         def uname_llimpl():
             l_utsbuf = lltype.malloc(UTSNAMEP.TO, flavor='raw')
@@ -572,7 +581,9 @@
         # to get a correct implementation of os.abspath
         # XXX why do we ignore WINAPI conventions everywhere?
         class CConfig:
-            _includes_ = ['Windows.h']
+            _compilation_info_ = ExternalCompilationInfo(
+                includes = ['Windows.h']
+            )
             MAX_PATH = platform.ConstantInteger('MAX_PATH')
             DWORD    = platform.SimpleType("DWORD", rffi.ULONG)
             LPCTSTR  = platform.SimpleType("LPCTSTR", rffi.CCHARP)
@@ -654,7 +665,9 @@
         # we need a different approach on Windows and on Posix
         if sys.platform.startswith('win'):
             class CConfig:
-                _includes_ = ['windows.h']
+                _compilation_info_ = ExternalCompilationInfo(
+                    includes = ['windows.h']
+                )
                 WIN32_FIND_DATA = platform.Struct('struct _WIN32_FIND_DATAA',
                     [('cFileName', lltype.FixedSizeArray(rffi.CHAR, 1))])
                 INVALID_HANDLE_VALUE = platform.ConstantInteger(
@@ -719,8 +732,11 @@
                     lltype.free(filedata, flavor='raw')
 
         else:
+            compilation_info = ExternalCompilationInfo(
+                includes = ['sys/types.h', 'dirent.h']
+            )
             class CConfig:
-                _includes_ = ['sys/types.h', 'dirent.h']
+                _compilation_info_ = compilation_info
                 DIRENT = platform.Struct('struct dirent',
                     [('d_name', lltype.FixedSizeArray(rffi.CHAR, 1))])
 
@@ -729,11 +745,11 @@
             DIRENT = config['DIRENT']
             DIRENTP = lltype.Ptr(DIRENT)
             os_opendir = self.llexternal('opendir', [rffi.CCHARP], DIRP,
-                                         includes=CConfig._includes_)
+                                         compilation_info=compilation_info)
             os_readdir = self.llexternal('readdir', [DIRP], DIRENTP,
-                                         includes=CConfig._includes_)
+                                         compilation_info=compilation_info)
             os_closedir = self.llexternal('closedir', [DIRP], rffi.INT,
-                                          includes=CConfig._includes_)
+                                          compilation_info=compilation_info)
 
             def os_listdir_llimpl(path):
                 dirp = os_opendir(path)
@@ -1107,8 +1123,8 @@
             return int(getattr(os, name)(status))
         fake.func_name = 'fake_' + name
 
-        os_c_func = self.llexternal("pypy_macro_wrapper_" + name, [lltype.Signed],
-                                    lltype.Signed, includes=['pypy_os_macros.h'],
+        os_c_func = self.llexternal("pypy_macro_wrapper_" + name,
+                                    [lltype.Signed], lltype.Signed,
                                     _callable=fake)
     
         if name in self.w_star_returning_int:

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_environ.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_environ.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_environ.py	Sun Nov 25 15:20:55 2007
@@ -132,6 +132,8 @@
 # ____________________________________________________________
 # Access to the 'environ' external variable
 
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
 if sys.platform.startswith('darwin'):
     CCHARPPP = rffi.CArrayPtr(rffi.CCHARPP)
     _os_NSGetEnviron = rffi.llexternal('_NSGetEnviron', [], CCHARPPP,
@@ -140,7 +142,8 @@
         return _os_NSGetEnviron()[0]
 else:
     os_get_environ, _os_set_environ = rffi.CExternVariable(rffi.CCHARPP,
-                                                           'environ')
+                                                           'environ',
+                                                           ExternalCompilationInfo())
 
 # ____________________________________________________________
 

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_stat.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_os_stat.py	Sun Nov 25 15:20:55 2007
@@ -11,6 +11,7 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rpython.lltypesystem.rtupletype import TUPLE_TYPE
 from pypy.rlib import rposix
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
 
 # XXX on Windows, stat() is flawed; see CPython's posixmodule.c for
 # an implementation based on the Win32 API
@@ -144,11 +145,15 @@
     _name_struct_stat = 'stat'
     INCLUDES = ['sys/types.h', 'sys/stat.h', 'unistd.h']
 
+compilation_info = ExternalCompilationInfo(
+    pre_include_lines = ['#define _FILE_OFFSET_BITS 64'],
+    includes = INCLUDES
+)
+
 from pypy.rpython.tool import rffi_platform as platform
 class CConfig:
     # This must be set to 64 on some systems to enable large file support.
-    _header_ = '#define _FILE_OFFSET_BITS 64'
-    _includes_ = INCLUDES
+    _compilation_info_ = compilation_info
     STAT_STRUCT = platform.Struct('struct %s' % _name_struct_stat, LL_STAT_FIELDS)
 config = platform.configure(CConfig)
 
@@ -198,7 +203,7 @@
     else:
         ARG1 = rffi.INT
     os_mystat = rffi.llexternal(c_func_name, [ARG1, STAT_STRUCT], rffi.INT,
-                                includes=INCLUDES)
+                                compilation_info=compilation_info)
 
     def os_mystat_llimpl(arg):
         stresult = lltype.malloc(STAT_STRUCT.TO, flavor='raw')

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_time.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_time.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/ll_time.py	Sun Nov 25 15:20:55 2007
@@ -9,14 +9,19 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.extfunc import BaseLazyRegistering, registering, extdef
 from pypy.rlib import rposix
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
+if sys.platform.startswith('win'):
+    includes = ['time.h', 'windows.h']
+else:
+    includes = ['sys/time.h', 'time.h', 'errno.h', 'sys/select.h',
+                'sys/types.h', 'unistd.h', 'sys/timeb.h']
+
 
 class CConfig:
-    if sys.platform.startswith('win'):
-        _includes_ = ['time.h', 'windows.h']
-    else:
-        _includes_ = ['sys/time.h', 'time.h', 'errno.h', 'sys/select.h',
-                      'sys/types.h', 'unistd.h', 'sys/timeb.h']
-    
+    _compilation_info_ = ExternalCompilationInfo(
+        includes=includes
+    )
     CLOCK_T = platform.SimpleType('clock_t', rffi.INT)
     TIMEVAL = platform.Struct('struct timeval', [('tv_sec', rffi.INT),
                                                  ('tv_usec', rffi.INT)])
@@ -25,7 +30,7 @@
     HAVE_FTIME = platform.Has('ftime')
 
 class CConfigForFTime:
-    _includes_ = ['sys/timeb.h']
+    _compilation_info_ = ExternalCompilationInfo(includes=['sys/timeb.h'])
     TIMEB = platform.Struct('struct timeb', [('time', rffi.INT),
                                              ('millitm', rffi.INT)])
 

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/module/test/test_posix.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/module/test/test_posix.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/module/test/test_posix.py	Sun Nov 25 15:20:55 2007
@@ -154,5 +154,5 @@
             assert res == fun(value)
 
 def test_os_wstar():
-    yield os_wstar_tester, compile_llvm
     yield os_wstar_tester, compile
+    yield os_wstar_tester, compile_llvm

Modified: pypy/branch/rewrite-compilation-logic/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/rpython/rtyper.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/rpython/rtyper.py	Sun Nov 25 15:20:55 2007
@@ -925,7 +925,7 @@
         return self.genop('direct_call', [cf]+list(args_v), resulttype)
 
     def gencapicall(self, cfnname, args_v, resulttype=None, **flags):
-        return self.genexternalcall(cfnname, args_v, resulttype=resulttype, external="C", **flags)
+        return self.genexternalcall(cfnname, args_v, resulttype=resulttype, external="CPython", **flags)
 
     def genconst(self, ll_value):
         return inputconst(typeOf(ll_value), ll_value)

Modified: pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/translator/c/genc.py	Sun Nov 25 15:20:55 2007
@@ -745,7 +745,7 @@
     libraries = eci.libraries
     f.write(SETUP_PY % locals())
     f.close()
-    eci = eci.convert_sources_to_files()
+    eci = eci.convert_sources_to_files(being_main=True)
 
     return filename, sg.getextrafiles() + list(eci.separate_module_files)
 

Modified: pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py	(original)
+++ pypy/branch/rewrite-compilation-logic/pypy/translator/c/node.py	Sun Nov 25 15:20:55 2007
@@ -821,16 +821,14 @@
         exception_policy = getattr(fnobj, 'exception_policy', None)
         return [FunctionCodeGenerator(fnobj.graph, db, exception_policy,
                                       functionname)]
-    elif getattr(fnobj, 'external', None) == 'C':
+    elif getattr(fnobj, 'external', None) is not None:
         if sandbox:
             return sandbox_stub(fnobj, db)
-        # XXX broken
-        return []
-        #if hasattr(fnobj, 'includes'):
-        #    return []   # assume no wrapper needed
-        #else:
-        #    # deprecated case
-        #    return [CExternalFunctionCodeGenerator(fnobj, db)]
+        elif fnobj.external == 'C':
+            return []
+        else:
+            assert fnobj.external == 'CPython'
+            return [CExternalFunctionCodeGenerator(fnobj, db)]
     else:
         raise ValueError, "don't know how to generate code for %r" % (fnobj,)
 



More information about the Pypy-commit mailing list