From owner-freebsd-python@FreeBSD.ORG  Sat May 17 11:25:14 2008
Return-Path: <owner-freebsd-python@FreeBSD.ORG>
Delivered-To: python@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C16061065670
	for <python@freebsd.org>; Sat, 17 May 2008 11:25:14 +0000 (UTC)
	(envelope-from mjl@luckie.org.nz)
Received: from mailfilter14.ihug.co.nz (mailfilter14.ihug.co.nz
	[203.109.136.14])
	by mx1.freebsd.org (Postfix) with ESMTP id 6C92D8FC14
	for <python@freebsd.org>; Sat, 17 May 2008 11:25:14 +0000 (UTC)
	(envelope-from mjl@luckie.org.nz)
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: ApsEANpWLkjLbboE/2dsb2JhbACBVasH
X-IronPort-AV: E=Sophos;i="4.27,500,1204455600"; d="scan'208";a="12757631"
Received: from 203-109-186-4.dsl.dyn.ihug.co.nz (HELO spandex.luckie.org.nz)
	([203.109.186.4])
	by smtp.mailfilter6.ihug.co.nz with ESMTP/TLS/DHE-RSA-AES256-SHA;
	17 May 2008 22:56:02 +1200
Received: from mjl by spandex.luckie.org.nz with local (Exim 4.69 (FreeBSD))
	(envelope-from <mjl@luckie.org.nz>) id 1JxK57-000Bop-5v
	for python@freebsd.org; Sat, 17 May 2008 22:56:05 +1200
Date: Sat, 17 May 2008 22:56:05 +1200
From: Matthew Luckie <mjl@luckie.org.nz>
To: python@freebsd.org
Message-ID: <20080517105604.GA25783@spandex.luckie.org.nz>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.4.2.3i
Cc: 
Subject: python25 _ctypes module on arm
X-BeenThere: freebsd-python@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: FreeBSD-specific Python issues <freebsd-python.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-python>, 
	<mailto:freebsd-python-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-python>
List-Post: <mailto:freebsd-python@freebsd.org>
List-Help: <mailto:freebsd-python-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-python>,
	<mailto:freebsd-python-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 17 May 2008 11:25:14 -0000

The python _ctypes module is not built on arm.  This is mainly because
Modules/_ctypes/libffi/configure does not have the magic glue for
arm-*-freebsd* but also because _ctypes.c assumes ffi_closure is available
(which it isn't in the libffi included with the Python distribution for
arm)

However, the configure script for python allows for linking against a
system libffi, which seems to work ok on arm anyway.

Is the following patch acceptable?  Note that it relies on a small change to
libffi port (which is included below and has been submitted as a PR, I
predict number 123754 (though it hasn't been assigned a number just
yet)

>>> from ctypes import *
>>> cdll.LoadLibrary("libc.so.7")
>>> libc = CDLL("libc.so.7")
>>> print libc.time(None)
0
>>> print libc.time      
<_FuncPtr object at 0x2031877c>
>>> printf = libc.printf
>>> printf("Hello, %s\n", "World!")
Hello, World!
14
>>> printf("An int %d, a double %f\n", 1234, c_double(3.14))
An int 1234, a double 3.140000
31

Note that the libc.time function should not return zero, i'm not sure
why that is but I imagine it might have something to do with time_t being
64 bits on arm.

--- python25.orig/Makefile      Sat Apr 26 07:01:46 2008
+++ python25/Makefile   Sat May 17 17:55:26 2008
@@ -103,6 +103,12 @@
 .if ${ARCH} == sparc64
 CFLAGS+=        -DPYTHON_DEFAULT_RECURSION_LIMIT=900
 .endif
+.if ${ARCH} == arm
+CONFIGURE_ARGS+=       --with-system-ffi
+LIB_DEPENDS+=          ffi.5:${PORTSDIR}/devel/libffi
+CONFIGURE_ENV+=                CFLAGS="${CFLAGS} -I${LOCALBASE}/include"
+CONFIGURE_ENV+=                LIBS="-L${LOCALBASE}/lib"
+.endif
 
 .if !exists(/usr/bin/ypcat) # the world with NO_NIS
 PLIST_SUB+=    NO_NIS="@comment "


=========================


diff -uNr libffi.orig/files/patch-include-Makefile.in libffi/files/patch-include
-Makefile.in
--- libffi.orig/files/patch-include-Makefile.in Thu Jan  1 12:00:00 1970
+++ libffi/files/patch-include-Makefile.in      Sat May 17 21:02:36 2008
@@ -0,0 +1,11 @@
+--- include/Makefile.in.orig   2008-05-17 21:00:01.000000000 +1200
++++ include/Makefile.in        2008-05-17 21:01:39.000000000 +1200
+@@ -182,7 +182,7 @@
+ AUTOMAKE_OPTIONS = foreign
+ DISTCLEANFILES = ffitarget.h
+ EXTRA_DIST = ffi.h.in ffi_common.h
+-includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
++includesdir = @includedir@
+ nodist_includes_HEADERS = ffi.h ffitarget.h 
+ all: all-am
+ 
diff -uNr libffi.orig/files/patch-libffi.pc.in libffi/files/patch-libffi.pc.in
--- libffi.orig/files/patch-libffi.pc.in        Thu Jan  1 12:00:00 1970
+++ libffi/files/patch-libffi.pc.in     Sat May 17 20:58:36 2008
@@ -0,0 +1,11 @@
+--- libffi.pc.in.orig  2008-05-17 20:56:19.000000000 +1200
++++ libffi.pc.in       2008-05-17 20:58:09.000000000 +1200
+@@ -1,7 +1,7 @@
+ prefix=@prefix@
+ exec_prefix=@exec_prefix@
+ libdir=@libdir@
+-includedir=${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
++includedir=@includedir@
+ 
+ Name: @PACKAGE_NAME@
+ Description: Library supporting Foreign Function Interfaces
diff -uNr libffi.orig/pkg-plist libffi/pkg-plist
--- libffi.orig/pkg-plist       Sat Apr  5 07:00:51 2008
+++ libffi/pkg-plist    Sat May 17 21:04:53 2008
@@ -1,9 +1,7 @@
-lib/libffi-%%PORTVERSION%%/include/ffi.h
-lib/libffi-%%PORTVERSION%%/include/ffitarget.h
+include/ffi.h
+include/ffitarget.h
 lib/libffi.a
 lib/libffi.la
 lib/libffi.so
 lib/libffi.so.5
 libdata/pkgconfig/libffi.pc
-@dirrm lib/libffi-%%PORTVERSION%%/include
-@dirrm lib/libffi-%%PORTVERSION%%