[Python-checkins] r46249 - in python/trunk/Modules/_ctypes/libffi: configure configure.ac fficonfig.h.in fficonfig.py.in src/powerpc/darwin.S src/powerpc/darwin_closure.S src/powerpc/ffi_darwin.c src/prep_cif.c src/x86/ffitarget.h

bob.ippolito python-checkins at python.org
Thu May 25 21:59:58 CEST 2006


Author: bob.ippolito
Date: Thu May 25 21:59:56 2006
New Revision: 46249

Modified:
   python/trunk/Modules/_ctypes/libffi/configure
   python/trunk/Modules/_ctypes/libffi/configure.ac
   python/trunk/Modules/_ctypes/libffi/fficonfig.h.in
   python/trunk/Modules/_ctypes/libffi/fficonfig.py.in
   python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin.S
   python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S
   python/trunk/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c
   python/trunk/Modules/_ctypes/libffi/src/prep_cif.c
   python/trunk/Modules/_ctypes/libffi/src/x86/ffitarget.h
Log:
enable darwin/x86 support for libffi and hence ctypes (doesn't yet support --enable-universalsdk)

Modified: python/trunk/Modules/_ctypes/libffi/configure
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/configure	(original)
+++ python/trunk/Modules/_ctypes/libffi/configure	Thu May 25 21:59:56 2006
@@ -3483,6 +3483,7 @@
 
 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 @@
 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 @@
           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 @@
   # 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" ;;

Modified: python/trunk/Modules/_ctypes/libffi/configure.ac
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/configure.ac	(original)
+++ python/trunk/Modules/_ctypes/libffi/configure.ac	Thu May 25 21:59:56 2006
@@ -21,6 +21,7 @@
 
 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 @@
 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/$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)

Modified: python/trunk/Modules/_ctypes/libffi/fficonfig.h.in
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/fficonfig.h.in	(original)
+++ python/trunk/Modules/_ctypes/libffi/fficonfig.h.in	Thu May 25 21:59:56 2006
@@ -114,9 +114,22 @@
 /* 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

Modified: python/trunk/Modules/_ctypes/libffi/fficonfig.py.in
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/fficonfig.py.in	(original)
+++ python/trunk/Modules/_ctypes/libffi/fficonfig.py.in	Thu May 25 21:59:56 2006
@@ -6,6 +6,7 @@
     '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 @@
     '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]

Modified: python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin.S
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin.S	(original)
+++ python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin.S	Thu May 25 21:59:56 2006
@@ -1,3 +1,4 @@
+#ifdef __ppc__
 /* -----------------------------------------------------------------------
    darwin.S - Copyright (c) 2000 John Hornkvist
 	      Copyright (c) 2004 Free Software Foundation, Inc.
@@ -243,3 +244,4 @@
 	.align LOG2_GPR_BYTES
 LLFB0$non_lazy_ptr:
 	.g_long LFB0
+#endif

Modified: python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S	(original)
+++ python/trunk/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S	Thu May 25 21:59:56 2006
@@ -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 @@
 	.align LOG2_GPR_BYTES
 LLFB1$non_lazy_ptr:
 	.g_long LFB1
+#endif

Modified: python/trunk/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c	(original)
+++ python/trunk/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c	Thu May 25 21:59:56 2006
@@ -1,3 +1,4 @@
+#ifdef __ppc__
 /* -----------------------------------------------------------------------
    ffi.c - Copyright (c) 1998 Geoffrey Keating
 
@@ -767,3 +768,4 @@
   /* Tell ffi_closure_ASM to perform return type promotions.  */
   return cif->rtype->type;
 }
+#endif

Modified: python/trunk/Modules/_ctypes/libffi/src/prep_cif.c
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/src/prep_cif.c	(original)
+++ python/trunk/Modules/_ctypes/libffi/src/prep_cif.c	Thu May 25 21:59:56 2006
@@ -55,11 +55,29 @@
       /* 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 @@
 /* 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, 
@@ -124,6 +155,10 @@
 #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*));
 #endif
@@ -139,7 +174,16 @@
 	 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))

Modified: python/trunk/Modules/_ctypes/libffi/src/x86/ffitarget.h
==============================================================================
--- python/trunk/Modules/_ctypes/libffi/src/x86/ffitarget.h	(original)
+++ python/trunk/Modules/_ctypes/libffi/src/x86/ffitarget.h	Thu May 25 21:59:56 2006
@@ -51,7 +51,7 @@
 #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__


More information about the Python-checkins mailing list