Exceptions support for C. exception_order test shows how to use type information to achieve correct catching order. Examples cleanup.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10671 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
03d275e42f
commit
88facfd390
27 changed files with 223 additions and 429 deletions
|
|
@ -1,21 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
|
||||
|
||||
run:
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
|
||||
|
||||
check: all
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include "example.h"
|
||||
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
class A {
|
||||
public:
|
||||
int i;
|
||||
A(int i) : i(i) {}
|
||||
void foo() {
|
||||
}
|
||||
};
|
||||
|
||||
class B : public A {
|
||||
public:
|
||||
B(int i) : A(i) {}
|
||||
};
|
||||
|
||||
class MyClass {
|
||||
public:
|
||||
void foo(A a, A* aa, A* aaa[5]) {
|
||||
printf("a.i = %d\n", a.i);
|
||||
printf("aa->i = %d\n", aa->i);
|
||||
int i = 0;
|
||||
while (aaa[i]) {
|
||||
printf("aaa[%d]->i = %d\n", i, aaa[i]->i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void bar(int x, int* px, int** xs) {
|
||||
printf("x = %d\n", x);
|
||||
printf("*px = %d\n", *px);
|
||||
int i = 0;
|
||||
while (xs[i]) {
|
||||
printf("*xs[%d] = %d\n", i, *xs[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void foo_1(A& a, A& b) {
|
||||
printf("a.i = %d\n", a.i);
|
||||
printf("b.i = %d\n", b.i);
|
||||
a.i++;
|
||||
b.i++;
|
||||
}
|
||||
|
||||
void foo_2(int& x, double& d) {
|
||||
printf("x = %d d = %f\n", x, d);
|
||||
x++;
|
||||
d++;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "example_proxy.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
MyClass* mc = new_MyClass();
|
||||
A* a = new_A(123), *b = new_A(234), *as[5];
|
||||
int i, j = 321, *js[5];
|
||||
double d = 55.0;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
as[i] = new_A(20 + i);
|
||||
js[i] = (int*) malloc(sizeof(int));
|
||||
*js[i] = 10 + i;
|
||||
}
|
||||
|
||||
as[i] = 0;
|
||||
js[i] = 0;
|
||||
|
||||
MyClass_bar(mc, j, &j, js);
|
||||
MyClass_foo(mc, a, b, as);
|
||||
MyClass_foo_1(mc, a, b);
|
||||
MyClass_foo_1(mc, a, b);
|
||||
|
||||
MyClass_foo_2(mc, &j, &d);
|
||||
MyClass_foo_2(mc, &j, &d);
|
||||
|
||||
delete_A(a);
|
||||
delete_A(b);
|
||||
delete_MyClass(mc);
|
||||
for (i = 0; i < 4; ++i)
|
||||
delete_A(as[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
reference
|
||||
simple
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
printf("%d shapes remain\n", Shape_nshapes_get());
|
||||
printf("Goodbye\n");
|
||||
return 0;
|
||||
|
||||
SWIG_exit(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
|
||||
|
||||
run:
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
|
||||
|
||||
check: all
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "example.h"
|
||||
|
||||
void foo_by_val(Bar bar) {
|
||||
bar.set(123);
|
||||
printf("inside foo_by_val: %d\n", bar.get());
|
||||
}
|
||||
|
||||
void foo_by_ref(Bar& bar) {
|
||||
bar.set(123);
|
||||
printf("inside foo_by_ref: %d\n", bar.get());
|
||||
}
|
||||
|
||||
void foo_by_ptr(Bar* bar) {
|
||||
bar->set(123);
|
||||
printf("inside foo_by_ptr: %d\n", bar->get());
|
||||
}
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
class Bar {
|
||||
private:
|
||||
int x;
|
||||
public:
|
||||
Bar() : x(0) {}
|
||||
~Bar() {}
|
||||
void set(int x) { this->x = x; }
|
||||
int get() { return x; }
|
||||
};
|
||||
|
||||
void foo_by_val(Bar bar);
|
||||
void foo_by_ref(Bar& bar);
|
||||
void foo_by_ptr(Bar* bar);
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "example_proxy.h"
|
||||
|
||||
void test(Bar * bar) {
|
||||
printf("value of x is %d\n", Bar_get(bar));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Bar* bar = new_Bar();
|
||||
test(bar);
|
||||
foo_by_val(bar);
|
||||
test(bar);
|
||||
foo_by_ptr(bar);
|
||||
test(bar);
|
||||
foo_by_ref(bar);
|
||||
test(bar);
|
||||
delete_Bar(bar);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
|
||||
|
||||
run:
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
|
||||
|
||||
check: all
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#include "example.h"
|
||||
|
||||
Bar foo_ret_val() {
|
||||
return Bar();
|
||||
}
|
||||
|
||||
Bar *foo_ret_ptr(Bar *bar) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
Bar &foo_ret_ref(Bar &bar) {
|
||||
return bar;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
class Bar {
|
||||
private:
|
||||
int x;
|
||||
public:
|
||||
Bar() : x(0) {}
|
||||
~Bar() {}
|
||||
void set(int x) { this->x = x; }
|
||||
int get() { return x; }
|
||||
};
|
||||
|
||||
Bar foo_ret_val();
|
||||
Bar& foo_ret_ref(Bar& bar);
|
||||
Bar* foo_ret_ptr(Bar* bar);
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "example_proxy.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Bar *b = foo_ret_val();
|
||||
printf("x = %d\n", Bar_get(b));
|
||||
|
||||
Bar *c = new_Bar();
|
||||
Bar *bp = foo_ret_ptr(c);
|
||||
//Bar *br = foo_ret_ref(c);
|
||||
|
||||
delete_Bar(b);
|
||||
delete_Bar(bp);
|
||||
delete_Bar(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +1,7 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
double *Foo_ptr = &Foo;
|
||||
char *my_str = "hello, world!";
|
||||
char *array_of_strs[] = { "one", "two" };
|
||||
|
||||
char *get_str(int i, void* ptr, float ff) {
|
||||
return array_of_strs[i];
|
||||
}
|
||||
double Foo = 3.0;
|
||||
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
|
|
@ -22,3 +14,5 @@ int gcd(int x, int y) {
|
|||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@
|
|||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
extern double *Foo_ptr;
|
||||
extern char *my_str;
|
||||
extern char **array_of_strs;
|
||||
extern char *get_str(int i, void* ptr, float ff);
|
||||
extern int gcd(int x, int y);
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@ int main(int argc, char **argv) {
|
|||
int a = 35;
|
||||
int b = 15;
|
||||
printf("Foo is %f\n", Foo);
|
||||
printf("Foo by ptr is \%f\n", *Foo_ptr);
|
||||
printf("my_str is: %s\n", my_str);
|
||||
printf("GCD(%d, %d)=%d\n", a, b, gcd(a, b));
|
||||
printf("array_of_strs contains %s and %s\n", get_str(0, 0, 0), get_str(1, 0, 0));
|
||||
return 0;
|
||||
SWIG_exit(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "c_arguments/c_arguments_proxy.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
A *a = new_A();
|
||||
|
||||
A *a1, *a2, *a3;
|
||||
|
||||
a1 = foo_1(a);
|
||||
a2 = foo_2(a);
|
||||
a3 = foo_3(a);
|
||||
|
||||
delete_A(a);
|
||||
delete_A(a1);
|
||||
delete_A(a2);
|
||||
delete_A(a3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
65
Examples/test-suite/c/exception_order_runme.c
Normal file
65
Examples/test-suite/c/exception_order_runme.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "exception_order/exception_order_proxy.h"
|
||||
|
||||
int main() {
|
||||
A* a = new_A();
|
||||
|
||||
SWIG_try {
|
||||
A_foo(a);
|
||||
}
|
||||
SWIG_catch(E1) {
|
||||
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
fprintf(stderr, "foo: bad exception order\n");
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
A_bar(a);
|
||||
}
|
||||
SWIG_catch(E2) {
|
||||
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
fprintf(stderr, "bar: bad exception order\n");
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
A_foobar(a);
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
if (strcmp(SWIG_exception.msg, "postcatch unknown") != 0) {
|
||||
fprintf(stderr, "bad exception order\n");
|
||||
SWIG_throw_msg(SWIG_exception.klass, SWIG_exception.msg);
|
||||
}
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
A_barfoo(a, 1);
|
||||
}
|
||||
SWIG_catch(E1) {
|
||||
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
fprintf(stderr, "barfoo(1): bad exception order\n");
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
A_barfoo(a, 2);
|
||||
}
|
||||
SWIG_catch(E2) {
|
||||
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
fprintf(stderr, "barfoo(2): bad exception order\n");
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
%module c_arguments
|
||||
|
||||
%inline %{
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() : i(0) {}
|
||||
int i;
|
||||
};
|
||||
|
||||
A foo_1(A *a) {
|
||||
return *a;
|
||||
}
|
||||
|
||||
A * foo_2(A *a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
A & foo_3(A *a) {
|
||||
return *a;
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
@ -33,8 +33,21 @@
|
|||
}
|
||||
#endif
|
||||
|
||||
%catches(E1,E2*,ET<int>,ET<double>,...) A::barfoo(int i);
|
||||
/*
|
||||
* Additional typemaps needed to handle exception order in C.
|
||||
*/
|
||||
#if defined(SWIGC)
|
||||
%typemap(throws) SWIGTYPE {
|
||||
SwigObj$1_basetype *_c_ex = _wrap_new_$1_basetype();
|
||||
SWIG_CThrowException(_c_ex, "C++ $1_type exception thrown");
|
||||
}
|
||||
|
||||
%typemap(throws) ET<int>, ET<double> {
|
||||
SWIG_CThrowException(NULL, "C++ $1_type exception thrown");
|
||||
}
|
||||
#endif
|
||||
|
||||
%catches(E1,E2*,ET<int>,ET<double>,...) A::barfoo(int i);
|
||||
|
||||
%allowexception efoovar;
|
||||
%allowexception A::efoovar;
|
||||
|
|
|
|||
185
Lib/c/c.swg
185
Lib/c/c.swg
|
|
@ -13,23 +13,27 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
typedef struct {
|
||||
void *obj;
|
||||
const char **typenames;
|
||||
} SwigObj;
|
||||
%}
|
||||
|
||||
// typemaps for function parameters
|
||||
|
||||
%typemap(ctype) void, short, int, long, char, float, double "$1_type"
|
||||
%typemap(ctype) void, short, int, long, char, float, double, bool "$1_type"
|
||||
%typemap(ctype) unsigned short, unsigned int, unsigned long, unsigned char "$1_type"
|
||||
%typemap(ctype) void *, short *, int *, long *, char *, float *, double * "$1_type"
|
||||
%typemap(ctype) void **, short **, int **, long **, char **, float **, double ** "$1_type"
|
||||
%typemap(ctype) void *, short *, int *, long *, char *, float *, double *, bool * "$1_type"
|
||||
%typemap(ctype) void **, short **, int **, long **, char **, float **, double **, bool ** "$1_type"
|
||||
%typemap(ctype) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1_type"
|
||||
%typemap(ctype) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1_type"
|
||||
%typemap(ctype) short &, int &, long &, char &, float &, double & "$1_basetype *"
|
||||
%typemap(ctype) short &, int &, long &, char &, float &, double &, bool & "$1_basetype *"
|
||||
%typemap(ctype) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1_basetype *"
|
||||
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_type"
|
||||
%typemap(ctype) const short, const int, const long, const char, const float, const double, const bool "$1_type"
|
||||
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_type"
|
||||
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
|
||||
%typemap(ctype) bool "_Bool"
|
||||
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype*) $input;"
|
||||
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1_type"
|
||||
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1 = ($1_basetype*) $input;"
|
||||
%typemap(ctype) SWIGTYPE "struct SwigObj$1_type *"
|
||||
%typemap(ctype) SWIGTYPE * "struct SwigObj$1_type"
|
||||
%typemap(ctype) SWIGTYPE & "struct SwigObj$1_basetype*"
|
||||
|
|
@ -81,13 +85,12 @@
|
|||
|
||||
// typemaps for return values
|
||||
|
||||
%typemap(couttype) void, short, int, long, char, float, double "$1_type"
|
||||
%typemap(couttype) void *, short *, int *, long *, char *, float *, double* "$1_type"
|
||||
%typemap(couttype) const short, const int, const long, const char, const float, const double "$1_basetype"
|
||||
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
|
||||
%typemap(couttype) short &, int &, long &, char &, float &, double & "$1_basetype *"
|
||||
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
|
||||
%typemap(couttype) bool "_Bool"
|
||||
%typemap(couttype) void, short, int, long, char, float, double, bool "$1_type"
|
||||
%typemap(couttype) void *, short *, int *, long *, char *, float *, double*, bool* "$1_type"
|
||||
%typemap(couttype) const short, const int, const long, const char, const float, const double, const bool "$1_basetype"
|
||||
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1_type"
|
||||
%typemap(couttype) short &, int &, long &, char &, float &, double &, bool & "$1_basetype *"
|
||||
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1_basetype const *"
|
||||
%typemap(couttype) SWIGTYPE "struct SwigObj$1_type *"
|
||||
%typemap(couttype) SWIGTYPE * "struct SwigObj$1_type"
|
||||
%typemap(couttype) SWIGTYPE & "struct SwigObj$1_basetype *"
|
||||
|
|
@ -132,25 +135,33 @@
|
|||
|
||||
// exception handling
|
||||
|
||||
%typemap(throws) int, long, short, unsigned int, unsigned long, unsigned short {
|
||||
char error_msg[256];
|
||||
sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
|
||||
SWIG_CThrowException(0, error_msg);
|
||||
}
|
||||
|
||||
%typemap(throws) char *, const char * {
|
||||
SWIG_CThrowException(0, $1);
|
||||
}
|
||||
|
||||
// this should match only non-built-in and non-template objects
|
||||
%typemap(throws) SWIGTYPE {
|
||||
(void)_e;
|
||||
SWIG_CThrowException(3, "C++ $1_type exception thrown");
|
||||
SWIG_CThrowException(0, "C++ $1_type exception thrown");
|
||||
}
|
||||
|
||||
%insert("runtime") %{
|
||||
|
||||
#define SWIG_MAX_HANDLERS 256
|
||||
#define SWIG_MAX_RT_STACK 256
|
||||
|
||||
SWIGEXPORTC int SWIG_exception_code;
|
||||
SWIGEXPORTC struct {
|
||||
int code;
|
||||
char *msg;
|
||||
SwigObj *klass;
|
||||
} SWIG_exception;
|
||||
|
||||
SWIGEXPORTC jmp_buf SWIG_rt_env;
|
||||
SWIGEXPORTC int SWIG_rt_init = 0;
|
||||
SWIGINTERN struct {
|
||||
int reg;
|
||||
int code;
|
||||
void (*fun)();
|
||||
} SWIG_Handlers[SWIG_MAX_HANDLERS];
|
||||
SWIGINTERN int SWIG_next_handler = 0;
|
||||
SWIGINTERN jmp_buf *SWIG_rt_stack_base = 0;
|
||||
SWIGINTERN jmp_buf *SWIG_rt_stack_ptr = 0;
|
||||
|
||||
|
|
@ -167,6 +178,13 @@ SWIGINTERN void SWIG_rt_stack_pop() {
|
|||
memcpy(SWIG_rt_env, SWIG_rt_stack_ptr, sizeof(SWIG_rt_env));
|
||||
}
|
||||
|
||||
SWIGINTERN void SWIG_cleanup() {
|
||||
if (SWIG_rt_stack_base)
|
||||
free(SWIG_rt_stack_base);
|
||||
if (SWIG_exception.msg)
|
||||
free(SWIG_exception.msg);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
@ -175,93 +193,112 @@ SWIGEXPORTC void SWIG_rt_try() {
|
|||
SWIG_rt_stack_push();
|
||||
}
|
||||
|
||||
SWIGEXPORTC int SWIG_rt_catch(int code) {
|
||||
int result = (SWIG_exception_code == code);
|
||||
SWIGEXPORTC int SWIG_rt_catch(const char *type) {
|
||||
int result = 0;
|
||||
if (!type || (strcmp("SWIG_AnyException", type) == 0)) {
|
||||
result = 1;
|
||||
}
|
||||
else if (SWIG_exception.klass) {
|
||||
int i = 0;
|
||||
while (SWIG_exception.klass->typenames[i]) {
|
||||
if (strcmp(SWIG_exception.klass->typenames[i++], type) == 0) {
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
SWIG_rt_stack_pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
SWIGEXPORTC void SWIG_rt_throw(int code) {
|
||||
longjmp(SWIG_rt_env, code);
|
||||
SWIGEXPORTC void SWIG_rt_throw(SwigObj *klass, const char *msg) {
|
||||
if (SWIG_exception.msg) {
|
||||
free(SWIG_exception.msg);
|
||||
SWIG_exception.msg = (char *) 0;
|
||||
}
|
||||
if (msg) {
|
||||
SWIG_exception.msg = (char *) malloc(strlen(msg));
|
||||
strcpy(SWIG_exception.msg, msg);
|
||||
}
|
||||
SWIG_exception.klass = klass;
|
||||
longjmp(SWIG_rt_env, 1);
|
||||
}
|
||||
|
||||
SWIGEXPORTC void SWIG_rt_endtry() {
|
||||
if (SWIG_exception.msg)
|
||||
free(SWIG_exception.msg);
|
||||
SWIG_rt_stack_pop();
|
||||
longjmp(SWIG_rt_env, SWIG_exception_code);
|
||||
longjmp(SWIG_rt_env, SWIG_exception.code);
|
||||
}
|
||||
|
||||
SWIGEXPORTC void SWIG_Register_Handler(int code, void (*fun)()) {
|
||||
if (SWIG_next_handler < SWIG_MAX_HANDLERS) {
|
||||
int i = SWIG_next_handler++;
|
||||
SWIG_Handlers[i].reg = 1;
|
||||
SWIG_Handlers[i].code = code;
|
||||
SWIG_Handlers[i].fun = fun;
|
||||
}
|
||||
}
|
||||
|
||||
SWIGEXPORTC void SWIG_Unregister_Handler(int code) {
|
||||
int i;
|
||||
for (i = 0; i < SWIG_next_handler; ++i) {
|
||||
if (SWIG_Handlers[i].code == code)
|
||||
SWIG_Handlers[i].reg = 0;
|
||||
}
|
||||
SWIGEXPORTC int SWIG_exit(int code) {
|
||||
SWIG_cleanup();
|
||||
exit(code);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIGINTERN void SWIG_terminate() {
|
||||
fprintf(stderr, "Unhandled exception: %s\n%s (error code: %d)\nExitting...\n",
|
||||
SWIG_exception.klass->typenames[0],
|
||||
SWIG_exception.msg,
|
||||
SWIG_exception.code);
|
||||
SWIG_exit(SWIG_exception.code);
|
||||
}
|
||||
|
||||
SWIGINTERN void SWIG_Runtime_init() {
|
||||
int i, code;
|
||||
if (!SWIG_rt_init) {
|
||||
SWIG_rt_init = 1;
|
||||
for (i = 0; i < SWIG_MAX_HANDLERS; ++i)
|
||||
SWIG_Handlers[i].reg = 0;
|
||||
SWIG_rt_stack_base = SWIG_rt_stack_ptr = (jmp_buf *) malloc(sizeof(jmp_buf) * SWIG_MAX_RT_STACK);
|
||||
if (code = setjmp(SWIG_rt_env)) {
|
||||
for (i = 0; i < SWIG_next_handler; ++i) {
|
||||
if (SWIG_Handlers[i].reg)
|
||||
if (SWIG_Handlers[i].code == code)
|
||||
SWIG_Handlers[i].fun();
|
||||
}
|
||||
fprintf(stderr, "Unhandled exception. Exitting...\n");
|
||||
exit(code);
|
||||
}
|
||||
if (SWIG_exception.code = setjmp(SWIG_rt_env))
|
||||
SWIG_terminate();
|
||||
}
|
||||
}
|
||||
|
||||
SWIGINTERN void SWIG_CThrowException(int code, char *msg) {
|
||||
SWIGINTERN void SWIG_CThrowException(void *klass, const char *msg) {
|
||||
if (SWIG_rt_init)
|
||||
longjmp(SWIG_rt_env, code);
|
||||
else {
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
exit(code);
|
||||
}
|
||||
SWIG_rt_throw((SwigObj *) klass, msg);
|
||||
else
|
||||
SWIG_terminate();
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%insert("proxy_header") %{
|
||||
// special value indicating any type of exception like 'catch(...)'
|
||||
#define SWIG_AnyException "SWIG_AnyException"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
void SWIG_Register_Handler(int code, void (*fun)());
|
||||
void SWIG_Unregister_Handler(int code);
|
||||
int SWIG_exception_try();
|
||||
void SWIG_exception_throw();
|
||||
|
||||
SWIGIMPORT jmp_buf SWIG_rt_env;
|
||||
SWIGIMPORT int SWIG_exception_code;
|
||||
|
||||
typedef struct {
|
||||
void *obj;
|
||||
const char **typenames;
|
||||
} SwigObj;
|
||||
|
||||
SWIGIMPORT struct {
|
||||
int code;
|
||||
char *msg;
|
||||
SwigObj *klass;
|
||||
} SWIG_exception;
|
||||
|
||||
SWIGIMPORT void SWIG_rt_try();
|
||||
SWIGIMPORT int SWIG_rt_catch();
|
||||
SWIGIMPORT void SWIG_rt_throw(int val);
|
||||
SWIGIMPORT int SWIG_rt_catch(const char *type);
|
||||
SWIGIMPORT void SWIG_rt_throw(SwigObj *klass, const char * msg);
|
||||
SWIGIMPORT int SWIG_rt_endtry();
|
||||
SWIGIMPORT int SWIG_exit(int code);
|
||||
|
||||
#define SWIG_try \
|
||||
SWIG_rt_try(); \
|
||||
if ((SWIG_exception_code = setjmp(SWIG_rt_env)) == 0)
|
||||
#define SWIG_catch(val) else if (SWIG_rt_catch(val))
|
||||
#define SWIG_throw(val) SWIG_rt_throw(val);
|
||||
if ((SWIG_exception.code = setjmp(SWIG_rt_env)) == 0)
|
||||
#define SWIG_catch(type) else if (SWIG_rt_catch(#type))
|
||||
#define SWIG_throw(klass) SWIG_rt_throw((SwigObj *) klass, 0);
|
||||
#define SWIG_throw_msg(klass, msg) SWIG_rt_throw((SwigObj *) klass, msg);
|
||||
#define SWIG_endtry else SWIG_rt_endtry();
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -212,6 +212,21 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
|
|||
|
||||
#endif // SWIGLUA
|
||||
|
||||
#ifdef SWIGC
|
||||
|
||||
%inline %{
|
||||
struct SWIG_CException {
|
||||
SWIG_CException(int code) {
|
||||
SWIG_exception.code = code;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
#define SWIG_exception(code, msg)\
|
||||
SWIG_CThrowException(_wrap_new_SWIG_CException(code), msg);
|
||||
|
||||
#endif // SWIGC
|
||||
|
||||
#ifdef __cplusplus
|
||||
/*
|
||||
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public:
|
|||
SWIG_typemap_lang("c");
|
||||
SWIG_config_file("c.swg");
|
||||
|
||||
// FIXME
|
||||
Swig_typemap_class_distinguish(false);
|
||||
|
||||
// look for certain command line options
|
||||
|
|
@ -185,8 +186,6 @@ public:
|
|||
virtual int globalvariableHandler(Node *n) {
|
||||
SwigType *type = Getattr(n, "type");
|
||||
String *type_str = SwigType_str(type, 0);
|
||||
//if (!CPlusPlus)
|
||||
// Printv(f_wrappers, "SWIGEXPORTC ", type_str, " ", Getattr(n, "name"), ";\n", NIL);
|
||||
if (proxy_flag) {
|
||||
Printv(f_proxy_header, "SWIGIMPORT ", type_str, " ", Getattr(n, "name"), ";\n", NIL);
|
||||
}
|
||||
|
|
@ -256,12 +255,12 @@ public:
|
|||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* getTypeSymbol()
|
||||
* getMangledType()
|
||||
*
|
||||
* incomplete for now...
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
const char *getTypeSymbol(String *type) {
|
||||
const char *getMangledType(String *type) {
|
||||
char *c = Char(type);
|
||||
if (strcmp(c, "int") == 0)
|
||||
return "i";
|
||||
|
|
@ -332,7 +331,7 @@ public:
|
|||
if (parms)
|
||||
Append(over_suffix, "_");
|
||||
for (p = parms; p; p = nextSibling(p)) {
|
||||
Append(over_suffix, getTypeSymbol(Getattr(p, "type")));
|
||||
Append(over_suffix, getMangledType(Getattr(p, "type")));
|
||||
}
|
||||
Append(name, over_suffix);
|
||||
}
|
||||
|
|
@ -618,7 +617,8 @@ public:
|
|||
// emit "class"-struct definition
|
||||
Printv(sobj, "struct SwigObj", name, " {\n void* obj;\n", NIL);
|
||||
if (runtime_flag)
|
||||
Printf(sobj, " const char* typenames[%d];\n}", Len(baselist) + 2);
|
||||
//Printf(sobj, " const char *typenames[%d];\n}", Len(baselist) + 2);
|
||||
Printf(sobj, " const char **typenames;\n}");
|
||||
else
|
||||
Printf(sobj, "}");
|
||||
|
||||
|
|
@ -627,7 +627,7 @@ public:
|
|||
|
||||
// declare it in the proxy header
|
||||
if (proxy_flag)
|
||||
Printv(f_proxy_header, "typedef ", sobj, " ", name, ";\n\n", NIL);
|
||||
Printv(f_proxy_header, "#define ", name, " SwigObj\n\n", NIL);
|
||||
|
||||
Delete(sobj);
|
||||
Delete(name);
|
||||
|
|
@ -908,6 +908,7 @@ public:
|
|||
void emit_runtime_make_object(Node *n, String *classname, String *code) {
|
||||
// store the name of each class in the hierarchy
|
||||
List *baselist = Getattr(parentNode(n), "bases");
|
||||
Printf(code, "result->typenames = (const char **) malloc(%d*sizeof(const char*));\n", Len(baselist) + 2);
|
||||
Printv(code, "result->typenames[0] = Swig_typename_", classname, ";\n", NIL);
|
||||
int i = 1;
|
||||
if (baselist) {
|
||||
|
|
@ -1059,8 +1060,9 @@ public:
|
|||
if (typecheck_flag)
|
||||
emit_runtime_typecheck(newclassname, destr_name, code);
|
||||
|
||||
Printv(code, "if (arg1)\n if (arg1->obj) {\n", NIL);
|
||||
Printv(code, " delete (", classname, "*) (arg1->obj);\nfree(arg1);\n", NIL);
|
||||
Printv(code, "if (arg1) if (arg1->obj) {\n", NIL);
|
||||
Printv(code, " delete (", classname, "*) (arg1->obj);\n", NIL);
|
||||
Printv(code, " free(arg1->typenames);\n free(arg1);\n", NIL);
|
||||
Printv(code, " arg1 = (", sobj_name, "*)0;\n}\n", NIL);
|
||||
Setattr(n, "wrap:action", code);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue