[Pythonmac-SIG] dlopenflags and sharing symbols across python extension modules

Zachary Pincus zpincus at stanford.edu
Fri Mar 10 23:25:44 CET 2006


> If you come up with a patch for (2) against Python's svn trunk that  
> is tested and works on 10.2 then I'll commit it.  It's not  
> appropriate to make this sort of change against Python 2.4,  
> though.  *Maybe* for the universal branch that Ronald and I are  
> doing, because that's also unlikely to be merged with the 2.4 branch.

Well, after wasting the better part of a day tracking down a computer  
capable of running 10.2, installing 10.2 on it, getting the latest  
updates and the newest 10.2 developer tools, I find that neither  
python 2.5 from svn (today's snapshot or a checkout from the 8th)  
*NOR* the svn snapshot of python 2.4 will build on 10.2.8.

Is python 2.5 (or even 2.4) supposed to be officially supported for  
10.2? (It certainly doesn't seem to be based on what's on the python  
web pages.) If not, I rather resent the goose chase I've been sent on  
just trying to submit a patch to get python to work the way the  
documentation says it does.

Anyhow, I was able to get python on 10.2 configure properly, which is  
all that the patch changes. So if python 2.5 ever were to work on  
10.2, my patch wouldn't prevent that.

Here's the patch. This includes a change to setup.py to build the dl  
module if dlfcn.h is available (which it is not on 10.2, so no  
incompatibility worries there either). I think this latter change is  
important because the 'standard idiom' for setting dlopenflags looks  
like this:
import dl
sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_NOW)
(as noted in the standard docs: http://docs.python.org/lib/module- 
sys.html )

If sys.setdlopenflags() is going to be respected, dl should be  
available to allow the flags to be looked up. (I know the ctypes  
module provides some of these flags, but given that the idiom on  
other platforms has been to use the dl module, not including dl when  
it could be seems like arbitrary breakage.)

Zach


Patch follows:

Index: configure
===================================================================
--- configure   (revision 42924)
+++ configure   (working copy)
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 42437 .
+# From configure.in Revision: 42563 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for python 2.5.
#
@@ -13974,7 +13974,8 @@
         ;;
         BeOS*) DYNLOADFILE="dynload_beos.o";;
         hp*|HP*) DYNLOADFILE="dynload_hpux.o";;
-       Darwin/*) DYNLOADFILE="dynload_next.o";;
+       # Use dynload_next.c only on 10.2 and below, which don't have  
native dlopen()
+       Darwin/[0123456].*) DYNLOADFILE="dynload_next.o";;
         atheos*) DYNLOADFILE="dynload_atheos.o";;
         *)
         # use dynload_shlib.c and dlopen() if we have it; otherwise  
stub
Index: configure.in
===================================================================
--- configure.in        (revision 42924)
+++ configure.in        (working copy)
@@ -2105,7 +2105,8 @@
         ;;
         BeOS*) DYNLOADFILE="dynload_beos.o";;
         hp*|HP*) DYNLOADFILE="dynload_hpux.o";;
-       Darwin/*) DYNLOADFILE="dynload_next.o";;
+       # Use dynload_next.c only on 10.2 and below, which don't have  
native dlopen()
+       Darwin/@<:@0123456@:>@.*) DYNLOADFILE="dynload_next.o";;
         atheos*) DYNLOADFILE="dynload_atheos.o";;
         *)
         # use dynload_shlib.c and dlopen() if we have it; otherwise  
stub
Index: setup.py
===================================================================
--- setup.py    (revision 42924)
+++ setup.py    (working copy)
@@ -885,7 +885,7 @@
          if sys.maxint == 0x7fffffff:
              # This requires sizeof(int) == sizeof(long) == sizeof 
(char*)
              dl_inc = find_file('dlfcn.h', [], inc_dirs)
-            if (dl_inc is not None) and (platform not in ['atheos',  
'darwin']):
+            if (dl_inc is not None) and (platform not in ['atheos']):
                  exts.append( Extension('dl', ['dlmodule.c']) )
          # Thomas Heller's _ctypes module




More information about the Pythonmac-SIG mailing list