[Python-bugs-list] Re: SWIG's embed.i and Python 1.5.2 on WinNT (PR#25)
fp@contact.de
fp@contact.de
Wed, 14 Jul 1999 12:34:51 -0400 (EDT)
Hi Guido,
SWIG automatically generates scripting language bindings
for C libraries. 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);
}
If you allow, I'd like to forward your questions to Dave Beazley
(beazley@cs.uchicago.edu), the author of SWIG.
- frank
P.S. Sorry for the duplicate PR#26. I was braindead and
pressed "Reload".
Guido van Rossum wrote:
> I don't think that exporting module initialization calls is the right
> solution. I don't know SWIG -- why is it calling these functions?
> If you reference some other extension module, will it require that
> module's init function to be exported? On Unix, will it fail if those
> extensions happen to be dynamically loaded instead of statically linked?
>
> A better approach would be to use the PyImport_ImportModule()
> function to import the module by name. This will find the module
> you're looking for regardless of whether it is built in or provided
> as a shared library.
--
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