update swig on windows
This commit is contained in:
23
winx64/bin/swigwin-4.0.0/Examples/python/exception/Makefile
Normal file
23
winx64/bin/swigwin-4.0.0/Examples/python/exception/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
45
winx64/bin/swigwin-4.0.0/Examples/python/exception/example.h
Normal file
45
winx64/bin/swigwin-4.0.0/Examples/python/exception/example.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* File : example.h */
|
||||
|
||||
#include <string.h>
|
||||
#ifndef SWIG
|
||||
struct A {
|
||||
};
|
||||
#endif
|
||||
|
||||
class Exc {
|
||||
public:
|
||||
Exc(int c, const char *m) {
|
||||
code = c;
|
||||
strncpy(msg,m,256);
|
||||
}
|
||||
int code;
|
||||
char msg[256];
|
||||
};
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
27
winx64/bin/swigwin-4.0.0/Examples/python/exception/example.i
Normal file
27
winx64/bin/swigwin-4.0.0/Examples/python/exception/example.i
Normal file
@@ -0,0 +1,27 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%catches(int) Test::simple();
|
||||
%catches(const char *) Test::message();
|
||||
%catches(Exc) Test::hosed();
|
||||
%catches(A*) Test::unknown();
|
||||
%catches(int, const char *, Exc) Test::multi(int x);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
%inline %{
|
||||
// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
42
winx64/bin/swigwin-4.0.0/Examples/python/exception/runme.py
Normal file
42
winx64/bin/swigwin-4.0.0/Examples/python/exception/runme.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# file: runme.py
|
||||
|
||||
# Throw a lot of exceptions
|
||||
|
||||
import example
|
||||
|
||||
t = example.Test()
|
||||
try:
|
||||
t.unknown()
|
||||
except RuntimeError, e:
|
||||
print "incomplete type", e.args[0]
|
||||
|
||||
try:
|
||||
t.simple()
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
|
||||
try:
|
||||
t.message()
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
|
||||
if not example.is_python_builtin():
|
||||
try:
|
||||
t.hosed()
|
||||
except example.Exc, e:
|
||||
print e.code, e.msg
|
||||
else:
|
||||
try:
|
||||
t.hosed()
|
||||
except BaseException, e:
|
||||
# Throwing builtin classes as exceptions not supported (-builtin
|
||||
# option)
|
||||
print e
|
||||
|
||||
for i in range(1, 4):
|
||||
try:
|
||||
t.multi(i)
|
||||
except RuntimeError, e:
|
||||
print e.args[0]
|
||||
except example.Exc, e:
|
||||
print e.code, e.msg
|
||||
Reference in New Issue
Block a user