_Files vs __files (&1.4 vs 1.5a3) was: [PYTHONMAC-SIG] Mac SWIG &
dynamic loading MacPython modules
Steven D. Majewski
sdm7g@Virginia.EDU
15 Sep 97 14:38:28 -0400
An old thread, so first, some history:
Long, long ago, I wrote:
>Has anyone gotten MacSWIG to work with dynamically loaded Python
>modules ? I keep getting link problems with the global "__file"
>variable, which I assume, should not be exported from PythonCorePPC, [...]
On Thu, May 29, 1997 5:41 AM, Jack Jansen <mailto:Jack.Jansen@cwi.nl>
wrote:
>
>It should definitely be exported from PythonCorePPC, otherwise you can't
use
>stdio in your extension. The trick is that you should put PythonCorePPC
>*before* the C library in your link sequence, so that the __file symbol
(and
>any other shared global data) is resolved from PythonCorePPC.
>
>This is documented somewhere, but the fact that I can't find it right now
>suggests that it might be stated a bit more clearly:-)
>
I had found my own temporary hack (below), which I thought might have
dangerous side effects, but did appear to work, and, as I wasn't yet trying
to seriously use SWIG, I didn't pursue Jack's solution
>added console.stubs.c to project.
>
>added two lines to my wrapper function:
>
> #include <stdio.h>
> FILE __files[FOPEN_MAX];
>
>and the SWIG example code builds (with CW11), imports, dynamically
>loads and appears to run without crashing.
>
However, on delving into this further I find:
Jack's suggestion does not work with MacPython 1.4 --
There is a "_Files" among the exported symbols, but not a "__files"
( Checking both in the export file in the source distrib, and using DumpPEF
to look at the symbol table from the PPC lib in the binary distribution. )
DumpPEF show that the symbol "__files" does appear in "PythonCore 1.5a3"
Replacing the 1.4 PythonCorePPC with than one and rebuilding does link
without any errors. Running Python 1.5a3 and importing the example
module produces this warning ( however, the module does appear to work
properly. )
Python 1.5a3 (#0, Aug 4 1997, 16:50:52) [CW PPC w/GUSI w/MSL]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import example
WARNING: Python C API version mismatch for module example:
This Python has API version 1007, module example has version 1006.
>>> dir()
['__builtins__', '__doc__', '__name__', 'example']
>>> dir(example)
['__doc__', '__file__', '__name__', 'cvar', 'fact', 'get_time', 'mod']
>>> example.__file__
'example.ppc.slb'
>>> example.cvar
Global variables { My_variable }
>>> example.fact
<built-in function fact>
>>> example.fact(7)
5040
>>> example.get_time()
'Mon Sep 15 14:01:31 1997\012'
>>> example.mod(7,4 )
3
>>>
- Steve Majewski
_______________
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________