1// 2// embed.i 3// SWIG file embedding the Python interpreter in something else. 4// This file is based on Python-1.5. It will not work with 5// earlier versions. 6// 7// This file makes it possible to extend Python and all of its 8// built-in functions without having to hack its setup script. 9// 10 11 12#ifdef AUTODOC 13%subsection "embed.i" 14%text %{ 15This module provides support for building a new version of the 16Python executable. This will be necessary on systems that do 17not support shared libraries and may be necessary with C++ 18extensions. This file contains everything you need to build 19a new version of Python from include files and libraries normally 20installed with the Python language. 21 22This module will automatically grab all of the Python modules 23present in your current Python executable (including any special 24purpose modules you have enabled such as Tkinter). Thus, you 25may need to provide additional link libraries when compiling. 26 27This library file only works with Python 1.5. A version 28compatible with Python 1.4 is available as embed14.i and 29a Python1.3 version is available as embed13.i. As far as 30I know, this module is C++ safe. 31%} 32#else 33%echo "embed.i : Using Python 1.5" 34#endif 35 36%wrapper %{ 37 38#include <Python.h> 39 40#ifdef __cplusplus 41extern "C" 42#endif 43void SWIG_init(); /* Forward reference */ 44 45#define _PyImport_Inittab swig_inittab 46 47/* Grab Python's inittab[] structure */ 48 49#ifdef __cplusplus 50extern "C" { 51#endif 52#include <config.c> 53 54#undef _PyImport_Inittab 55 56/* Now define our own version of it. 57 Hopefully someone does not have more than 1000 built-in modules */ 58 59struct _inittab SWIG_Import_Inittab[1000]; 60 61static int swig_num_modules = 0; 62 63/* Function for adding modules to Python */ 64 65static void swig_add_module(char *name, void (*initfunc)()) { 66 SWIG_Import_Inittab[swig_num_modules].name = name; 67 SWIG_Import_Inittab[swig_num_modules].initfunc = initfunc; 68 swig_num_modules++; 69 SWIG_Import_Inittab[swig_num_modules].name = (char *) 0; 70 SWIG_Import_Inittab[swig_num_modules].initfunc = 0; 71} 72 73/* Function to add all of Python's build in modules to our interpreter */ 74 75static void swig_add_builtin() { 76 int i = 0; 77 while (swig_inittab[i].name) { 78 swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc); 79 i++; 80 } 81#ifdef SWIGMODINIT 82 SWIGMODINIT 83#endif 84 /* Add SWIG builtin function */ 85 swig_add_module(SWIG_name, SWIG_init); 86} 87 88#ifdef __cplusplus 89} 90#endif 91 92#ifdef __cplusplus 93extern "C" { 94#endif 95 96extern int Py_Main(int, char **); 97 98#ifdef __cplusplus 99} 100#endif 101 102extern struct _inittab *PyImport_Inittab; 103 104int 105main(int argc, char **argv) { 106 swig_add_builtin(); 107 PyImport_Inittab = SWIG_Import_Inittab; 108 return Py_Main(argc,argv); 109} 110 111%} 112 113 114 115 116