[Distutils] Sharing code between C extensions
Jack Jansen
Jack.Jansen@oratrix.com
Mon Oct 21 18:08:02 2002
On maandag, oktober 21, 2002, at 01:27 , Anders J. Munch wrote:
> What I'd like to do is to have multiple C extensions in the same .pyd.
All attempts to do this lead to disaster. If it isn't on your
platform it is on another one. And the same is true for multiple
.pyd files, each containing a single module, that link against
each other. (I know: been there, done that:-)
There's two solutions I use for this, but you'd have to work out
the distutils magic for yourself:
1. Use a normal shared library (.dll, .so) for the shared code
and/or the glue between the modules. Use a shared-data DLL if
you need to share data. On some OSes you can get away with
putting the dll in the same directory as the pyd's, on others
you may have to install it in a system location. PythonWin does
something like this with PyWinTypes. MacPython does it with a
little help from the core.
2. Use Python's import mechanism. In module A's init() routine
import module B. Call a special method in B that returns a
pointer (coded a Python integer or Cobject or some such). You
now have a pointer from one module to the other. Numeric does
this.
--
- Jack Jansen <Jack.Jansen@oratrix.com>
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution --
Emma Goldman -