Since I have made several changes to SWIG over the years to accomodate

special cases and other things in wxPython, and since I plan on making
several more, I've decided to put the SWIG sources in wxPython's CVS
instead of relying on maintaining patches.  This effectivly becomes a
fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
doesn't have some things I rely on in 1.1, not to mention that my
custom patches would all have to be redone, I felt that this is the
easier road to take.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-04-29 19:56:57 +00:00
parent 3bd1e03385
commit c90f71dd8c
135 changed files with 51307 additions and 1 deletions

View File

@@ -0,0 +1,137 @@
# Generated automatically from Makefile.in by configure.
# ---------------------------------------------------------------
# $Header$
# SWIG Python Makefile
#
# This file can be used to build various Python extensions with SWIG.
# By default this file is set up for dynamic loading, but it can
# be easily customized for static extensions by modifying various
# portions of the file.
#
# SRCS = C source files
# CXXSRCS = C++ source files
# OBJCSRCS = Objective-C source files
# OBJS = Additional .o files (compiled previously)
# INTERFACE = SWIG interface file
# TARGET = Name of target module or executable
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module.so # Use this kind of target for dynamic loading
#TARGET = mypython # Use this target for static linking
prefix = /usr/local
exec_prefix = ${prefix}
CC = cc
CXX = CC
OBJC = cc -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# SWIG Options
# SWIG = location of the SWIG executable
# SWIGOPT = SWIG compiler options
# SWIGCC = Compiler used to compile the wrapper file
SWIG = $(exec_prefix)/bin/swig
SWIGOPT = -python
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIB = -lembed.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED =
BUILD = ld -G
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (needed if rebuilding Python + tkinter)
XLIB = -L/usr/openwin/lib -lX11
XINCLUDE = -I/usr/openwin/include
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H -I/usr/local/include/python1.5 -I/usr/local/lib/python1.5/config
PY_LIB = /usr/local/lib/python1.5/config
# Tcl installation. Needed if rebuilding Python with tkinter.
TCL_INCLUDE = -I/usr/local/include
TCL_LIB = -L/usr/local/lib
# Build libraries (needed for static builds)
LIBM = -lm
LIBC =
SYSLIBS = $(LIBM) $(LIBC) -lsocket -lnsl -ldl
# Build options (uncomment only one these)
#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PY_LIB) -lpython1.5 $(TKINTER) $(LIBS) $(SYSLIBS)
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDE) $(PY_INCLUDE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,136 @@
# ---------------------------------------------------------------
# $Header$
# SWIG Python Makefile
#
# This file can be used to build various Python extensions with SWIG.
# By default this file is set up for dynamic loading, but it can
# be easily customized for static extensions by modifying various
# portions of the file.
#
# SRCS = C source files
# CXXSRCS = C++ source files
# OBJCSRCS = Objective-C source files
# OBJS = Additional .o files (compiled previously)
# INTERFACE = SWIG interface file
# TARGET = Name of target module or executable
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module@SO@ # Use this kind of target for dynamic loading
#TARGET = mypython # Use this target for static linking
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
CXX = @CXX@
OBJC = @CC@ -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# SWIG Options
# SWIG = location of the SWIG executable
# SWIGOPT = SWIG compiler options
# SWIGCC = Compiler used to compile the wrapper file
SWIG = $(exec_prefix)/bin/swig
SWIGOPT = -python
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIB = -lembed.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED = @CCSHARED@
BUILD = @LDSHARED@
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (needed if rebuilding Python + tkinter)
XLIB = @XLIBSW@
XINCLUDE = @XINCLUDES@
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@
PY_LIB = @PYLIB@
# Tcl installation. Needed if rebuilding Python with tkinter.
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB = @TCLLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options (uncomment only one these)
#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PY_LIB) @PYLINK@ $(TKINTER) $(LIBS) $(SYSLIBS)
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDE) $(PY_INCLUDE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,36 @@
/* This file defines an internal function for processing default arguments
with shadow classes.
There seems to be no straightforward way to write a shadow functions
involving default arguments. For example :
def foo(arg1,arg2,*args):
shadowc.foo(arg1,arg2,args)
This fails because args is now a tuple and SWIG doesn't know what to
do with it.
This file allows a different approach :
def foo(arg1,arg2,*args):
shadowc.__call_defarg(shadowc.foo,(arg1,arg2,)+args)
Basically, we form a new tuple from the object, call this special
__call_defarg method and it passes control to the real wrapper function.
An ugly hack, but it works.
*/
static PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
PyObject *func;
PyObject *parms;
if (!PyArg_ParseTuple(args,"OO",&func,&parms))
return NULL;
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
return NULL;
}
return PyEval_CallObject(func,parms);
}

View File

@@ -0,0 +1,115 @@
//
// embed15.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.5. It will not work with
// earlier versions.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as Tkinter). Thus, you
may need to provide additional link libraries when compiling.
This library file only works with Python 1.5. A version
compatible with Python 1.4 is available as embed14.i and
a Python1.3 version is available as embed13.i. As far as
I know, this module is C++ safe.
%}
#else
%echo "embed.i : Using Python 1.5"
#endif
%wrapper %{
#include <Python.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define _PyImport_Inittab swig_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <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];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
_SwigImport_Inittab[swig_num_modules].name = name;
_SwigImport_Inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
_SwigImport_Inittab[swig_num_modules].name = (char *) 0;
_SwigImport_Inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (swig_inittab[i].name) {
swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int Py_Main(int, char **);
#ifdef __cplusplus
}
#endif
extern struct _inittab *PyImport_Inittab;
int
main(int argc, char **argv) {
swig_add_builtin();
PyImport_Inittab = _SwigImport_Inittab;
return Py_Main(argc,argv);
}
%}

View File

@@ -0,0 +1,342 @@
//
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.3, but it might work with
// later versions.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed13.i"
%text %{
This module provides support for building a new version of the
Python 1.3 executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module is functionally equivalent to the embed.i library,
but has a number of changes needed to work with older versions
of Python.
%}
#else
%echo "embed.i : Using Python 1.3"
#endif
%wrapper %{
#ifndef NEED_GETOPT
#include <unistd.h>
#endif
#include <pythonrun.h>
typedef struct SWIGPyTab {
char *name;
void (*initfunc)();
} SWIGPyTab;
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(void); /* Forward reference */
#define inittab python_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef inittab
/* Now define our own version of it.
God forbid someone have more than 1000 built-in modules! */
SWIGPyTab inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
inittab[swig_num_modules].name = name;
inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
inittab[swig_num_modules].name = (char *) 0;
inittab[swig_num_modules].initfunc = (void (*)()) 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (python_inittab[i].name) {
swig_add_module(python_inittab[i].name, python_inittab[i].initfunc);
i++;
}
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
}
#ifdef __cplusplus
}
#endif
/* Interface to getopt(): */
extern int optind;
extern char *optarg;
#ifdef NEED_GETOPT
#ifdef __cplusplus
extern "C" int getopt(int, char **, char *);
#else
extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
#endif
#endif
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
/* Subroutines that live in their own file */
#ifdef __cplusplus
extern "C" {
extern int isatty(int fd);
extern int PySys_SetArgv(int, char **);
#endif
extern char *getversion();
extern char *getcopyright();
#ifdef __cplusplus
}
#endif
/* For getprogramname(); set by main() */
static char *argv0;
/* For getargcargv(); set by main() */
static char **orig_argv;
static int orig_argc;
/* Short usage message (with %s for argv0) */
static char *usage_line =
"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n";
/* Long usage message, split into parts < 512 bytes */
static char *usage_top = "\n\
Options and arguments (and corresponding environment variables):\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
-c cmd : program passed in as string (terminates option list)\n\
";
static char *usage_bot = "\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\
\n\
Other environment variables:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : colon-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\
";
/* Main program */
int
main(int argc, char **argv) {
int c;
int sts;
char *command = NULL;
char *filename = NULL;
FILE *fp = stdin;
char *p;
int inspect = 0;
int unbuffered = 0;
swig_add_builtin(); /* Add SWIG built-in modules */
orig_argc = argc; /* For getargcargv() */
orig_argv = argv;
argv0 = argv[0]; /* For getprogramname() */
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1;
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
Py_SuppressPrintingFlag = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = 1;
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
the command to interpret. */
command = (char *) malloc(strlen(optarg) + 2);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
strcpy(command, optarg);
strcat(command, "\n");
break;
}
switch (c) {
case 'd':
Py_DebugFlag++;
break;
case 'i':
inspect++;
break;
case 's':
Py_SuppressPrintingFlag++;
break;
case 'u':
unbuffered++;
break;
case 'v':
Py_VerboseFlag++;
break;
/* This space reserved for other options */
default:
fprintf(stderr, usage_line, argv[0]);
fprintf(stderr, usage_top);
fprintf(stderr, usage_bot);
exit(2);
/*NOTREACHED*/
}
}
if (unbuffered) {
#ifndef MPW
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
#else
/* On MPW (3.2) unbuffered seems to hang */
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
#endif
}
if (command == NULL && optind < argc &&
strcmp(argv[optind], "-") != 0)
filename = argv[optind];
if (Py_VerboseFlag ||
command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s\n%s\n",
getversion(), getcopyright());
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
Py_Initialize();
if (command != NULL) {
/* Backup optind and force sys.argv[0] = '-c' */
optind--;
argv[optind] = "-c";
}
PySys_SetArgv(argc-optind, argv+optind);
if (command) {
sts = PyRun_SimpleString(command) != 0;
}
else {
if (filename == NULL && isatty((int)fileno(fp))) {
char *startup = getenv("PYTHONSTARTUP");
if (startup != NULL && startup[0] != '\0') {
FILE *fp = fopen(startup, "r");
if (fp != NULL) {
(void) PyRun_SimpleFile(fp, startup);
PyErr_Clear();
fclose(fp);
}
}
}
sts = PyRun_AnyFile(
fp, filename == NULL ? "<stdin>" : filename) != 0;
if (filename != NULL)
fclose(fp);
}
if (inspect && isatty((int)fileno(stdin)) &&
(filename != NULL || command != NULL))
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Py_Exit(sts);
/*NOTREACHED*/
}
/* Return the program name -- some code out there needs this. */
#ifdef __cplusplus
extern "C"
#endif
char *
getprogramname()
{
return argv0;
}
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
#ifdef __cplusplus
extern "C"
#endif
void
getargcargv(int *argc,char ***argv)
{
*argc = orig_argc;
*argv = orig_argv;
}
/* Total Hack to get getpath.c to compile under C++ */
#ifdef __cplusplus
#define malloc (char *) malloc
extern "C" {
#endif
#include <getpath.c>
#ifdef __cplusplus
}
#undef malloc
#endif
%}

View File

@@ -0,0 +1,340 @@
//
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.4.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as tkinter). Thus, you
may need to provide additional link libraries when compiling.
This library file only works with Python 1.4. A version compatible
with Python 1.3 is available as embed13.i. A Python 1.5 version is
available as embed15.i As far as I know, this module is C++ safe
(well, it works for me).
%}
#else
%echo "embed.i : Using Python 1.4"
#endif
%wrapper %{
#ifndef NEED_GETOPT
#include <unistd.h>
#endif
#include <pythonrun.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define inittab python_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef inittab
/* Now define our own version of it.
Hopefully someone does not have more than 1000 built-in modules */
struct _inittab inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
inittab[swig_num_modules].name = name;
inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
inittab[swig_num_modules].name = (char *) 0;
inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (python_inittab[i].name) {
swig_add_module(python_inittab[i].name, python_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
/* Interface to getopt(): */
extern int optind;
extern char *optarg;
#ifdef NEED_GETOPT
#ifdef __cplusplus
extern "C" int getopt(int, char **, char *);
#else
extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
#endif
#endif
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
/* Subroutines that live in their own file */
#ifdef __cplusplus
extern "C" {
extern int isatty(int fd);
extern void PySys_SetArgv(int, char **);
#endif
extern char *Py_GetVersion();
extern char *Py_GetCopyright();
#ifdef __cplusplus
}
#endif
/* For getprogramname(); set by main() */
static char *argv0;
/* For getargcargv(); set by main() */
static char **orig_argv;
static int orig_argc;
/* Short usage message (with %s for argv0) */
static char *usage_line =
"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n";
/* Long usage message, split into parts < 512 bytes */
static char *usage_top = "\n\
Options and arguments (and corresponding environment variables):\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
-c cmd : program passed in as string (terminates option list)\n\
";
static char *usage_bot = "\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\
\n\
Other environment variables:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : colon-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\
";
/* Main program */
int
main(int argc, char **argv) {
int c;
int sts;
char *command = NULL;
char *filename = NULL;
FILE *fp = stdin;
char *p;
int inspect = 0;
int unbuffered = 0;
swig_add_builtin(); /* Add SWIG built-in modules */
orig_argc = argc; /* For getargcargv() */
orig_argv = argv;
argv0 = argv[0]; /* For getprogramname() */
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1;
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
Py_SuppressPrintingFlag = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = 1;
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
the command to interpret. */
command = (char *) malloc(strlen(optarg) + 2);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
strcpy(command, optarg);
strcat(command, "\n");
break;
}
switch (c) {
case 'd':
Py_DebugFlag++;
break;
case 'i':
inspect++;
break;
case 's':
Py_SuppressPrintingFlag++;
break;
case 'u':
unbuffered++;
break;
case 'v':
Py_VerboseFlag++;
break;
/* This space reserved for other options */
default:
fprintf(stderr, usage_line, argv[0]);
fprintf(stderr, usage_top);
fprintf(stderr, usage_bot);
exit(2);
/*NOTREACHED*/
}
}
if (unbuffered) {
#ifndef MPW
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
#else
/* On MPW (3.2) unbuffered seems to hang */
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
#endif
}
if (command == NULL && optind < argc &&
strcmp(argv[optind], "-") != 0)
filename = argv[optind];
if (Py_VerboseFlag ||
command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s\n%s\n",
Py_GetVersion(), Py_GetCopyright());
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
Py_Initialize();
if (command != NULL) {
/* Backup optind and force sys.argv[0] = '-c' */
optind--;
argv[optind] = "-c";
}
PySys_SetArgv(argc-optind, argv+optind);
if (command) {
sts = PyRun_SimpleString(command) != 0;
}
else {
if (filename == NULL && isatty((int)fileno(fp))) {
char *startup = getenv("PYTHONSTARTUP");
if (startup != NULL && startup[0] != '\0') {
FILE *fp = fopen(startup, "r");
if (fp != NULL) {
(void) PyRun_SimpleFile(fp, startup);
PyErr_Clear();
fclose(fp);
}
}
}
sts = PyRun_AnyFile(
fp, filename == NULL ? "<stdin>" : filename) != 0;
if (filename != NULL)
fclose(fp);
}
if (inspect && isatty((int)fileno(stdin)) &&
(filename != NULL || command != NULL))
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Py_Exit(sts);
/*NOTREACHED*/
}
/* Return the program name -- some code out there needs this. */
#ifdef __cplusplus
extern "C"
#endif
char *
Py_GetProgramName()
{
return argv0;
}
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
#ifdef __cplusplus
extern "C"
#endif
void
getargcargv(int *argc,char ***argv)
{
*argc = orig_argc;
*argv = orig_argv;
}
/* Total Hack to get getpath.c to compile under C++ */
#ifdef __cplusplus
#define malloc (char *) malloc
extern "C" {
#endif
#include <getpath.c>
#ifdef __cplusplus
}
#undef malloc
#endif
%}

View File

@@ -0,0 +1,115 @@
//
// embed15.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.5. It will not work with
// earlier versions.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as Tkinter). Thus, you
may need to provide additional link libraries when compiling.
This library file only works with Python 1.5. A version
compatible with Python 1.4 is available as embed14.i and
a Python1.3 version is available as embed13.i. As far as
I know, this module is C++ safe.
%}
#else
%echo "embed.i : Using Python 1.5"
#endif
%wrapper %{
#include <Python.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define _PyImport_Inittab swig_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <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];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
_SwigImport_Inittab[swig_num_modules].name = name;
_SwigImport_Inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
_SwigImport_Inittab[swig_num_modules].name = (char *) 0;
_SwigImport_Inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (swig_inittab[i].name) {
swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int Py_Main(int, char **);
#ifdef __cplusplus
}
#endif
extern struct _inittab *PyImport_Inittab;
int
main(int argc, char **argv) {
swig_add_builtin();
PyImport_Inittab = _SwigImport_Inittab;
return Py_Main(argc,argv);
}
%}

View File

@@ -0,0 +1,652 @@
//
// SWIG pointer conversion and utility library
//
// Dave Beazley
// April 19, 1997
//
// Python specific implementation. This file is included
// by the file ../pointer.i
%{
#include <ctype.h>
/*------------------------------------------------------------------
ptrcast(value,type)
Constructs a new pointer value. Value may either be a string
or an integer. Type is a string corresponding to either the
C datatype or mangled datatype.
ptrcast(0,"Vector *")
or
ptrcast(0,"Vector_p")
------------------------------------------------------------------ */
static PyObject *ptrcast(PyObject *_PTRVALUE, char *type) {
char *r,*s;
void *ptr;
PyObject *obj;
char *typestr,*c;
/* Produce a "mangled" version of the type string. */
typestr = (char *) malloc(strlen(type)+2);
/* Go through and munge the typestring */
r = typestr;
*(r++) = '_';
c = type;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
*(r++) = 'p';
}
else *(r++) = *c;
} else {
*(r++) = '_';
}
c++;
}
*(r++) = 0;
/* Check to see what kind of object _PTRVALUE is */
if (PyInt_Check(_PTRVALUE)) {
ptr = (void *) PyInt_AsLong(_PTRVALUE);
/* Received a numerical value. Make a pointer out of it */
r = (char *) malloc(strlen(typestr)+22);
if (ptr) {
SWIG_MakePtr(r, ptr, typestr);
} else {
sprintf(r,"_0%s",typestr);
}
obj = PyString_FromString(r);
free(r);
} else if (PyString_Check(_PTRVALUE)) {
/* Have a real pointer value now. Try to strip out the pointer
value */
s = PyString_AsString(_PTRVALUE);
r = (char *) malloc(strlen(type)+22);
/* Now extract the pointer value */
if (!SWIG_GetPtr(s,&ptr,0)) {
if (ptr) {
SWIG_MakePtr(r,ptr,typestr);
} else {
sprintf(r,"_0%s",typestr);
}
obj = PyString_FromString(r);
} else {
obj = NULL;
}
free(r);
} else {
obj = NULL;
}
free(typestr);
if (!obj)
PyErr_SetString(PyExc_TypeError,"Type error in ptrcast. Argument is not a valid pointer value.");
return obj;
}
/*------------------------------------------------------------------
ptrvalue(ptr,type = 0)
Attempts to dereference a pointer value. If type is given, it
will try to use that type. Otherwise, this function will attempt
to "guess" the proper datatype by checking against all of the
builtin C datatypes.
------------------------------------------------------------------ */
static PyObject *ptrvalue(PyObject *_PTRVALUE, int index, char *type) {
void *ptr;
char *s;
PyObject *obj;
if (!PyString_Check(_PTRVALUE)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrvalue. Argument is not a valid pointer value.");
return NULL;
}
s = PyString_AsString(_PTRVALUE);
if (SWIG_GetPtr(s,&ptr,0)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrvalue. Argument is not a valid pointer value.");
return NULL;
}
/* If no datatype was passed, try a few common datatypes first */
if (!type) {
/* No datatype was passed. Type to figure out if it's a common one */
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
type = "int";
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
type = "double";
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
type = "short";
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
type = "long";
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
type = "float";
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
type = "char";
} else if (!SWIG_GetPtr(s,&ptr,"_char_pp")) {
type = "char *";
} else {
type = "unknown";
}
}
if (!ptr) {
PyErr_SetString(PyExc_TypeError,"Unable to dereference NULL pointer.");
return NULL;
}
/* Now we have a datatype. Try to figure out what to do about it */
if (strcmp(type,"int") == 0) {
obj = PyInt_FromLong((long) *(((int *) ptr) + index));
} else if (strcmp(type,"double") == 0) {
obj = PyFloat_FromDouble((double) *(((double *) ptr)+index));
} else if (strcmp(type,"short") == 0) {
obj = PyInt_FromLong((long) *(((short *) ptr)+index));
} else if (strcmp(type,"long") == 0) {
obj = PyInt_FromLong((long) *(((long *) ptr)+index));
} else if (strcmp(type,"float") == 0) {
obj = PyFloat_FromDouble((double) *(((float *) ptr)+index));
} else if (strcmp(type,"char") == 0) {
obj = PyString_FromString(((char *) ptr)+index);
} else if (strcmp(type,"char *") == 0) {
char *c = *(((char **) ptr)+index);
if (c) obj = PyString_FromString(c);
else obj = PyString_FromString("NULL");
} else {
PyErr_SetString(PyExc_TypeError,"Unable to dereference unsupported datatype.");
return NULL;
}
return obj;
}
/*------------------------------------------------------------------
ptrcreate(type,value = 0,numelements = 1)
Attempts to create a new object of given type. Type must be
a basic C datatype. Will not create complex objects.
------------------------------------------------------------------ */
static PyObject *ptrcreate(char *type, PyObject *_PYVALUE, int numelements) {
void *ptr;
PyObject *obj;
int sz;
char *cast;
char temp[40];
/* Check the type string against a variety of possibilities */
if (strcmp(type,"int") == 0) {
sz = sizeof(int)*numelements;
cast = "_int_p";
} else if (strcmp(type,"short") == 0) {
sz = sizeof(short)*numelements;
cast = "_short_p";
} else if (strcmp(type,"long") == 0) {
sz = sizeof(long)*numelements;
cast = "_long_p";
} else if (strcmp(type,"double") == 0) {
sz = sizeof(double)*numelements;
cast = "_double_p";
} else if (strcmp(type,"float") == 0) {
sz = sizeof(float)*numelements;
cast = "_float_p";
} else if (strcmp(type,"char") == 0) {
sz = sizeof(char)*numelements;
cast = "_char_p";
} else if (strcmp(type,"char *") == 0) {
sz = sizeof(char *)*(numelements+1);
cast = "_char_pp";
} else {
PyErr_SetString(PyExc_TypeError,"Unable to create unknown datatype.");
return NULL;
}
/* Create the new object */
ptr = (void *) malloc(sz);
if (!ptr) {
PyErr_SetString(PyExc_MemoryError,"Out of memory in swig_create.");
return NULL;
}
/* Now try to set its default value */
if (_PYVALUE) {
if (strcmp(type,"int") == 0) {
int *ip,i,ivalue;
ivalue = (int) PyInt_AsLong(_PYVALUE);
ip = (int *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"short") == 0) {
short *ip,ivalue;
int i;
ivalue = (short) PyInt_AsLong(_PYVALUE);
ip = (short *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"long") == 0) {
long *ip,ivalue;
int i;
ivalue = (long) PyInt_AsLong(_PYVALUE);
ip = (long *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"double") == 0) {
double *ip,ivalue;
int i;
ivalue = (double) PyFloat_AsDouble(_PYVALUE);
ip = (double *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"float") == 0) {
float *ip,ivalue;
int i;
ivalue = (float) PyFloat_AsDouble(_PYVALUE);
ip = (float *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"char") == 0) {
char *ip,*ivalue;
ivalue = (char *) PyString_AsString(_PYVALUE);
ip = (char *) ptr;
strncpy(ip,ivalue,numelements-1);
} else if (strcmp(type,"char *") == 0) {
char **ip, *ivalue;
int i;
ivalue = (char *) PyString_AsString(_PYVALUE);
ip = (char **) ptr;
for (i = 0; i < numelements; i++) {
if (ivalue) {
ip[i] = (char *) malloc(strlen(ivalue)+1);
strcpy(ip[i],ivalue);
} else {
ip[i] = 0;
}
}
ip[numelements] = 0;
}
}
/* Create the pointer value */
SWIG_MakePtr(temp,ptr,cast);
obj = PyString_FromString(temp);
return obj;
}
/*------------------------------------------------------------------
ptrset(ptr,value,index = 0,type = 0)
Attempts to set the value of a pointer variable. If type is
given, we will use that type. Otherwise, we'll guess the datatype.
------------------------------------------------------------------ */
static PyObject *ptrset(PyObject *_PTRVALUE, PyObject *_PYVALUE, int index, char *type) {
void *ptr;
char *s;
PyObject *obj;
if (!PyString_Check(_PTRVALUE)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrset. Argument is not a valid pointer value.");
return NULL;
}
s = PyString_AsString(_PTRVALUE);
if (SWIG_GetPtr(s,&ptr,0)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrset. Argument is not a valid pointer value.");
return NULL;
}
/* If no datatype was passed, try a few common datatypes first */
if (!type) {
/* No datatype was passed. Type to figure out if it's a common one */
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
type = "int";
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
type = "double";
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
type = "short";
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
type = "long";
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
type = "float";
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
type = "char";
} else if (!SWIG_GetPtr(s,&ptr,"_char_pp")) {
type = "char *";
} else {
type = "unknown";
}
}
if (!ptr) {
PyErr_SetString(PyExc_TypeError,"Unable to set NULL pointer.");
return NULL;
}
/* Now we have a datatype. Try to figure out what to do about it */
if (strcmp(type,"int") == 0) {
*(((int *) ptr)+index) = (int) PyInt_AsLong(_PYVALUE);
} else if (strcmp(type,"double") == 0) {
*(((double *) ptr)+index) = (double) PyFloat_AsDouble(_PYVALUE);
} else if (strcmp(type,"short") == 0) {
*(((short *) ptr)+index) = (short) PyInt_AsLong(_PYVALUE);
} else if (strcmp(type,"long") == 0) {
*(((long *) ptr)+index) = (long) PyInt_AsLong(_PYVALUE);
} else if (strcmp(type,"float") == 0) {
*(((float *) ptr)+index) = (float) PyFloat_AsDouble(_PYVALUE);
} else if (strcmp(type,"char") == 0) {
char *c = PyString_AsString(_PYVALUE);
strcpy(((char *) ptr)+index, c);
} else if (strcmp(type,"char *") == 0) {
char *c = PyString_AsString(_PYVALUE);
char **ca = (char **) ptr;
if (ca[index]) free(ca[index]);
if (strcmp(c,"NULL") == 0) {
ca[index] = 0;
} else {
ca[index] = (char *) malloc(strlen(c)+1);
strcpy(ca[index],c);
}
} else {
PyErr_SetString(PyExc_TypeError,"Unable to set unsupported datatype.");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/*------------------------------------------------------------------
ptradd(ptr,offset)
Adds a value to an existing pointer value. Will do a type-dependent
add for basic datatypes. For other datatypes, will do a byte-add.
------------------------------------------------------------------ */
static PyObject *ptradd(PyObject *_PTRVALUE, int offset) {
char *r,*s;
void *ptr,*junk;
PyObject *obj;
char *type;
/* Check to see what kind of object _PTRVALUE is */
if (PyString_Check(_PTRVALUE)) {
/* Have a potential pointer value now. Try to strip out the value */
s = PyString_AsString(_PTRVALUE);
/* Try to handle a few common datatypes first */
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
ptr = (void *) (((int *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
ptr = (void *) (((double *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
ptr = (void *) (((short *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
ptr = (void *) (((long *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
ptr = (void *) (((float *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
ptr = (void *) (((char *) ptr) + offset);
} else if (!SWIG_GetPtr(s,&ptr,0)) {
ptr = (void *) (((char *) ptr) + offset);
} else {
PyErr_SetString(PyExc_TypeError,"Type error in ptradd. Argument is not a valid pointer value.");
return NULL;
}
type = SWIG_GetPtr(s,&junk,"INVALID POINTER");
r = (char *) malloc(strlen(type)+20);
if (ptr) {
SWIG_MakePtr(r,ptr,type);
} else {
sprintf(r,"_0%s",type);
}
obj = PyString_FromString(r);
free(r);
}
return obj;
}
/*------------------------------------------------------------------
ptrmap(type1,type2)
Allows a mapping between type1 and type2. (Like a typedef)
------------------------------------------------------------------ */
static void ptrmap(char *type1, char *type2) {
char *typestr1,*typestr2,*c,*r;
/* Produce a "mangled" version of the type string. */
typestr1 = (char *) malloc(strlen(type1)+2);
/* Go through and munge the typestring */
r = typestr1;
*(r++) = '_';
c = type1;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
*(r++) = 'p';
}
else *(r++) = *c;
} else {
*(r++) = '_';
}
c++;
}
*(r++) = 0;
typestr2 = (char *) malloc(strlen(type2)+2);
/* Go through and munge the typestring */
r = typestr2;
*(r++) = '_';
c = type2;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
*(r++) = 'p';
}
else *(r++) = *c;
} else {
*(r++) = '_';
}
c++;
}
*(r++) = 0;
SWIG_RegisterMapping(typestr1,typestr2,0);
SWIG_RegisterMapping(typestr2,typestr1,0);
}
/*------------------------------------------------------------------
ptrfree(ptr)
Destroys a pointer value
------------------------------------------------------------------ */
PyObject *ptrfree(PyObject *_PTRVALUE) {
void *ptr, *junk;
char *s;
if (!PyString_Check(_PTRVALUE)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrfree. Argument is not a valid pointer value.");
return NULL;
}
s = PyString_AsString(_PTRVALUE);
if (SWIG_GetPtr(s,&ptr,0)) {
PyErr_SetString(PyExc_TypeError,"Type error in ptrfree. Argument is not a valid pointer value.");
return NULL;
}
/* Check to see if this pointer is a char ** */
if (!SWIG_GetPtr(s,&junk,"_char_pp")) {
char **c = (char **) ptr;
if (c) {
int i = 0;
while (c[i]) {
free(c[i]);
i++;
}
}
}
if (ptr)
free((char *) ptr);
Py_INCREF(Py_None);
return Py_None;
}
%}
%typemap(python,in) PyObject *ptr, PyObject *value {
$target = $source;
}
%typemap(python,out) PyObject *ptrcast,
PyObject *ptrvalue,
PyObject *ptrcreate,
PyObject *ptrset,
PyObject *ptradd,
PyObject *ptrfree
{
$target = $source;
}
%typemap(python,ret) int ptrset {
if ($source == -1) return NULL;
}
PyObject *ptrcast(PyObject *ptr, char *type);
// Casts a pointer ptr to a new datatype given by the string type.
// type may be either the SWIG generated representation of a datatype
// or the C representation. For example :
//
// ptrcast(ptr,"double_p"); # Python representation
// ptrcast(ptr,"double *"); # C representation
//
// A new pointer value is returned. ptr may also be an integer
// value in which case the value will be used to set the pointer
// value. For example :
//
// a = ptrcast(0,"Vector_p");
//
// Will create a NULL pointer of type "Vector_p"
//
// The casting operation is sensitive to formatting. As a result,
// "double *" is different than "double*". As a result of thumb,
// there should always be exactly one space between the C datatype
// and any pointer specifiers (*).
PyObject *ptrvalue(PyObject *ptr, int index = 0, char *type = 0);
// Returns the value that a pointer is pointing to (ie. dereferencing).
// The type is automatically inferred by the pointer type--thus, an
// integer pointer will return an integer, a double will return a double,
// and so on. The index and type fields are optional parameters. When
// an index is specified, this function returns the value of ptr[index].
// This allows array access. When a type is specified, it overrides
// the given pointer type. Examples :
//
// ptrvalue(a) # Returns the value *a
// ptrvalue(a,10) # Returns the value a[10]
// ptrvalue(a,10,"double") # Returns a[10] assuming a is a double *
PyObject *ptrset(PyObject *ptr, PyObject *value, int index = 0, char *type = 0);
// Sets the value pointed to by a pointer. The type is automatically
// inferred from the pointer type so this function will work for
// integers, floats, doubles, etc... The index and type fields are
// optional. When an index is given, it provides array access. When
// type is specified, it overrides the given pointer type. Examples :
//
// ptrset(a,3) # Sets the value *a = 3
// ptrset(a,3,10) # Sets a[10] = 3
// ptrset(a,3,10,"int") # Sets a[10] = 3 assuming a is a int *
PyObject *ptrcreate(char *type, PyObject *value = 0, int nitems = 1);
// Creates a new object and returns a pointer to it. This function
// can be used to create various kinds of objects for use in C functions.
// type specifies the basic C datatype to create and value is an
// optional parameter that can be used to set the initial value of the
// object. nitems is an optional parameter that can be used to create
// an array. This function results in a memory allocation using
// malloc(). Examples :
//
// a = ptrcreate("double") # Create a new double, return pointer
// a = ptrcreate("int",7) # Create an integer, set value to 7
// a = ptrcreate("int",0,1000) # Create an integer array with initial
// # values all set to zero
//
// This function only recognizes a few common C datatypes as listed below :
//
// int, short, long, float, double, char, char *, void
//
// All other datatypes will result in an error. However, other
// datatypes can be created by using the ptrcast function. For
// example:
//
// a = ptrcast(ptrcreate("int",0,100),"unsigned int *")
PyObject *ptrfree(PyObject *ptr);
// Destroys the memory pointed to by ptr. This function calls free()
// and should only be used with objects created by ptrcreate(). Since
// this function calls free, it may work with other objects, but this
// is generally discouraged unless you absolutely know what you're
// doing.
PyObject *ptradd(PyObject *ptr, int offset);
// Adds a value to the current pointer value. For the C datatypes of
// int, short, long, float, double, and char, the offset value is the
// number of objects and works in exactly the same manner as in C. For
// example, the following code steps through the elements of an array
//
// a = ptrcreate("double",0,100); # Create an array double a[100]
// b = a;
// for i in range(0,100):
// ptrset(b,0.0025*i); # set *b = 0.0025*i
// b = ptradd(b,1); # b++ (go to next double)
//
// In this case, adding one to b goes to the next double.
//
// For all other datatypes (including all complex datatypes), the
// offset corresponds to bytes. This function does not perform any
// bounds checking and negative offsets are perfectly legal.
void ptrmap(char *type1, char *type2);
// This is a rarely used function that performs essentially the same
// operation as a C typedef. To manage datatypes at run-time, SWIG
// modules manage an internal symbol table of type mappings. This
// table keeps track of which types are equivalent to each other. The
// ptrmap() function provides a mechanism for scripts to add symbols
// to this table. For example :
//
// ptrmap("double_p","Real_p");
//
// would make the types "doublePtr" and "RealPtr" equivalent to each
// other. Pointers of either type could now be used interchangably.
//
// Normally this function is not needed, but it can be used to
// circumvent SWIG's normal type-checking behavior or to work around
// weird type-handling problems.

View File

@@ -0,0 +1,32 @@
#include <string.h>
#include <stdlib.h>
/* Definitions for Windows/Unix exporting */
#if defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#include "Python.h"
#ifdef __cplusplus
extern "C" {
#endif
extern void SWIG_MakePtr(char *, void *, char *);
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
extern char *SWIG_GetPtr(char *, void **, char *);
extern char *SWIG_GetPtrObj(PyObject *, void **, char *);
extern void SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
extern PyObject *SWIG_newvarlink(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,417 @@
/***********************************************************************
* $Header$
* swig_lib/python/python.cfg
*
* Contains variable linking and pointer type-checking code.
************************************************************************/
#include <string.h>
#include <stdlib.h>
#include "Python.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Definitions for Windows/Unix exporting */
#if defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
typedef struct {
char *name;
PyObject *(*get_attr)(void);
int (*set_attr)(PyObject *);
} swig_globalvar;
typedef struct swig_varlinkobject {
PyObject_HEAD
swig_globalvar **vars;
int nvars;
int maxvars;
} swig_varlinkobject;
/* ----------------------------------------------------------------------
swig_varlink_repr()
Function for python repr method
---------------------------------------------------------------------- */
static PyObject *
swig_varlink_repr(swig_varlinkobject *v)
{
v = v;
return PyString_FromString("<Global variables>");
}
/* ---------------------------------------------------------------------
swig_varlink_print()
Print out all of the global variable names
--------------------------------------------------------------------- */
static int
swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags)
{
int i = 0;
flags = flags;
fprintf(fp,"Global variables { ");
while (v->vars[i]) {
fprintf(fp,"%s", v->vars[i]->name);
i++;
if (v->vars[i]) fprintf(fp,", ");
}
fprintf(fp," }\n");
return 0;
}
/* --------------------------------------------------------------------
swig_varlink_getattr
This function gets the value of a variable and returns it as a
PyObject. In our case, we'll be looking at the datatype and
converting into a number or string
-------------------------------------------------------------------- */
static PyObject *
swig_varlink_getattr(swig_varlinkobject *v, char *n)
{
int i = 0;
char temp[128];
while (v->vars[i]) {
if (strcmp(v->vars[i]->name,n) == 0) {
return (*v->vars[i]->get_attr)();
}
i++;
}
sprintf(temp,"C global variable %s not found.", n);
PyErr_SetString(PyExc_NameError,temp);
return NULL;
}
/* -------------------------------------------------------------------
swig_varlink_setattr()
This function sets the value of a variable.
------------------------------------------------------------------- */
static int
swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p)
{
char temp[128];
int i = 0;
while (v->vars[i]) {
if (strcmp(v->vars[i]->name,n) == 0) {
return (*v->vars[i]->set_attr)(p);
}
i++;
}
sprintf(temp,"C global variable %s not found.", n);
PyErr_SetString(PyExc_NameError,temp);
return 1;
}
statichere PyTypeObject varlinktype = {
/* PyObject_HEAD_INIT(&PyType_Type) Note : This doesn't work on some machines */
PyObject_HEAD_INIT(0)
0,
"varlink", /* Type name */
sizeof(swig_varlinkobject), /* Basic size */
0, /* Itemsize */
0, /* Deallocator */
(printfunc) swig_varlink_print, /* Print */
(getattrfunc) swig_varlink_getattr, /* get attr */
(setattrfunc) swig_varlink_setattr, /* Set attr */
0, /* tp_compare */
(reprfunc) swig_varlink_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_mapping*/
0, /* tp_hash */
};
/* Create a variable linking object for use later */
SWIGSTATICRUNTIME(PyObject *)
SWIG_newvarlink(void)
{
swig_varlinkobject *result = 0;
result = PyMem_NEW(swig_varlinkobject,1);
varlinktype.ob_type = &PyType_Type; /* Patch varlinktype into a PyType */
result->ob_type = &varlinktype;
/* _Py_NewReference(result); Does not seem to be necessary */
result->nvars = 0;
result->maxvars = 64;
result->vars = (swig_globalvar **) malloc(64*sizeof(swig_globalvar *));
result->vars[0] = 0;
result->ob_refcnt = 0;
Py_XINCREF((PyObject *) result);
return ((PyObject*) result);
}
SWIGSTATICRUNTIME(void)
SWIG_addvarlink(PyObject *p, char *name,
PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p))
{
swig_varlinkobject *v;
v= (swig_varlinkobject *) p;
if (v->nvars >= v->maxvars -1) {
v->maxvars = 2*v->maxvars;
v->vars = (swig_globalvar **) realloc(v->vars,v->maxvars*sizeof(swig_globalvar *));
if (v->vars == NULL) {
fprintf(stderr,"SWIG : Fatal error in initializing Python module.\n");
exit(1);
}
}
v->vars[v->nvars] = (swig_globalvar *) malloc(sizeof(swig_globalvar));
v->vars[v->nvars]->name = (char *) malloc(strlen(name)+1);
strcpy(v->vars[v->nvars]->name,name);
v->vars[v->nvars]->get_attr = get_attr;
v->vars[v->nvars]->set_attr = set_attr;
v->nvars++;
v->vars[v->nvars] = 0;
}
/* -----------------------------------------------------------------------------
* Pointer type-checking
* ----------------------------------------------------------------------------- */
/* SWIG pointer structure */
typedef struct SwigPtrType {
char *name; /* Datatype name */
int len; /* Length (used for optimization) */
void *(*cast)(void *); /* Pointer casting function */
struct SwigPtrType *next; /* Linked list pointer */
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static int SwigStart[256]; /* Starting positions of types */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Register a new datatype with the type-checker */
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
int i;
SwigPtrType *t = 0,*t1;
/* Allocate the pointer table if necessary */
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
}
/* Grow the table */
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++) {
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
}
if (!t) {
t = &SwigPtrTable[SwigPtrN++];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
}
/* Check for existing entries */
while (t->next) {
if ((strcmp(t->name,newtype) == 0)) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *c, const void *ptr, char *type) {
static char hex[17] = "0123456789abcdef";
unsigned long p, s;
char result[24], *r;
r = result;
p = (unsigned long) ptr;
if (p > 0) {
while (p > 0) {
s = p & 0xf;
*(r++) = hex[s];
p = p >> 4;
}
*r = '_';
while (r >= result)
*(c++) = *(r--);
strcpy (c, type);
} else {
strcpy (c, "NULL");
}
}
/* Function for getting a pointer value */
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(char *c, void **ptr, char *t)
{
unsigned long p;
char temp_type[256], *name;
int i, len, start, end;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
register int d;
p = 0;
/* Pointer values must start with leading underscore */
if (*c != '_') {
*ptr = (void *) 0;
if (strcmp(c,"NULL") == 0) return (char *) 0;
else c;
}
c++;
/* Extract hex value from pointer */
while (d = *c) {
if ((d >= '0') && (d <= '9'))
p = (p << 4) + (d - '0');
else if ((d >= 'a') && (d <= 'f'))
p = (p << 4) + (d - ('a'-10));
else
break;
c++;
}
*ptr = (void *) p;
if ((!t) || (strcmp(t,c)==0)) return (char *) 0;
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) SwigStart[i] = SwigPtrN;
for (i = SwigPtrN-1; i >= 0; i--) SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++) SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat && (strcmp(t,cache->name) == 0) && (strcmp(c,cache->mapped) == 0)) {
cache->stat++;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
/* Type mismatch. Look through type-mapping table */
start = SwigStart[(int) t[1]];
end = SwigStart[(int) t[1]+1];
sp = &SwigPtrTable[start];
/* Try to find a match */
while (start <= end) {
if (strncmp(t,sp->name,sp->len) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
/* Try to find entry for our given datatype */
while(tp) {
if (tp->len >= 255) {
return c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,t+len,255-tp->len);
if (strcmp(c,temp_type) == 0) {
strcpy(SwigCache[SwigCacheIndex].mapped,c);
strcpy(SwigCache[SwigCacheIndex].name,t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
/* Get pointer value */
*ptr = (void *) p;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
return c;
}
/* New object-based GetPointer function. This uses the Python abstract
* object interface to automatically dereference the 'this' attribute
* of shadow objects. */
SWIGSTATICRUNTIME(char *)
SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type) {
PyObject *sobj = obj;
char *str;
if (!PyString_Check(obj)) {
sobj = PyObject_GetAttrString(obj,"this");
if (!sobj) return "";
}
str = PyString_AsString(sobj);
return SWIG_GetPtr(str,ptr,type);
}
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,564 @@
//
// SWIG Typemap library
// Dave Beazley
// May 5, 1997
//
// Python implementation
//
// This library provides standard typemaps for modifying SWIG's behavior.
// With enough entries in this file, I hope that very few people actually
// ever need to write a typemap.
//
// Disclaimer : Unless you really understand how typemaps work, this file
// probably isn't going to make much sense.
//
#ifdef AUTODOC
%section "Typemap Library (Python)",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include typemaps.i
The SWIG typemap library provides a language independent mechanism for
supporting output arguments, input values, and other C function
calling mechanisms. The primary use of the library is to provide a
better interface to certain C function--especially those involving
pointers.
%}
#endif
// ------------------------------------------------------------------------
// Pointer handling
//
// These mappings provide support for input/output arguments and common
// uses for C/C++ pointers.
// ------------------------------------------------------------------------
// INPUT typemaps.
// These remap a C pointer to be an "INPUT" value which is passed by value
// instead of reference.
#ifdef AUTODOC
%subsection "Input Methods"
%text %{
The following methods can be applied to turn a pointer into a simple
"input" value. That is, instead of passing a pointer to an object,
you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
unsigned char *INPUT
float *INPUT
double *INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include typemaps.i
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
%}
#endif
%typemap(python,in) double *INPUT(double temp)
{
temp = PyFloat_AsDouble($source);
$target = &temp;
}
%typemap(python,in) float *INPUT(float temp)
{
temp = (float) PyFloat_AsDouble($source);
$target = &temp;
}
%typemap(python,in) int *INPUT(int temp)
{
temp = (int) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) short *INPUT(short temp)
{
temp = (short) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) long *INPUT(long temp)
{
temp = (long) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) unsigned int *INPUT(unsigned int temp)
{
temp = (unsigned int) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) unsigned short *INPUT(unsigned short temp)
{
temp = (unsigned short) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) unsigned long *INPUT(unsigned long temp)
{
temp = (unsigned long) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) unsigned char *INPUT(unsigned char temp)
{
temp = (unsigned char) PyInt_AsLong($source);
$target = &temp;
}
%typemap(python,in) signed char *INPUT(signed char temp)
{
temp = (unsigned char) PyInt_AsLong($source);
$target = &temp;
}
// OUTPUT typemaps. These typemaps are used for parameters that
// are output only. The output value is appended to the result as
// a list element.
#ifdef AUTODOC
%subsection "Output Methods"
%text %{
The following methods can be applied to turn a pointer into an "output"
value. When calling a function, no input value would be given for
a parameter, but an output value would be returned. In the case of
multiple output values, they are returned in the form of a Python tuple.
int *OUTPUT
short *OUTPUT
long *OUTPUT
unsigned int *OUTPUT
unsigned short *OUTPUT
unsigned long *OUTPUT
unsigned char *OUTPUT
float *OUTPUT
double *OUTPUT
A Python List can also be returned by using L_OUTPUT instead of OUTPUT.
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
returns the integer part in one of its parameters).K:
double modf(double x, double *ip);
You could wrap it with SWIG as follows :
%include typemaps.i
double modf(double x, double *OUTPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *OUTPUT { double *ip };
double modf(double x, double *ip);
The Python output of the function would be a tuple containing both
output values.
%}
#endif
// I don't use this anywhere, get rid of it...
// Helper function for List output
// static PyObject* l_output_helper(PyObject* target, PyObject* o) {
// PyObject* o2;
// if (!target) {
// target = o;
// } else if (target == Py_None) {
// Py_DECREF(Py_None);
// target = o;
// } else {
// if (!PyList_Check(target)) {
// o2 = target;
// target = PyList_New(0);
// PyList_Append(target, o2);
// Py_XDECREF(o2);
// }
// PyList_Append(target,o);
// Py_XDECREF(o);
// }
// return target;
// }
%{
%}
// Force the argument to be ignored.
%typemap(python,ignore) int *L_OUTPUT(int temp),
short *L_OUTPUT(short temp),
long *L_OUTPUT(long temp),
unsigned int *L_OUTPUT(unsigned int temp),
unsigned short *L_OUTPUT(unsigned short temp),
unsigned long *L_OUTPUT(unsigned long temp),
unsigned char *L_OUTPUT(unsigned char temp),
signed char *L_OUTPUT(signed char temp),
float *L_OUTPUT(float temp),
double *L_OUTPUT(double temp)
{
$target = &temp;
}
%typemap(python,argout) int *L_OUTPUT,
short *L_OUTPUT,
long *L_OUTPUT,
unsigned int *L_OUTPUT,
unsigned short *L_OUTPUT,
unsigned long *L_OUTPUT,
unsigned char *L_OUTPUT,
signed char *L_OUTPUT
{
PyObject *o;
o = PyInt_FromLong((long) (*$source));
l_output_helper($target,o);
}
%typemap(python,argout) float *L_OUTPUT,
double *L_OUTPUT
{
PyObject *o;
o = PyFloat_FromDouble((double) (*$source));
$target = l_output_helper($target,o);
}
// These typemaps contributed by Robin Dunn
//----------------------------------------------------------------------
//
// T_OUTPUT typemap (and helper function) to return multiple argouts as
// a tuple instead of a list.
//
// Author: Robin Dunn
//----------------------------------------------------------------------
%{
static PyObject* t_output_helper(PyObject* target, PyObject* o) {
PyObject* o2;
PyObject* o3;
if (!target) {
target = o;
} else if (target == Py_None) {
Py_DECREF(Py_None);
target = o;
} else {
if (!PyTuple_Check(target)) {
o2 = target;
target = PyTuple_New(1);
PyTuple_SetItem(target, 0, o2);
}
o3 = PyTuple_New(1);
PyTuple_SetItem(o3, 0, o);
o2 = target;
target = PySequence_Concat(o2, o3);
Py_DECREF(o2);
Py_DECREF(o3);
}
return target;
}
%}
// Force the argument to be ignored.
%typemap(python,ignore) int *T_OUTPUT(int temp),
short *T_OUTPUT(short temp),
long *T_OUTPUT(long temp),
unsigned int *T_OUTPUT(unsigned int temp),
unsigned short *T_OUTPUT(unsigned short temp),
unsigned long *T_OUTPUT(unsigned long temp),
unsigned char *T_OUTPUT(unsigned char temp),
float *T_OUTPUT(float temp),
double *T_OUTPUT(double temp)
{
$target = &temp;
}
%typemap(python,argout) int *T_OUTPUT,
short *T_OUTPUT,
long *T_OUTPUT,
unsigned int *T_OUTPUT,
unsigned short *T_OUTPUT,
unsigned long *T_OUTPUT,
unsigned char *T_OUTPUT
{
PyObject *o;
o = PyInt_FromLong((long) (*$source));
$target = t_output_helper($target, o);
}
%typemap(python,argout) float *T_OUTPUT,
double *T_OUTPUT
{
PyObject *o;
o = PyFloat_FromDouble((double) (*$source));
$target = t_output_helper($target, o);
}
// Set the default output typemap
#ifdef OUTPUT_LIST
%typemap(python,ignore) int *OUTPUT = int *L_OUTPUT;
%typemap(python,ignore) short *OUTPUT = short *L_OUTPUT;
%typemap(python,ignore) long *OUTPUT = long *L_OUTPUT;
%typemap(python,ignore) unsigned *OUTPUT = unsigned *L_OUTPUT;
%typemap(python,ignore) unsigned short *OUTPUT = unsigned short *L_OUTPUT;
%typemap(python,ignore) unsigned long *OUTPUT = unsigned long *L_OUTPUT;
%typemap(python,ignore) unsigned char *OUTPUT = unsigned char *L_OUTPUT;
%typemap(python,ignore) signed char *OUTPUT = signed char *L_OUTPUT;
%typemap(python,ignore) double *OUTPUT = double *L_OUTPUT;
%typemap(python,ignore) float *OUTPUT = float *L_OUTPUT;
%typemap(python,argout) int *OUTPUT = int *L_OUTPUT;
%typemap(python,argout) short *OUTPUT = short *L_OUTPUT;
%typemap(python,argout) long *OUTPUT = long *L_OUTPUT;
%typemap(python,argout) unsigned *OUTPUT = unsigned *L_OUTPUT;
%typemap(python,argout) unsigned short *OUTPUT = unsigned short *L_OUTPUT;
%typemap(python,argout) unsigned long *OUTPUT = unsigned long *L_OUTPUT;
%typemap(python,argout) unsigned char *OUTPUT = unsigned char *L_OUTPUT;
%typemap(python,argout) signed char *OUTPUT = signed char *L_OUTPUT;
%typemap(python,argout) double *OUTPUT = double *L_OUTPUT;
%typemap(python,argout) float *OUTPUT = float *L_OUTPUT;
#else
%typemap(python,ignore) int *OUTPUT = int *T_OUTPUT;
%typemap(python,ignore) short *OUTPUT = short *T_OUTPUT;
%typemap(python,ignore) long *OUTPUT = long *T_OUTPUT;
%typemap(python,ignore) unsigned *OUTPUT = unsigned *T_OUTPUT;
%typemap(python,ignore) unsigned short *OUTPUT = unsigned short *T_OUTPUT;
%typemap(python,ignore) unsigned long *OUTPUT = unsigned long *T_OUTPUT;
%typemap(python,ignore) unsigned char *OUTPUT = unsigned char *T_OUTPUT;
%typemap(python,ignore) signed char *OUTPUT = signed char *T_OUTPUT;
%typemap(python,ignore) double *OUTPUT = double *T_OUTPUT;
%typemap(python,ignore) float *OUTPUT = float *T_OUTPUT;
%typemap(python,argout) int *OUTPUT = int *T_OUTPUT;
%typemap(python,argout) short *OUTPUT = short *T_OUTPUT;
%typemap(python,argout) long *OUTPUT = long *T_OUTPUT;
%typemap(python,argout) unsigned *OUTPUT = unsigned *T_OUTPUT;
%typemap(python,argout) unsigned short *OUTPUT = unsigned short *T_OUTPUT;
%typemap(python,argout) unsigned long *OUTPUT = unsigned long *T_OUTPUT;
%typemap(python,argout) unsigned char *OUTPUT = unsigned char *T_OUTPUT;
%typemap(python,argout) signed char *OUTPUT = signed char *T_OUTPUT;
%typemap(python,argout) double *OUTPUT = double *T_OUTPUT;
%typemap(python,argout) float *OUTPUT = float *T_OUTPUT;
#endif
// INOUT
// Mappings for an argument that is both an input and output
// parameter
#ifdef AUTODOC
%subsection "Input/Output Methods"
%text %{
The following methods can be applied to make a function parameter both
an input and output value. This combines the behavior of both the
"INPUT" and "OUTPUT" methods described earlier. Output values are
returned in the form of a Python tuple. To return a Python list,
using L_INOUT instead.
int *INOUT
short *INOUT
long *INOUT
unsigned int *INOUT
unsigned short *INOUT
unsigned long *INOUT
unsigned char *INOUT
float *INOUT
double *INOUT
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include typemaps.i
void neg(double *INOUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INOUT { double *x };
void neg(double *x);
Unlike C, this mapping does not directly modify the input value (since
this makes no sense in Python). Rather, the modified input value shows
up as the return value of the function. Thus, to apply this function
to a Python variable you might do this :
x = neg(x)
Note : previous versions of SWIG used the symbol 'BOTH' to mark
input/output arguments. This is still supported, but will be slowly
phased out in future releases.
%}
#endif
%typemap(python,in) int *INOUT = int *INPUT;
%typemap(python,in) short *INOUT = short *INPUT;
%typemap(python,in) long *INOUT = long *INPUT;
%typemap(python,in) unsigned *INOUT = unsigned *INPUT;
%typemap(python,in) unsigned short *INOUT = unsigned short *INPUT;
%typemap(python,in) unsigned long *INOUT = unsigned long *INPUT;
%typemap(python,in) unsigned char *INOUT = unsigned char *INPUT;
%typemap(python,in) float *INOUT = float *INPUT;
%typemap(python,in) double *INOUT = double *INPUT;
%typemap(python,argout) int *INOUT = int *OUTPUT;
%typemap(python,argout) short *INOUT = short *OUTPUT;
%typemap(python,argout) long *INOUT = long *OUTPUT;
%typemap(python,argout) unsigned *INOUT = unsigned *OUTPUT;
%typemap(python,argout) unsigned short *INOUT = unsigned short *OUTPUT;
%typemap(python,argout) unsigned long *INOUT = unsigned long *OUTPUT;
%typemap(python,argout) unsigned char *INOUT = unsigned char *OUTPUT;
%typemap(python,argout) float *INOUT = float *OUTPUT;
%typemap(python,argout) double *INOUT = double *OUTPUT;
%typemap(python,in) int *T_INOUT = int *INPUT;
%typemap(python,in) short *T_INOUT = short *INPUT;
%typemap(python,in) long *T_INOUT = long *INPUT;
%typemap(python,in) unsigned *T_INOUT = unsigned *INPUT;
%typemap(python,in) unsigned short *T_INOUT = unsigned short *INPUT;
%typemap(python,in) unsigned long *T_INOUT = unsigned long *INPUT;
%typemap(python,in) unsigned char *T_INOUT = unsigned char *INPUT;
%typemap(python,in) float *T_INOUT = float *INPUT;
%typemap(python,in) double *T_INOUT = double *INPUT;
%typemap(python,argout) int *T_INOUT = int *T_OUTPUT;
%typemap(python,argout) short *T_INOUT = short *T_OUTPUT;
%typemap(python,argout) long *T_INOUT = long *T_OUTPUT;
%typemap(python,argout) unsigned *T_INOUT = unsigned *T_OUTPUT;
%typemap(python,argout) unsigned short *T_INOUT = unsigned short *T_OUTPUT;
%typemap(python,argout) unsigned long *T_INOUT = unsigned long *T_OUTPUT;
%typemap(python,argout) unsigned char *T_INOUT = unsigned char *T_OUTPUT;
%typemap(python,argout) float *T_INOUT = float *T_OUTPUT;
%typemap(python,argout) double *T_INOUT = double *T_OUTPUT;
%typemap(python,in) int *L_INOUT = int *INPUT;
%typemap(python,in) short *L_INOUT = short *INPUT;
%typemap(python,in) long *L_INOUT = long *INPUT;
%typemap(python,in) unsigned *L_INOUT = unsigned *INPUT;
%typemap(python,in) unsigned short *L_INOUT = unsigned short *INPUT;
%typemap(python,in) unsigned long *L_INOUT = unsigned long *INPUT;
%typemap(python,in) unsigned char *L_INOUT = unsigned char *INPUT;
%typemap(python,in) float *L_INOUT = float *INPUT;
%typemap(python,in) double *L_INOUT = double *INPUT;
%typemap(python,argout) int *L_INOUT = int *L_OUTPUT;
%typemap(python,argout) short *L_INOUT = short *L_OUTPUT;
%typemap(python,argout) long *L_INOUT = long *L_OUTPUT;
%typemap(python,argout) unsigned *L_INOUT = unsigned *L_OUTPUT;
%typemap(python,argout) unsigned short *L_INOUT = unsigned short *L_OUTPUT;
%typemap(python,argout) unsigned long *L_INOUT = unsigned long *L_OUTPUT;
%typemap(python,argout) unsigned char *L_INOUT = unsigned char *L_OUTPUT;
%typemap(python,argout) float *L_INOUT = float *L_OUTPUT;
%typemap(python,argout) double *L_INOUT = double *L_OUTPUT;
// Backwards compatibility
%typemap(python,in) int *BOTH = int *INOUT;
%typemap(python,in) short *BOTH = short *INOUT;
%typemap(python,in) long *BOTH = long *INOUT;
%typemap(python,in) unsigned *BOTH = unsigned *INOUT;
%typemap(python,in) unsigned short *BOTH = unsigned short *INOUT;
%typemap(python,in) unsigned long *BOTH = unsigned long *INOUT;
%typemap(python,in) unsigned char *BOTH = unsigned char *INOUT;
%typemap(python,in) float *BOTH = float *INOUT;
%typemap(python,in) double *BOTH = double *INOUT;
%typemap(python,argout) int *BOTH = int *INOUT;
%typemap(python,argout) short *BOTH = short *INOUT;
%typemap(python,argout) long *BOTH = long *INOUT;
%typemap(python,argout) unsigned *BOTH = unsigned *INOUT;
%typemap(python,argout) unsigned short *BOTH = unsigned short *INOUT;
%typemap(python,argout) unsigned long *BOTH = unsigned long *INOUT;
%typemap(python,argout) unsigned char *BOTH = unsigned char *INOUT;
%typemap(python,argout) float *BOTH = float *INOUT;
%typemap(python,argout) double *BOTH = double *INOUT;
%typemap(python,in) int *T_BOTH = int *T_INOUT;
%typemap(python,in) short *T_BOTH = short *T_INOUT;
%typemap(python,in) long *T_BOTH = long *T_INOUT;
%typemap(python,in) unsigned *T_BOTH = unsigned *T_INOUT;
%typemap(python,in) unsigned short *T_BOTH = unsigned short *T_INOUT;
%typemap(python,in) unsigned long *T_BOTH = unsigned long *T_INOUT;
%typemap(python,in) unsigned char *T_BOTH = unsigned char *T_INOUT;
%typemap(python,in) float *T_BOTH = float *T_INOUT;
%typemap(python,in) double *T_BOTH = double *T_INOUT;
%typemap(python,argout) int *T_BOTH = int *T_INOUT;
%typemap(python,argout) short *T_BOTH = short *T_INOUT;
%typemap(python,argout) long *T_BOTH = long *T_INOUT;
%typemap(python,argout) unsigned *T_BOTH = unsigned *T_INOUT;
%typemap(python,argout) unsigned short *T_BOTH = unsigned short *T_INOUT;
%typemap(python,argout) unsigned long *T_BOTH = unsigned long *T_INOUT;
%typemap(python,argout) unsigned char *T_BOTH = unsigned char *T_INOUT;
%typemap(python,argout) float *T_BOTH = float *T_INOUT;
%typemap(python,argout) double *T_BOTH = double *T_INOUT;
// --------------------------------------------------------------------
// Special types
//
// --------------------------------------------------------------------
#ifdef AUTODOC
%subsection "Special Methods"
%text %{
The typemaps.i library also provides the following mappings :
PyObject *
When a PyObject * appears as either an input value or return
value of a function, SWIG passes it through unmodified. Thus,
if you want to write a C function that operates on PyObjects,
it is easy to write. For example :
%include typemaps.i
PyObject *spam(PyObject *obj1, int n);
Unlike normal Python wrapper functions, These functions can
use any combination of parameters that you wish.
%}
#endif
// If a PyObject * appears as either an argument or a function return
// value, simply pass it straight through.
%typemap(python,in) PyObject * {
$target = $source;
}
%typemap(python,out) PyObject * {
$target = $source;
}