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