[pypy-svn] r72313 - in pypy/branch/kill-python-h/pypy: rlib rpython/module rpython/tool translator/c translator/c/src translator/tool

arigo at codespeak.net arigo at codespeak.net
Wed Mar 17 16:00:31 CET 2010


Author: arigo
Date: Wed Mar 17 16:00:29 2010
New Revision: 72313

Added:
   pypy/branch/kill-python-h/pypy/translator/c/src/commondefs.h   (contents, props changed)
Modified:
   pypy/branch/kill-python-h/pypy/rlib/rmmap.py
   pypy/branch/kill-python-h/pypy/rpython/module/ll_os.py
   pypy/branch/kill-python-h/pypy/rpython/module/ll_os_stat.py
   pypy/branch/kill-python-h/pypy/rpython/tool/rffi_platform.py
   pypy/branch/kill-python-h/pypy/translator/c/genc.py
   pypy/branch/kill-python-h/pypy/translator/c/src/g_prerequisite.h
   pypy/branch/kill-python-h/pypy/translator/c/src/main.h
   pypy/branch/kill-python-h/pypy/translator/c/src/obmalloc.c
   pypy/branch/kill-python-h/pypy/translator/tool/cbuild.py
Log:
Random whacking in order (originally) to remove the dependencies
to Python.h or pyconfig.h.


Modified: pypy/branch/kill-python-h/pypy/rlib/rmmap.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/rlib/rmmap.py	(original)
+++ pypy/branch/kill-python-h/pypy/rlib/rmmap.py	Wed Mar 17 16:00:29 2010
@@ -32,9 +32,10 @@
 class CConfig:
     _compilation_info_ = ExternalCompilationInfo(
         includes=includes,
-        pre_include_bits=['#ifndef _GNU_SOURCE\n' +
-                          '#define _GNU_SOURCE\n' +
-                          '#endif']
+        #pre_include_bits=['#ifndef _GNU_SOURCE\n' +
+        #                  '#define _GNU_SOURCE\n' +
+        #                  '#endif']
+        # ^^^ _GNU_SOURCE is always defined by the ExternalCompilationInfo now
     )
     size_t = rffi_platform.SimpleType("size_t", rffi.LONG)
     off_t = rffi_platform.SimpleType("off_t", rffi.LONG)

Modified: pypy/branch/kill-python-h/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/kill-python-h/pypy/rpython/module/ll_os.py	Wed Mar 17 16:00:29 2010
@@ -88,31 +88,17 @@
     def __init__(self):
         self.configure(CConfig)
 
-        # on some platforms, e.g. OS X Leopard, the following constants which
-        # may be defined in pyconfig.h triggers "legacy" behaviour for functions
-        # like setpgrp():
-        #
-        #   _POSIX_C_SOURCE 200112L
-        #   _XOPEN_SOURCE 600
-        #   _DARWIN_C_SOURCE 1
-        #
-        # since the translation currently includes pyconfig.h, the checkcompiles
-        # call below include the pyconfig.h file so that the same behaviour is
-        # present in both the check and the final translation...
-
         if hasattr(os, 'getpgrp'):
             self.GETPGRP_HAVE_ARG = platform.checkcompiles(
                 "getpgrp(0)",
-                '#include "pyconfig.h"\n#include <unistd.h>',
-                [platform.get_python_include_dir()]
-                )
+                '#include <unistd.h>',
+                [])
 
         if hasattr(os, 'setpgrp'):
             self.SETPGRP_HAVE_ARG = platform.checkcompiles(
                 "setpgrp(0,0)",
-                '#include "pyconfig.h"\n#include <unistd.h>',
-                [platform.get_python_include_dir()]
-                )
+                '#include <unistd.h>',
+                [])
 
         # we need an indirection via c functions to get macro calls working on llvm XXX still?
         if hasattr(os, 'WCOREDUMP'):

Modified: pypy/branch/kill-python-h/pypy/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/rpython/module/ll_os_stat.py	(original)
+++ pypy/branch/kill-python-h/pypy/rpython/module/ll_os_stat.py	Wed Mar 17 16:00:29 2010
@@ -136,7 +136,8 @@
 
 compilation_info = ExternalCompilationInfo(
     # This must be set to 64 on some systems to enable large file support.
-    pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
+    #pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
+    # ^^^ nowadays it's always set in all C files we produce.
     includes = INCLUDES
 )
 

Modified: pypy/branch/kill-python-h/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/rpython/tool/rffi_platform.py	(original)
+++ pypy/branch/kill-python-h/pypy/rpython/tool/rffi_platform.py	Wed Mar 17 16:00:29 2010
@@ -8,7 +8,6 @@
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.translator.platform import CompilationError
 from pypy.tool.udir import udir
-import distutils
 
 # ____________________________________________________________
 #
@@ -18,7 +17,7 @@
     if include_dirs is None:
         include_dirs = []
     return ExternalCompilationInfo(
-        pre_include_bits=[c_header_source],
+        post_include_bits=[c_header_source],
         include_dirs=include_dirs
     )
 
@@ -563,11 +562,6 @@
 
 # ____________________________________________________________
 
-def get_python_include_dir():
-    from distutils import sysconfig
-    gcv = sysconfig.get_config_vars()
-    return gcv.get('INCLUDEPY', '.') # this is for running on top of pypy-c
-
 def configure_external_library(name, eci, configurations,
                                symbol=None, _cache={}):
     """try to find the external library.

Modified: pypy/branch/kill-python-h/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/translator/c/genc.py	(original)
+++ pypy/branch/kill-python-h/pypy/translator/c/genc.py	Wed Mar 17 16:00:29 2010
@@ -116,11 +116,8 @@
 
     def get_eci(self):
         from distutils import sysconfig
-        python_inc = sysconfig.get_python_inc() # XXX refactor remaining dependencies
-                                                # like obmalloc into separately compilable
-                                                # modules etc.
         pypy_include_dir = py.path.local(autopath.pypydir).join('translator', 'c')
-        include_dirs = [python_inc, pypy_include_dir]
+        include_dirs = [pypy_include_dir]
         return ExternalCompilationInfo(include_dirs=include_dirs)
 
     def build_database(self):
@@ -735,16 +732,7 @@
         print >> f
 
 
-def gen_size_check(f):
-    from pypy.rlib.rarithmetic import LONG_BIT
-    print >> f, '#if 8 * SIZEOF_LONG != %d' % (LONG_BIT,)
-    print >> f, '#  error "C files are generated for a %d-bit platform"' % (
-        LONG_BIT,)
-    print >> f, '#endif'
-    print >> f
-
 def gen_structdef(f, database):
-    gen_size_check(f)
     structdeflist = database.getstructdeflist()
     print >> f, '/***********************************************************/'
     print >> f, '/***  Structure definitions                              ***/'
@@ -830,6 +818,10 @@
     print >> f, '\treturn error;'
     print >> f, '}'
 
+def commondefs(defines):
+    from pypy.rlib.rarithmetic import LONG_BIT
+    defines['PYPY_LONG_BIT'] = LONG_BIT
+
 def gen_source_standalone(database, modulename, targetdir, eci,
                           entrypointname, defines={}): 
     assert database.standalone
@@ -845,16 +837,11 @@
     #
     print >> f, '#include "common_header.h"'
     print >> f
+    commondefs(defines)
     defines['PYPY_STANDALONE'] = entrypointname
     for key, value in defines.items():
         print >> fi, '#define %s %s' % (key, value)
 
-    if sys.platform == 'win32':
-        print >> fi, '#define Py_BUILD_CORE /* avoid pulling python libs in */'
-        print >> fi, '#define WIN32_LEAN_AND_MEAN /* winsock/winsock2 mess */'
-
-    print >> fi, '#include "pyconfig.h"'
-
     eci.write_c_header(fi)
     print >> fi, '#include "src/g_prerequisite.h"'
 
@@ -902,14 +889,10 @@
     #
     print >> f, '#include "common_header.h"'
     print >> f
+    commondefs(defines)
     for key, value in defines.items():
         print >> fi, '#define %s %s' % (key, value)
 
-    if sys.platform == 'win32':
-        print >> fi, '#define WIN32_LEAN_AND_MEAN /* winsock/winsock2 mess */'
-
-    print >> fi, '#include "pyconfig.h"'
-
     eci.write_c_header(fi)
     print >> fi, '#include "src/g_prerequisite.h"'
 

Added: pypy/branch/kill-python-h/pypy/translator/c/src/commondefs.h
==============================================================================
--- (empty file)
+++ pypy/branch/kill-python-h/pypy/translator/c/src/commondefs.h	Wed Mar 17 16:00:29 2010
@@ -0,0 +1,75 @@
+
+/************************************************************/
+ /***  C header subsection: common types and macros        ***/
+
+
+/* We only support the following two kinds of platform:
+
+                 int     long     long long     void*
+   --32-bit--    32      32         64          32
+   --64-bit--    32      64         64          64
+
+   In particular, Win64 is not supported because it has sizeof(long) == 4.
+   To fix this, find and review all the places that cast a pointer to a long.
+*/
+
+#include <limits.h>
+
+#if INT_MAX != 2147483647
+#  error "unsupported value for INT_MAX"
+#endif
+#if INT_MIN != -2147483647-1
+#  error "unsupported value for INT_MIN"
+#endif
+
+#if LLONG_MAX != 9223372036854775807LL
+#  error "unsupported value for LLONG_MAX"
+#endif
+#if LLONG_MIN != -9223372036854775807LL-1LL
+#  error "unsupported value for LLONG_MIN"
+#endif
+
+
+/******************** 32-bit support ********************/
+#if PYPY_LONG_BIT == 32
+
+#  if LONG_MAX != 2147483647L
+#    error "error in LONG_MAX (32-bit sources but a 64-bit compiler?)"
+#  endif
+#  if LONG_MIN != -2147483647L-1L
+#    error "unsupported value for LONG_MIN"
+#  endif
+
+#  define SIZEOF_INT        4
+#  define SIZEOF_LONG       4
+#  define SIZEOF_LONG_LONG  8
+
+/******************** 64-bit support ********************/
+#else
+
+#  if LONG_MAX != 9223372036854775807L
+#    error "error in LONG_MAX (64-bit sources but a 32-bit compiler?)"
+#  endif
+#  if LONG_MIN != -9223372036854775807L-1L
+#    error "unsupported value for LONG_MIN"
+#  endif
+
+#  define SIZEOF_INT        4
+#  define SIZEOF_LONG       8
+#  define SIZEOF_LONG_LONG  8
+
+#endif
+
+/********************************************************/
+
+typedef long Py_intptr_t;
+typedef unsigned long Py_uintptr_t;
+
+#if ((-1) >> 1) > 0
+#  define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
+	  ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
+#elif ((-1) >> 1) == -1
+#  define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
+#else
+#  error "uh? strange result"
+#endif

Modified: pypy/branch/kill-python-h/pypy/translator/c/src/g_prerequisite.h
==============================================================================
--- pypy/branch/kill-python-h/pypy/translator/c/src/g_prerequisite.h	(original)
+++ pypy/branch/kill-python-h/pypy/translator/c/src/g_prerequisite.h	Wed Mar 17 16:00:29 2010
@@ -2,19 +2,9 @@
 /**************************************************************/
 /***  this is included before any code produced by genc.py  ***/
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE  /* this must be defined before including other headers
-                        in order to get a few extra functions like mremap() */
-#endif
+#include "src/commondefs.h"
 
-/* XXX for now we always include Python.h even to produce stand-alone
- * executables (which are *not* linked against CPython then),
- * to get the convenient macro definitions
- */
 #ifndef AVR
-#include "Python.h"
-
-
 #include "thread.h"   /* needs to be included early to define the
                          struct RPyOpaque_ThreadLock */
 #endif

Modified: pypy/branch/kill-python-h/pypy/translator/c/src/main.h
==============================================================================
--- pypy/branch/kill-python-h/pypy/translator/c/src/main.h	(original)
+++ pypy/branch/kill-python-h/pypy/translator/c/src/main.h	Wed Mar 17 16:00:29 2010
@@ -23,6 +23,12 @@
 
     instrument_setup();
 
+    if (sizeof(void*) != SIZEOF_LONG) {
+        errmsg = "only support platforms where sizeof(void*) == sizeof(long),"
+                 " for now";
+        goto error;
+    }
+
     errmsg = RPython_StartupCode();
     if (errmsg) goto error;
 

Modified: pypy/branch/kill-python-h/pypy/translator/c/src/obmalloc.c
==============================================================================
--- pypy/branch/kill-python-h/pypy/translator/c/src/obmalloc.c	(original)
+++ pypy/branch/kill-python-h/pypy/translator/c/src/obmalloc.c	Wed Mar 17 16:00:29 2010
@@ -1,4 +1,3 @@
-#include "Python.h"
 
 #ifdef WITH_PYMALLOC
 

Modified: pypy/branch/kill-python-h/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/branch/kill-python-h/pypy/translator/tool/cbuild.py	(original)
+++ pypy/branch/kill-python-h/pypy/translator/tool/cbuild.py	Wed Mar 17 16:00:29 2010
@@ -225,6 +225,7 @@
         return ExternalCompilationInfo(**attrs)
 
     def write_c_header(self, fileobj):
+        print >> fileobj, STANDARD_DEFINES
         for piece in self.pre_include_bits:
             print >> fileobj, piece
         for path in self.includes:
@@ -254,8 +255,6 @@
             f = filename.open("w")
             if being_main:
                 f.write("#define PYPY_NOT_MAIN_FILE\n")
-            if sys.platform == 'win32':
-                f.write("#define WIN32_LEAN_AND_MEAN\n")
             self.write_c_header(f)
             source = str(source)
             f.write(source)
@@ -292,3 +291,28 @@
         d['separate_module_files'] = ()
         d['separate_module_sources'] = ()
         return ExternalCompilationInfo(**d)
+
+
+# ____________________________________________________________
+#
+# This is extracted from pyconfig.h from CPython.  It sets the macros
+# that affect the features we get from system include files.
+
+STANDARD_DEFINES = '''
+/* Define on Darwin to activate all library features */
+#define _DARWIN_C_SOURCE 1
+/* This must be set to 64 on some systems to enable large file support. */
+#define _FILE_OFFSET_BITS 64
+/* Define on Linux to activate all library features */
+#define _GNU_SOURCE 1
+/* This must be defined on some systems to enable large file support. */
+#define _LARGEFILE_SOURCE 1
+/* Define on NetBSD to activate all library features */
+#define _NETBSD_SOURCE 1
+/* Define to activate features from IEEE Stds 1003.1-2001 */
+#define _POSIX_C_SOURCE 200112L
+/* Define on FreeBSD to activate all library features */
+#define __BSD_VISIBLE 1
+/* Windows: winsock/winsock2 mess */
+#define WIN32_LEAN_AND_MEAN
+'''



More information about the Pypy-commit mailing list