Fixed naming convention issues (internal Swig variables, shadow -> proxy, test.c -> runme.c, etc.), modified Makefiles, bugfixes ("name" -> "sym:name"). Started C test-suite.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10655 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Maciej Drwal 2008-07-09 20:02:20 +00:00
commit a13c5976b5
35 changed files with 925 additions and 639 deletions

View file

@ -1,14 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
MAIN = test.c
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c_cpp
clean:
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
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* *~

View file

@ -1,2 +1,2 @@
#include "example.h"
#include "example.h"

View file

@ -1,52 +1,52 @@
#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++;
}
};
#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++;
}
};

View file

@ -1,8 +1,8 @@
%module example
%{
#include "example.h"
%}
%include "example.h"
%module example
%{
#include "example.h"
%}
%include "example.h"

View file

@ -0,0 +1,36 @@
#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;
}

4
Examples/c/check.list Normal file
View file

@ -0,0 +1,4 @@
# see top-level Makefile.in
class
reference
simple

View file

@ -1,14 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
MAIN = test.c
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c_cpp
clean:
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
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* *~

View file

@ -1,28 +1,28 @@
/* File : example.c */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}
/* File : example.c */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}

View file

@ -1,39 +1,39 @@
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -1,10 +1,10 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

43
Examples/c/class/runme.c Normal file
View file

@ -0,0 +1,43 @@
#include <stdio.h>
#include "example_proxy.h"
int main(int argc, char **argv) {
printf("Creating some objects:\n");
Circle* c = new_Circle(10);
printf(" Created circle\n");
Square* s = new_Square(10);
printf(" Created square\n");
printf("\nA total of %d shapes were created\n", Shape_nshapes_get());
Circle_x_set(c, 20);
Circle_y_set(c, 30);
Shape* shape = (Shape*) s;
Shape_x_set(shape, -10);
Shape_y_set(shape, 5);
printf("\nHere is their current positions:\n");
printf(" Circle = (%f %f)\n", Circle_x_get(c), Circle_y_get(c));
printf(" Square = (%f %f)\n", Square_x_get(s), Square_y_get(s));
printf("\nHere are some properties of the shapes:\n");
Shape* shapes[] = {(Shape*) c, (Shape*) s};
int i;
for (i = 0; i < 2; i++) {
printf(" %s\n", i ? "Square" : "Circle");
printf(" area = %f\n", Shape_area(shapes[i]));
printf(" perimeter = %f\n", Shape_perimeter(shapes[i]));
}
printf("\nGuess I'll clean up now\n");
delete_Square(s);
delete_Circle(c);
printf("%d shapes remain\n", Shape_nshapes_get());
printf("Goodbye\n");
return 0;
}

View file

@ -1,14 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
MAIN = test.c
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c_cpp
clean:
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
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* *~

View file

@ -1,19 +1,19 @@
#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());
}
#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());
}

View file

@ -1,16 +1,16 @@
#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);
#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);

View file

@ -1,8 +1,8 @@
%module example
%{
#include "example.h"
%}
%include "example.h"
%module example
%{
#include "example.h"
%}
%include "example.h"

View file

@ -0,0 +1,21 @@
#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;
}

View file

@ -1,14 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
MAIN = test.c
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c_cpp
clean:
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
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* *~

View file

@ -1,10 +1,10 @@
#include "example.h"
Bar foo_ret_val() {
return Bar();
}
Bar* foo_ret_ptr(Bar* bar) {
return bar;
}
#include "example.h"
Bar foo_ret_val() {
return Bar();
}
Bar* foo_ret_ptr(Bar* bar) {
return bar;
}

View file

@ -1,16 +1,16 @@
#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);
#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);

View file

@ -1,8 +1,8 @@
%module example
%{
#include "example.h"
%}
%include "example.h"
%module example
%{
#include "example.h"
%}
%include "example.h"

11
Examples/c/return/runme.c Normal file
View file

@ -0,0 +1,11 @@
#include <stdio.h>
#include "example_proxy.h"
int main(int argc, char** argv) {
Bar b = foo_ret_val();
//Bar * bp = foo_ret_ptr(NULL);
printf("x = %d\n", Bar_get(&b));
return 0;
}

View file

@ -1,14 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
SRCS = example.c
TARGET = example
INTERFACE = example.i
MAIN = test.c
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MAIN='$(MAIN)' c
clean:
rm -f *.o *.so *.out *.a *.exe *.dll *_wrap* *_proxy* *~
TOP = ../..
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
SRCS = example.c
TARGET = example
INTERFACE = example.i
RUNME = runme.c
PROXY = example_proxy.c
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c
run:
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
TARGET='$(TARGET)' c_compile
env LD_LIBRARY_PATH=. ./runme
clean:
rm -f *.o *.so *.out *.a *.exe *.dll *_wrap* *_proxy* *~

View file

@ -1,24 +1,24 @@
/* 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];
}
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
/* 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];
}
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}

View file

@ -1,12 +1,12 @@
/* File : example.i */
%module example
%inline %{
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);
%}
/* File : example.i */
%module example
%inline %{
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);
%}

15
Examples/c/simple/runme.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdio.h>
#include "example_proxy.h"
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;
}