[Python-bugs-list] Re: SWIG's embed.i and Python 1.5.2 on WinNT (PR#27)

fp@contact.de fp@contact.de
Wed, 14 Jul 1999 13:49:14 -0400 (EDT)


Guido van Rossum wrote:
> > SWIG automatically generates scripting language bindings
> > for C libraries.
> 
> I knew that :-)

I guess you do. Just in case :-)

> > It provides a feature to build a standalone
> > interpreter that contains the wrapper module and all the
> > standard builtin modules of Python. For that purpose the
> > SWIG-generated module source provides its own `main',
> > "grabs" Python's inittab[] structure, adds the wrapper
> > module, sets PyImport_Inittab to the patched inittab and
> > calls Py_Main(). The generated source looks like this
> > (with some omissions):
> >
> >       #define _PyImport_Inittab swig_inittab
> >       /* Grab Python's inittab[] structure */
> >
> >       #include <config.c> /* This is Pythons's config.c! */
> >
> >       #undef _PyImport_Inittab
> >
> >       /* Now define our own version of it.
> >          Hopefully someone does not have more than 1000
> >          built-in modules */
> >
> >       struct _inittab _SwigImport_Inittab[1000];
> >
> >       [...]
> >
> >       int
> >       main(int argc, char **argv) {
> >               swig_add_builtin(); /* add wrapper module */
> >               PyImport_Inittab = _SwigImport_Inittab;
> >               return Py_Main(argc,argv);
> >       }
> 
> I'm not sure I understand what this has to do with your original
> request.  Do you still think it requires a patch to Python?

The problem is that PyImport_Inittab lives in the DLL. It needs
to be exported since main() assigns to it. _SwigImport_Inittab
lives in my .EXE and has references to initimp, PyMarshal_Init
and initsha, and so those need to be exported too.
The initialization functions of all the other builtin modules
are declared "DL_EXPORT"; that was the reason I thougt initimp
etc. have been left out unintentionally.

> Also Python has a better way to manipulate the inittab than to play
> dirty preprocessor tricks.  There's a whole API to deal with it:
> PyImport_ExtendInittab(), PyImport_AppendInittab().

Seems to be a much cleaner way to do the same. The thing to be
changed is SWIG, I think. I will check that with Dave Beazley.

Thank you for your help,
	Frank

-- 
Frank Patz
CONTACT Software GmbH                 email: fp@contact.de
Wiener Str. 1-3                       phone: +49 421 20153 18
D-28359 Bremen                        fax:   +49 421 20153 41