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,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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue