]> granicus.if.org Git - python/commitdiff
enable darwin/x86 support for libffi and hence ctypes (doesn't yet support --enable...
authorBob Ippolito <bob@redivi.com>
Thu, 25 May 2006 19:59:56 +0000 (19:59 +0000)
committerBob Ippolito <bob@redivi.com>
Thu, 25 May 2006 19:59:56 +0000 (19:59 +0000)
Modules/_ctypes/libffi/configure
Modules/_ctypes/libffi/configure.ac
Modules/_ctypes/libffi/fficonfig.h.in
Modules/_ctypes/libffi/fficonfig.py.in
Modules/_ctypes/libffi/src/powerpc/darwin.S
Modules/_ctypes/libffi/src/powerpc/darwin_closure.S
Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c
Modules/_ctypes/libffi/src/prep_cif.c
Modules/_ctypes/libffi/src/x86/ffitarget.h

index 27abbecbb3e6af46966beef4a3a23e476d8610b0..9fdd65497125de3d54e656d32cf8cdead5275244 100755 (executable)
@@ -3483,6 +3483,7 @@ fi
 
 TARGETDIR="unknown"
 case "$host" in
+i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
 i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
 i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
 i*86-*-solaris2.1[0-9]*) TARGET=X86_64; TARGETDIR=x86;;
@@ -5243,6 +5244,9 @@ presetting ac_cv_c_bigendian=no (or yes) will help" >&2;}
 esac
 
 
+
+
+
 if test x$TARGET = xSPARC; then
     echo "$as_me:$LINENO: checking assembler and linker support unaligned pc related relocs" >&5
 echo $ECHO_N "checking assembler and linker support unaligned pc related relocs... $ECHO_C" >&6
@@ -5470,7 +5474,15 @@ _ACEOF
           ac_config_commands="$ac_config_commands src"
 
 
-          ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETDIR/ffitarget.h"
+TARGETINCDIR=$TARGETDIR
+case $host in
+*-*-darwin*)
+   TARGETINCDIR="darwin"
+   ;;
+esac
+
+
+          ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h"
 
           ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h"
 
@@ -6017,7 +6029,7 @@ do
   # Handling of arguments.
   "include/ffi.h" ) CONFIG_FILES="$CONFIG_FILES include/ffi.h" ;;
   "fficonfig.py" ) CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;;
-  "include/ffitarget.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETDIR/ffitarget.h" ;;
+  "include/ffitarget.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h" ;;
   "include/ffi_common.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;;
   "include" ) CONFIG_COMMANDS="$CONFIG_COMMANDS include" ;;
   "src" ) CONFIG_COMMANDS="$CONFIG_COMMANDS src" ;;
index 6dafe35fe86202fa49d77a9ba4e231555991acca..a0d75131c37493ff3d610c7ca0a53d92c4dd3b99 100644 (file)
@@ -21,6 +21,7 @@ AC_FUNC_MMAP_BLACKLIST
 
 TARGETDIR="unknown"
 case "$host" in
+i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;;
 i*86-*-linux*) TARGET=X86; TARGETDIR=x86;;
 i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;;
 i*86-*-solaris2.1[[0-9]]*) TARGET=X86_64; TARGETDIR=x86;;
@@ -99,6 +100,24 @@ fi
 AC_SUBST(HAVE_LONG_DOUBLE)
 
 AC_C_BIGENDIAN
+AH_VERBATIM([WORDS_BIGENDIAN],
+[
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). 
+
+   The block below does compile-time checking for endianness on platforms
+   that use GCC and therefore allows compiling fat binaries on OSX by using
+   '-arch ppc -arch i386' as the compile flags. The phrasing was choosen
+   such that the configure-result is used on systems that don't use GCC.
+*/
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN 1
+#else
+#ifndef __LITTLE_ENDIAN__
+#undef WORDS_BIGENDIAN
+#endif
+#endif])
+
 
 if test x$TARGET = xSPARC; then
     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
@@ -201,7 +220,15 @@ test -d src || mkdir src
 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
 ], [TARGETDIR="$TARGETDIR"])
 
-AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
+TARGETINCDIR=$TARGETDIR
+case $host in
+*-*-darwin*)
+   TARGETINCDIR="darwin"
+   ;;
+esac
+
+
+AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h)
 AC_CONFIG_LINKS(include/ffi_common.h:include/ffi_common.h)
 
 AC_CONFIG_FILES(include/ffi.h fficonfig.py)
index 0fd2db559472dea78a0de2c58ebe81df5d11b6fb..bcc5a58d40dbd4ae210975cac20698742016c20f 100644 (file)
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+
 /* Define to 1 if your processor stores words with the most significant byte
-   first (like Motorola and SPARC, unlike Intel and VAX). */
+   first (like Motorola and SPARC, unlike Intel and VAX). 
+
+   The block below does compile-time checking for endianness on platforms
+   that use GCC and therefore allows compiling fat binaries on OSX by using
+   '-arch ppc -arch i386' as the compile flags. The phrasing was choosen
+   such that the configure-result is used on systems that don't use GCC.
+*/
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN 1
+#else
+#ifndef __LITTLE_ENDIAN__
 #undef WORDS_BIGENDIAN
+#endif
+#endif
 
 
 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
index 89f79693b338ced3f8678a4e1eabed8ac7146d30..1a7a67a8193ef9bac8cd6e5542a86b9b14e510d0 100644 (file)
@@ -6,6 +6,7 @@ ffi_platforms = {
     'MIPS_IRIX': ['src/mips/ffi.c', 'src/mips/o32.S', 'src/mips/n32.S'],
     'MIPS_LINUX': ['src/mips/ffi.c', 'src/mips/o32.S'],
     'X86': ['src/x86/ffi.c', 'src/x86/sysv.S'],
+    'X86_DARWIN': ['src/x86/ffi_darwin.c', 'src/x86/darwin.S'],
     'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'],
     'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'],
     'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'],
@@ -26,6 +27,17 @@ ffi_platforms = {
     'PA': ['src/pa/linux.S', 'src/pa/ffi.c'],
 }
 
+# Build all darwin related files on all supported darwin architectures, this
+# makes it easier to build universal binaries.
+if 0:
+    all_darwin = ('X86_DARWIN', 'POWERPC_DARWIN')
+    all_darwin_files = []
+    for pn in all_darwin:
+        all_darwin_files.extend(ffi_platforms[pn])
+    for pn in all_darwin:
+        ffi_platforms[pn] = all_darwin_files
+    del all_darwin, all_darwin_files, pn
+
 ffi_srcdir = '@srcdir@'
 ffi_sources += ffi_platforms['@MKTARGET@']
 ffi_sources = [os.path.join('@srcdir@', f) for f in ffi_sources]
index d8a1df5fe98622783b2cf92d105691e59f97b040..917dc9328699e30931a358f4495cffdc90de1c1e 100644 (file)
@@ -1,3 +1,4 @@
+#ifdef __ppc__
 /* -----------------------------------------------------------------------
    darwin.S - Copyright (c) 2000 John Hornkvist
              Copyright (c) 2004 Free Software Foundation, Inc.
@@ -243,3 +244,4 @@ LEFDE1:
        .align LOG2_GPR_BYTES
 LLFB0$non_lazy_ptr:
        .g_long LFB0
+#endif
index 6d9a364095e31a1ca98397ad858129451e3a005a..71054f5f06760b2219ea710e47d488b8dd15cfb1 100644 (file)
@@ -1,3 +1,4 @@
+#ifdef __ppc__
 /* -----------------------------------------------------------------------
    darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation,
    Inc. based on ppc_closure.S
@@ -315,3 +316,4 @@ L_ffi_closure_helper_DARWIN$lazy_ptr:
        .align LOG2_GPR_BYTES
 LLFB1$non_lazy_ptr:
        .g_long LFB1
+#endif
index 9337e66574e616a23166a36893ebb3fb1f1ed896..1595b00a5ff1dcfcb7296482aba426db721bbec7 100644 (file)
@@ -1,3 +1,4 @@
+#ifdef __ppc__
 /* -----------------------------------------------------------------------
    ffi.c - Copyright (c) 1998 Geoffrey Keating
 
@@ -767,3 +768,4 @@ int ffi_closure_helper_DARWIN (ffi_closure* closure, void * rvalue,
   /* Tell ffi_closure_ASM to perform return type promotions.  */
   return cif->rtype->type;
 }
+#endif
index 0faa5ddeaa3893ea5fa2765fff9646279cea63ec..8d76718cdcc9b26a51514061a97913c85798f954 100644 (file)
@@ -55,11 +55,29 @@ static ffi_status initialize_aggregate(/*@out@*/ ffi_type *arg)
       /* Perform a sanity check on the argument type */
       FFI_ASSERT_VALID_TYPE(*ptr);
 
+#ifdef POWERPC_DARWIN
+      {
+             int curalign;
+
+             curalign = (*ptr)->alignment;
+             if (ptr != &(arg->elements[0])) {
+                     if (curalign > 4 && curalign != 16) {
+                             curalign = 4;
+                     }
+             }
+      arg->size = ALIGN(arg->size, curalign);
+      arg->size += (*ptr)->size;
+
+      arg->alignment = (arg->alignment > curalign) ? 
+             arg->alignment : curalign;
+      }
+#else
       arg->size = ALIGN(arg->size, (*ptr)->alignment);
       arg->size += (*ptr)->size;
 
       arg->alignment = (arg->alignment > (*ptr)->alignment) ? 
        arg->alignment : (*ptr)->alignment;
+#endif
 
       ptr++;
     }
@@ -89,6 +107,19 @@ static ffi_status initialize_aggregate(/*@out@*/ ffi_type *arg)
 /* Perform machine independent ffi_cif preparation, then call
    machine dependent routine. */
 
+#ifdef X86_DARWIN
+static inline int struct_on_stack(int size)
+{
+       if (size > 8) return 1;
+       /* This is not what the ABI says, but is what is really implemented */
+       switch (size) {
+       case 1: case 2: case 4: case 8: return 0;
+       return 1;
+       }
+}
+#endif
+
+
 ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, 
                        ffi_abi abi, unsigned int nargs, 
                        /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, 
@@ -123,6 +154,10 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif,
   if (cif->rtype->type == FFI_TYPE_STRUCT
 #ifdef SPARC
       && (cif->abi != FFI_V9 || cif->rtype->size > 32)
+#endif
+#ifdef X86_DARWIN
+
+      && (struct_on_stack(cif->rtype->size))
 #endif
       )
     bytes = STACK_ARG_SIZE(sizeof(void*));
@@ -139,7 +174,16 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif,
         check after the initialization.  */
       FFI_ASSERT_VALID_TYPE(*ptr);
 
-#if !defined __x86_64__ && !defined S390 && !defined PA
+#if defined(X86_DARWIN)
+      {
+             int align = (*ptr)->alignment;
+             if (align > 4) align = 4;
+             if ((align - 1) & bytes)
+                bytes = ALIGN(bytes, align);
+             bytes += STACK_ARG_SIZE((*ptr)->size);
+      }
+
+#elif !defined __x86_64__ && !defined S390 && !defined PA
 #ifdef SPARC
       if (((*ptr)->type == FFI_TYPE_STRUCT
           && ((*ptr)->size > 16 || cif->abi != FFI_V9))
index 9500f40aa8013e5799943a87eeca52d031be64e0..8b20d3c7af052cdfc3d749ba97d4f22dfa38db2e 100644 (file)
@@ -51,7 +51,7 @@ typedef enum ffi_abi {
 #endif
 
   /* ---- Intel x86 and AMD x86-64 - */
-#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__))
+#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) 
   FFI_SYSV,
   FFI_UNIX64,   /* Unix variants all use the same ABI for x86-64  */
 #ifdef __i386__