embed15.i 2.8 KB

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