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:
parent
f585c69d02
commit
a13c5976b5
35 changed files with 925 additions and 639 deletions
|
|
@ -1103,10 +1103,12 @@ c: $(SRCS)
|
|||
$(SWIG) -c $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES)
|
||||
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
|
||||
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(TARGET)
|
||||
|
||||
c_cpp: $(SRCS)
|
||||
$(SWIG) -c++ -c $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
|
||||
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
|
||||
$(CC) $(MAIN) $(TARGET)_proxy.c -L. -l$(TARGET)
|
||||
|
||||
c_compile: $(RUNME) $(PROXY)
|
||||
$(CC) $(RUNME) $(PROXY) -L. -l$(TARGET) -o $(RUNME:.c=)
|
||||
|
||||
|
|
|
|||
|
|
@ -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* *~
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
#include "example.h"
|
||||
|
||||
#include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
36
Examples/c/arguments/runme.c
Normal file
36
Examples/c/arguments/runme.c
Normal 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
4
Examples/c/check.list
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
reference
|
||||
simple
|
||||
|
|
@ -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* *~
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
43
Examples/c/class/runme.c
Normal 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;
|
||||
}
|
||||
|
||||
|
|
@ -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* *~
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
21
Examples/c/reference/runme.c
Normal file
21
Examples/c/reference/runme.c
Normal 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;
|
||||
}
|
||||
|
||||
|
|
@ -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* *~
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
11
Examples/c/return/runme.c
Normal 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;
|
||||
}
|
||||
|
||||
|
|
@ -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* *~
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
15
Examples/c/simple/runme.c
Normal 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;
|
||||
}
|
||||
|
||||
62
Examples/test-suite/c/Makefile.in
Normal file
62
Examples/test-suite/c/Makefile.in
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#######################################################################
|
||||
# Makefile for C test-suite
|
||||
#######################################################################
|
||||
|
||||
LANGUAGE = c
|
||||
C = gcc
|
||||
CXX = g++
|
||||
SCRIPTSUFFIX = _runme.c
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@/..
|
||||
top_builddir = @top_builddir@/..
|
||||
|
||||
C_TEST_CASES =
|
||||
|
||||
CPP_TEST_CASES = \
|
||||
c_arguments
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
$(setup)
|
||||
+(cd $* && $(swig_and_compile_cpp))
|
||||
$(run_testcase)
|
||||
|
||||
%.ctest:
|
||||
$(setup)
|
||||
+(cd $* && $(swig_and_compile_c))
|
||||
$(run_testcase)
|
||||
|
||||
%.multicpptest:
|
||||
$(setup)
|
||||
+(cd $* && $(swig_and_compile_multi_cpp))
|
||||
$(run_testcase)
|
||||
|
||||
# Makes a directory for the testcase if it does not exist
|
||||
setup = \
|
||||
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
|
||||
echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
|
||||
else \
|
||||
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
|
||||
fi; \
|
||||
if [ ! -d $* ]; then \
|
||||
mkdir $*; \
|
||||
fi;
|
||||
|
||||
# Compiles C files then runs the testcase. A testcase is only run if
|
||||
# a file is found which has _runme.c appended after the testcase name.
|
||||
run_testcase = \
|
||||
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then (\
|
||||
cd $* && $(COMPILETOOL) $(CC) ../$*_runme.c $*_proxy.c -L. -l$* -o $*_runme && \
|
||||
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_LIBRARY_PATH="$*:$$DYLD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme;) \
|
||||
fi;
|
||||
|
||||
# Clean: remove testcase directories
|
||||
%.clean:
|
||||
@if [ -d $* ]; then \
|
||||
rm -rf $*; \
|
||||
fi;
|
||||
|
||||
clean:
|
||||
@rm -f *_wrap.* *_proxy.* *~ *.exe *.dll *.so *.out *runme
|
||||
17
Examples/test-suite/c/c_arguments_runme.c
Normal file
17
Examples/test-suite/c/c_arguments_runme.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "c_arguments/c_arguments_proxy.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
A* a = new_A();
|
||||
if (A_foo(a, 0) != 1)
|
||||
fprintf(stderr, "call to A_foo() failed\n");
|
||||
delete_A(a);
|
||||
|
||||
int ***array = (int ***) 0;
|
||||
|
||||
foo_1(array);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
20
Examples/test-suite/c_arguments.i
Normal file
20
Examples/test-suite/c_arguments.i
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
%module c_arguments
|
||||
|
||||
%inline %{
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() {}
|
||||
int foo(int i) {
|
||||
return i+1;
|
||||
}
|
||||
};
|
||||
|
||||
void foo(A a, A &ra, A *pa, char c, char *str, char **pstr, char ***ppstri) {
|
||||
}
|
||||
|
||||
void foo_1(int ***a) {
|
||||
|
||||
}
|
||||
|
||||
%}
|
||||
165
Lib/c/c.swg
165
Lib/c/c.swg
|
|
@ -1,80 +1,85 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* c.swg
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%insert("runtime") "clabels.swg"
|
||||
%insert("shadow_header") "cproxy.swg"
|
||||
|
||||
// typemaps for function parameters
|
||||
|
||||
%typemap(ctype) void, short, int, long, char, float, double "$1_type"
|
||||
%typemap(ctype) void*, short*, int*, long*, char*, float*, double* "$1_type"
|
||||
%typemap(ctype) short&, int&, long&, char&, float&, double& "$1_basetype *"
|
||||
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_basetype"
|
||||
%typemap(ctype) bool "_Bool"
|
||||
%typemap(ctype) SWIGTYPE "$1_type"
|
||||
%typemap(ctype) SWIGTYPE * "$1_type"
|
||||
%typemap(ctype) SWIGTYPE & "$1_type"
|
||||
%typemap(ctype) SWIGTYPE * [ANY] "$1_basetype*"
|
||||
%typemap(ctype) SWIGCLASSTYPE "struct Obj$1_type *"
|
||||
%typemap(ctype) SWIGCLASSTYPE * "struct Obj$1_type"
|
||||
%typemap(ctype) SWIGCLASSTYPE & "struct Obj$*1_ltype *"
|
||||
%typemap(ctype) SWIGCLASSTYPE * [ANY] "struct Obj$1_basetype*"
|
||||
|
||||
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_basetype) $input;"
|
||||
%typemap(in) void*, short*, int*, long*, char*, float*, double*, bool* "$1 = ($1_basetype *) $input;"
|
||||
%typemap(in) short&, int&, long&, char&, float&, double&, bool& "$1 = ($1_basetype *) $input;"
|
||||
%typemap(in) SWIGTYPE "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE * "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE & "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE * [ANY] "$1 = ($1_basetype*) $input;"
|
||||
%typemap(in) SWIGCLASSTYPE {
|
||||
$1 = * ($1_type *) ($input->obj);
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE * {
|
||||
$1 = ($1_type) $input->obj;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE * [ANY] {
|
||||
$1 = ($1_basetype*) malloc($1_dim0 * sizeof($1_basetype));
|
||||
int i;
|
||||
for (i = 0; i < $1_dim0; ++i)
|
||||
if ($input[i])
|
||||
$1[i] = ($1_basetype) $input[i]->obj;
|
||||
else
|
||||
$1[i] = ($1_basetype) 0;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE & {
|
||||
$1 = ($*1_ltype *) $input->obj;
|
||||
}
|
||||
|
||||
// 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) bool "_Bool"
|
||||
%typemap(couttype) SWIGTYPE "struct Obj$1_type"
|
||||
%typemap(couttype) SWIGTYPE * "struct Obj$*1_type *"
|
||||
|
||||
%typemap(out) short, int, long, char, float, double, bool "$result = $1;"
|
||||
%typemap(out) void*, short*, int*, long*, char*, float*, double*, bool* "$result = $1;"
|
||||
%typemap(out) void ""
|
||||
|
||||
%typemap(out) SWIGTYPE {
|
||||
$result.obj = (void*) &$1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE * {
|
||||
$result->obj = (void*) $1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE & {
|
||||
// return by reference
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* c.swg
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%insert("runtime") "clabels.swg"
|
||||
%insert("proxy_header") "cproxy.swg"
|
||||
|
||||
// typemaps for function parameters
|
||||
|
||||
%typemap(ctype) void, short, int, long, char, float, double "$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) unsigned short*, unsigned int*, unsigned long*, unsigned char* "$1_type"
|
||||
%typemap(ctype) short&, int&, long&, char&, float&, double& "$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_basetype"
|
||||
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_basetype"
|
||||
%typemap(ctype) bool "_Bool"
|
||||
%typemap(ctype) SWIGTYPE "$1_type"
|
||||
%typemap(ctype) SWIGTYPE * "$1_type"
|
||||
%typemap(ctype) SWIGTYPE & "$1_type"
|
||||
%typemap(ctype) SWIGTYPE * [ANY] "$1_basetype*"
|
||||
%typemap(ctype) SWIGCLASSTYPE "struct SwigObj$1_type *"
|
||||
%typemap(ctype) SWIGCLASSTYPE * "struct SwigObj$1_type"
|
||||
%typemap(ctype) SWIGCLASSTYPE & "struct SwigObj$*1_ltype *"
|
||||
%typemap(ctype) SWIGCLASSTYPE * [ANY] "struct SwigObj$1_basetype *"
|
||||
|
||||
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_basetype) $input;"
|
||||
%typemap(in) void*, short*, int*, long*, char*, float*, double*, bool* "$1 = ($1_basetype *) $input;"
|
||||
%typemap(in) short&, int&, long&, char&, float&, double&, bool& "$1 = ($1_basetype *) $input;"
|
||||
|
||||
%typemap(in) SWIGTYPE "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE * "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE & "$1 = ($1_type) $input;"
|
||||
%typemap(in) SWIGTYPE * [ANY] "$1 = ($1_basetype*) $input;"
|
||||
%typemap(in) SWIGCLASSTYPE {
|
||||
$1 = * ($1_type *) ($input->obj);
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE * {
|
||||
$1 = ($1_type) $input->obj;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE * [ANY] {
|
||||
$1 = ($1_basetype*) malloc($1_dim0 * sizeof($1_basetype));
|
||||
int i;
|
||||
for (i = 0; i < $1_dim0; ++i)
|
||||
if ($input[i])
|
||||
$1[i] = ($1_basetype) $input[i]->obj;
|
||||
else
|
||||
$1[i] = ($1_basetype) 0;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGCLASSTYPE & {
|
||||
$1 = ($*1_ltype *) $input->obj;
|
||||
}
|
||||
|
||||
// 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) bool "_Bool"
|
||||
%typemap(couttype) SWIGTYPE "struct SwigObj$1_type"
|
||||
%typemap(couttype) SWIGTYPE * "struct SwigObj$*1_type *"
|
||||
|
||||
%typemap(out) short, int, long, char, float, double, bool "$result = $1;"
|
||||
%typemap(out) void*, short*, int*, long*, char*, float*, double*, bool* "$result = $1;"
|
||||
%typemap(out) void ""
|
||||
|
||||
%typemap(out) SWIGTYPE {
|
||||
$result.obj = (void*) &$1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE * {
|
||||
$result->obj = (void*) $1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE & {
|
||||
// return by reference
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,32 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* clabels.swg
|
||||
*
|
||||
* Definitions of C specific preprocessor symbols.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
// this is used instead of default SWIGEXPORT symbol
|
||||
|
||||
#ifndef SWIGEXPORTC
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# define SWIGEXPORTC
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
# define SWIGEXPORTC __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define SWIGEXPORTC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SWIGPROTECT
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# define SWIGPROTECT(x)
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
# define SWIGPROTECT(x) __attribute__ ((visibility("protected"))) x
|
||||
# else
|
||||
# define SWIGPROTECT(x)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* clabels.swg
|
||||
*
|
||||
* Definitions of C specific preprocessor symbols.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
// this is used instead of default SWIGEXPORT symbol
|
||||
|
||||
#ifndef SWIGEXPORTC
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# define SWIGEXPORTC
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
# define SWIGEXPORTC __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define SWIGEXPORTC
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SWIGPROTECT
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# define SWIGPROTECT(x)
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
# define SWIGPROTECT(x) __attribute__ ((visibility("protected"))) x
|
||||
# else
|
||||
# define SWIGPROTECT(x)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cproxy.swg
|
||||
*
|
||||
* Definitions of C specific preprocessor symbols for proxies.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SWIGIMPORT
|
||||
# ifndef __GNUC__
|
||||
# define __DLL_IMPORT __declspec(dllimport)
|
||||
# else
|
||||
# define __DLL_IMPORT __attribute__((dllimport)) extern
|
||||
# endif
|
||||
# if !defined (__WIN32__)
|
||||
# define SWIGIMPORT extern
|
||||
# else
|
||||
# define SWIGIMPORT __DLL_IMPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* cproxy.swg
|
||||
*
|
||||
* Definitions of C specific preprocessor symbols for proxies.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SWIGIMPORT
|
||||
# ifndef __GNUC__
|
||||
# define __DLL_IMPORT __declspec(dllimport)
|
||||
# else
|
||||
# define __DLL_IMPORT __attribute__((dllimport)) extern
|
||||
# endif
|
||||
# if !defined (__WIN32__)
|
||||
# define SWIGIMPORT extern
|
||||
# else
|
||||
# define SWIGIMPORT __DLL_IMPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
23
Makefile.in
23
Makefile.in
|
|
@ -57,6 +57,7 @@ skip-clisp = test -n "@SKIP_CLISP@"
|
|||
skip-cffi = test -n "@SKIP_CFFI@"
|
||||
skip-uffi = test -n "@SKIP_UFFI@"
|
||||
skip-r = test -n "@SKIP_R@"
|
||||
skip-c = test -n "@SKIP_C@"
|
||||
|
||||
# Additional dependencies for some tests
|
||||
skip-gcj = test -n "@SKIP_GCJ@"
|
||||
|
|
@ -91,6 +92,7 @@ check-aliveness:
|
|||
@$(skip-modula3) || ./$(TARGET) -modula3 -help
|
||||
@$(skip-lua) || ./$(TARGET) -lua -help
|
||||
@$(skip-r) || ./$(TARGET) -r -help
|
||||
@$(skip-c) || ./$(TARGET) -c -help
|
||||
|
||||
# Checks examples for compilation (does not run them)
|
||||
check-examples: \
|
||||
|
|
@ -113,7 +115,8 @@ check-examples: \
|
|||
check-clisp-examples \
|
||||
check-uffi-examples \
|
||||
check-cffi-examples \
|
||||
check-r-examples
|
||||
check-r-examples \
|
||||
check-c-examples
|
||||
|
||||
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
|
||||
perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
|
||||
|
|
@ -135,6 +138,7 @@ clisp_examples :=
|
|||
uffi_examples :=
|
||||
cffi_examples :=
|
||||
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
|
||||
c_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/c/check.list)
|
||||
|
||||
# all examples
|
||||
check-%-examples :
|
||||
|
|
@ -181,7 +185,8 @@ check-gifplot: \
|
|||
check-chicken-gifplot \
|
||||
# check-lua-gifplot \
|
||||
# check-csharp-gifplot \
|
||||
# check-modula3-gifplot
|
||||
# check-modula3-gifplot \
|
||||
# check-c-gifplot
|
||||
|
||||
check-%-gifplot: gifplot-library
|
||||
@if test -z "$(skip-$*)"; then \
|
||||
|
|
@ -228,7 +233,8 @@ check-test-suite: \
|
|||
check-uffi-test-suite \
|
||||
check-cffi-test-suite \
|
||||
check-chicken-test-suite \
|
||||
check-r-test-suite
|
||||
check-r-test-suite \
|
||||
check-c-test-suite
|
||||
|
||||
check-%-test-suite:
|
||||
@if test -z "$(skip-$*)"; then \
|
||||
|
|
@ -279,7 +285,8 @@ all-test-suite: \
|
|||
all-uffi-test-suite \
|
||||
all-cffi-test-suite \
|
||||
all-chicken-test-suite \
|
||||
all-r-test-suite
|
||||
all-r-test-suite \
|
||||
all-c-test-suite
|
||||
|
||||
all-%-test-suite:
|
||||
@$(MAKE) -k -s check-$*-test-suite ACTION=all
|
||||
|
|
@ -306,7 +313,8 @@ broken-test-suite: \
|
|||
broken-uffi-test-suite \
|
||||
broken-cffi-test-suite \
|
||||
broken-chicken-test-suite \
|
||||
broken-r-test-suite
|
||||
broken-r-test-suite \
|
||||
broken-c-test-suite
|
||||
|
||||
broken-%-test-suite:
|
||||
@$(MAKE) -k -s check-$*-test-suite ACTION=broken
|
||||
|
|
@ -391,7 +399,8 @@ noskip-test-suite: \
|
|||
noskip-uffi-test-suite \
|
||||
noskip-cffi-test-suite \
|
||||
noskip-chicken-test-suite \
|
||||
noskip-r-test-suite
|
||||
noskip-r-test-suite \
|
||||
noskip-c-test-suite
|
||||
|
||||
noskip-%-test-suite:
|
||||
dir="Examples/test-suite/$*"; \
|
||||
|
|
@ -440,7 +449,7 @@ install-main:
|
|||
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
|
||||
|
||||
lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php4 ocaml octave \
|
||||
pike chicken csharp modula3 allegrocl clisp lua cffi uffi r
|
||||
pike chicken csharp modula3 allegrocl clisp lua cffi uffi r c
|
||||
|
||||
lib-modules = std
|
||||
|
||||
|
|
|
|||
|
|
@ -18,16 +18,16 @@ class C:public Language {
|
|||
File *f_header;
|
||||
File *f_wrappers;
|
||||
File *f_init;
|
||||
File *f_shadow_c;
|
||||
File *f_shadow_h;
|
||||
File *f_proxy_c;
|
||||
File *f_proxy_h;
|
||||
|
||||
String *f_shadow_code_init;
|
||||
String *f_shadow_code_body;
|
||||
String *f_shadow_header;
|
||||
String *f_proxy_code_init;
|
||||
String *f_proxy_code_body;
|
||||
String *f_proxy_header;
|
||||
|
||||
String *empty_string;
|
||||
|
||||
bool shadow_flag;
|
||||
bool proxy_flag;
|
||||
bool runtime_flag;
|
||||
|
||||
public:
|
||||
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
C() :
|
||||
empty_string(NewString("")),
|
||||
shadow_flag(true),
|
||||
proxy_flag(true),
|
||||
runtime_flag(true) {
|
||||
}
|
||||
|
||||
|
|
@ -64,12 +64,15 @@ public:
|
|||
if (argv[i]) {
|
||||
if (strcmp(argv[i], "-help") == 0) {
|
||||
Printf(stdout, "%s\n", usage);
|
||||
} else if ((strcmp(argv[i], "-shadow") == 0) || (strcmp(argv[i], "-proxy") == 0)) {
|
||||
shadow_flag = true;
|
||||
} else if ((strcmp(argv[i], "-proxy") == 0) || (strcmp(argv[i], "-proxy") == 0)) {
|
||||
proxy_flag = true;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-noproxy") == 0) {
|
||||
shadow_flag = false;
|
||||
proxy_flag = false;
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-noruntime") == 0) {
|
||||
runtime_flag = false;
|
||||
Swig_mark_arg(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,12 +109,12 @@ public:
|
|||
Printf(f_header, "#include <stdlib.h>\n");
|
||||
Printf(f_header, "#include <string.h>\n");
|
||||
Printf(f_header, "#include <setjmp.h>\n\n");
|
||||
Printf(f_header, "static jmp_buf __rt_env;\n");
|
||||
Printf(f_header, "static int __rt_init = 0;\n\n");
|
||||
Printf(f_header, "void __runtime_init() {\n");
|
||||
Printf(f_header, " if (!__rt_init) {\n");
|
||||
Printf(f_header, " __rt_init = 1;\n");
|
||||
Printf(f_header, " if (setjmp(__rt_env)) {\n");
|
||||
Printf(f_header, "static jmp_buf Swig_rt_env;\n");
|
||||
Printf(f_header, "static int Swig_rt_init = 0;\n\n");
|
||||
Printf(f_header, "void Swig_runtime_init() {\n");
|
||||
Printf(f_header, " if (!Swig_rt_init) {\n");
|
||||
Printf(f_header, " Swig_rt_init = 1;\n");
|
||||
Printf(f_header, " if (setjmp(Swig_rt_env)) {\n");
|
||||
Printf(f_header, " fprintf(stderr, \"An error occured. Exitting...\\n\");\n");
|
||||
Printf(f_header, " exit(1);\n");
|
||||
Printf(f_header, " }\n");
|
||||
|
|
@ -119,32 +122,32 @@ public:
|
|||
Printf(f_header, "}\n\n");
|
||||
}
|
||||
|
||||
// generate shadow files if enabled
|
||||
if (shadow_flag) {
|
||||
f_shadow_code_init = NewString("");
|
||||
f_shadow_code_body = NewString("");
|
||||
f_shadow_header = NewString("");
|
||||
// generate proxy files if enabled
|
||||
if (proxy_flag) {
|
||||
f_proxy_code_init = NewString("");
|
||||
f_proxy_code_body = NewString("");
|
||||
f_proxy_header = NewString("");
|
||||
|
||||
// create shadow files with appropriate name
|
||||
String *shadow_code_filename = NewStringf("%s%s_proxy.c", SWIG_output_directory(), Char(module));
|
||||
if ((f_shadow_c = NewFile(shadow_code_filename, "w")) == 0) {
|
||||
FileErrorDisplay(shadow_code_filename);
|
||||
// create proxy files with appropriate name
|
||||
String *proxy_code_filename = NewStringf("%s%s_proxy.c", SWIG_output_directory(), Char(module));
|
||||
if ((f_proxy_c = NewFile(proxy_code_filename, "w")) == 0) {
|
||||
FileErrorDisplay(proxy_code_filename);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
String *shadow_header_filename = NewStringf("%s%s_proxy.h", SWIG_output_directory(), Char(module));
|
||||
if ((f_shadow_h = NewFile(shadow_header_filename, "w")) == 0) {
|
||||
FileErrorDisplay(shadow_header_filename);
|
||||
String *proxy_header_filename = NewStringf("%s%s_proxy.h", SWIG_output_directory(), Char(module));
|
||||
if ((f_proxy_h = NewFile(proxy_header_filename, "w")) == 0) {
|
||||
FileErrorDisplay(proxy_header_filename);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Swig_register_filebyname("shadow_code_init", f_shadow_code_init);
|
||||
Swig_register_filebyname("shadow_code_body", f_shadow_code_body);
|
||||
Swig_register_filebyname("shadow_header", f_shadow_header);
|
||||
Swig_register_filebyname("proxy_code_init", f_proxy_code_init);
|
||||
Swig_register_filebyname("proxy_code_body", f_proxy_code_body);
|
||||
Swig_register_filebyname("proxy_header", f_proxy_header);
|
||||
|
||||
Swig_banner(f_shadow_code_init);
|
||||
Swig_banner(f_shadow_header);
|
||||
Printf(f_shadow_code_init, "#include \"%s\"\n\n", shadow_header_filename);
|
||||
Swig_banner(f_proxy_code_init);
|
||||
Swig_banner(f_proxy_header);
|
||||
Printf(f_proxy_code_init, "#include \"%s\"\n\n", proxy_header_filename);
|
||||
}
|
||||
|
||||
Swig_register_filebyname("header", f_header);
|
||||
|
|
@ -163,15 +166,15 @@ public:
|
|||
Printf(f_wrappers, "}\n");
|
||||
Printf(f_wrappers, "#endif\n");
|
||||
|
||||
// finalize generating shadow file
|
||||
if (shadow_flag) {
|
||||
Printv(f_shadow_c, f_shadow_code_init, "\n", NIL);
|
||||
Printv(f_shadow_c, f_shadow_code_body, "\n", NIL);
|
||||
Printv(f_shadow_h, f_shadow_header, "\n", NIL);
|
||||
Close(f_shadow_c);
|
||||
Close(f_shadow_h);
|
||||
Delete(f_shadow_code_init);
|
||||
Delete(f_shadow_header);
|
||||
// finalize generating proxy file
|
||||
if (proxy_flag) {
|
||||
Printv(f_proxy_c, f_proxy_code_init, "\n", NIL);
|
||||
Printv(f_proxy_c, f_proxy_code_body, "\n", NIL);
|
||||
Printv(f_proxy_h, f_proxy_header, "\n", NIL);
|
||||
Close(f_proxy_c);
|
||||
Close(f_proxy_h);
|
||||
Delete(f_proxy_code_init);
|
||||
Delete(f_proxy_header);
|
||||
}
|
||||
|
||||
// write all to the file
|
||||
|
|
@ -198,8 +201,8 @@ public:
|
|||
String *type_str = SwigType_str(type, 0);
|
||||
//if (!CPlusPlus)
|
||||
// Printv(f_wrappers, "SWIGEXPORTC ", type_str, " ", Getattr(n, "name"), ";\n", NIL);
|
||||
if (shadow_flag) {
|
||||
Printv(f_shadow_header, "SWIGIMPORT ", type_str, " ", Getattr(n, "name"), ";\n", NIL);
|
||||
if (proxy_flag) {
|
||||
Printv(f_proxy_header, "SWIGIMPORT ", type_str, " ", Getattr(n, "name"), ";\n", NIL);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
|
@ -209,12 +212,12 @@ public:
|
|||
* ------------------------------------------------------------------------ */
|
||||
|
||||
virtual int globalfunctionHandler(Node *n ) {
|
||||
String* action = NewString("");
|
||||
String* vis_hint = NewString("");
|
||||
String* return_type_str = SwigType_str(Getattr(n, "type"), 0);
|
||||
String* name = Getattr(n, "sym:name");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
String* arg_list = NewString("");
|
||||
String *action = NewString("");
|
||||
String *vis_hint = NewString("");
|
||||
String *return_type_str = SwigType_str(Getattr(n, "type"), 0);
|
||||
String *name = Getattr(n, "sym:name");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
String *arg_list = NewString("");
|
||||
|
||||
if (SwigType_type(Getattr(n, "type")) != T_VOID) {
|
||||
Printv(action, "$cppresult = (", SwigType_str(Getattr(n, "type"), 0), ") ", NIL);
|
||||
|
|
@ -272,8 +275,8 @@ public:
|
|||
* incomplete for now...
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
const char* getTypeSymbol(String* type) {
|
||||
char* c = Char(type);
|
||||
const char *getTypeSymbol(String *type) {
|
||||
char *c = Char(type);
|
||||
if (strcmp(c, "int") == 0)
|
||||
return "i";
|
||||
if (strcmp(c, "double") == 0)
|
||||
|
|
@ -398,7 +401,7 @@ public:
|
|||
SwigType* type = Getattr(p, "type");
|
||||
String* lname = Getattr(p, "lname");
|
||||
String* c_parm_type = NewString("");
|
||||
String* shadow_parm_type = NewString("");
|
||||
String* proxy_parm_type = NewString("");
|
||||
String* arg_name = NewString("");
|
||||
|
||||
Printf(arg_name, "c%s", lname);
|
||||
|
|
@ -414,20 +417,20 @@ public:
|
|||
Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(type, 0));
|
||||
}
|
||||
|
||||
// use shadow-type for parameter if supplied
|
||||
// use proxy-type for parameter if supplied
|
||||
String* stype = Getattr(p, "c:stype");
|
||||
if (stype) {
|
||||
Printv(shadow_parm_type, SwigType_str(stype, 0), NIL);
|
||||
Printv(proxy_parm_type, SwigType_str(stype, 0), NIL);
|
||||
}
|
||||
else {
|
||||
Printv(shadow_parm_type, c_parm_type, NIL);
|
||||
Printv(proxy_parm_type, c_parm_type, NIL);
|
||||
}
|
||||
|
||||
Replaceall(c_parm_type, "::", "_");
|
||||
|
||||
Printv(arg_names, gencomma ? ", " : "", Getattr(p, "name"), NIL);
|
||||
Printv(wrapper->def, gencomma ? ", " : "", c_parm_type, " ", arg_name, NIL);
|
||||
Printv(proto, gencomma ? ", " : "", shadow_parm_type, " ", Getattr(p, "name"), NIL);
|
||||
Printv(proto, gencomma ? ", " : "", proxy_parm_type, " ", Getattr(p, "name"), NIL);
|
||||
gencomma = 1;
|
||||
|
||||
// apply typemaps for input parameter
|
||||
|
|
@ -448,7 +451,7 @@ public:
|
|||
p = nextSibling(p);
|
||||
}
|
||||
Delete(arg_name);
|
||||
Delete(shadow_parm_type);
|
||||
Delete(proxy_parm_type);
|
||||
Delete(c_parm_type);
|
||||
}
|
||||
|
||||
|
|
@ -483,23 +486,23 @@ public:
|
|||
Append(wrapper->code, "}\n");
|
||||
}
|
||||
|
||||
// take care of shadow function
|
||||
if (shadow_flag) {
|
||||
// use shadow-type for return type if supplied
|
||||
SwigType* shadow_type = Getattr(n, "c:stype");
|
||||
if (shadow_type) {
|
||||
return_type = SwigType_str(shadow_type, 0);
|
||||
// take care of proxy function
|
||||
if (proxy_flag) {
|
||||
// use proxy-type for return type if supplied
|
||||
SwigType *proxy_type = Getattr(n, "c:stype");
|
||||
if (proxy_type) {
|
||||
return_type = SwigType_str(proxy_type, 0);
|
||||
}
|
||||
|
||||
// emit proxy functions prototypes
|
||||
Printv(f_shadow_code_init, "extern ", return_type, " ", wname, "(", proto, ");\n", NIL);
|
||||
Printv(f_shadow_code_body, return_type, " ", name, "(", proto, ") {\n", NIL);
|
||||
Printv(f_proxy_code_init, "extern ", return_type, " ", wname, "(", proto, ");\n", NIL);
|
||||
Printv(f_proxy_code_body, return_type, " ", name, "(", proto, ") {\n", NIL);
|
||||
|
||||
// call to the wrapper function
|
||||
Printv(f_shadow_code_body, " return ", wname, "(", arg_names, ");\n}\n", NIL);
|
||||
Printv(f_proxy_code_body, " return ", wname, "(", arg_names, ");\n}\n", NIL);
|
||||
|
||||
// add function declaration to the proxy header file
|
||||
Printv(f_shadow_header, return_type, " ", name, "(", proto, ");\n");
|
||||
Printv(f_proxy_header, return_type, " ", name, "(", proto, ");\n");
|
||||
}
|
||||
|
||||
Wrapper_print(wrapper, f_wrappers);
|
||||
|
|
@ -518,25 +521,25 @@ public:
|
|||
* emit_runtime_typecheck()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
void emit_runtime_typecheck(String* classname, String* funcname, String* code) {
|
||||
void emit_runtime_typecheck(String *classname, String *funcname, String *code) {
|
||||
Printf(code, "{\nint i = 0, type_ok = 0;\n");
|
||||
Printf(code, "if (arg1 == NULL) {\n");
|
||||
Printv(code, " fprintf(stderr, \"error: NULL object-struct passed to ", funcname, "\\n\");\n");
|
||||
Printf(code, " longjmp(__rt_env, 0);\n}\n");
|
||||
Printf(code, " longjmp(Swig_rt_env, 0);\n}\n");
|
||||
Printf(code, "while(arg1->typenames[i]) {\n");
|
||||
Printv(code, " if (strcmp(arg1->typenames[i++], \"", classname, "\") == 0) {\n", NIL);
|
||||
Printf(code, " type_ok = 1;\nbreak;\n}\n}\n");
|
||||
Printf(code, "if (!type_ok) {\n");
|
||||
Printv(code, " fprintf(stderr, \"error: object-struct passed to ", funcname, " is not of class ", classname, "\\n\");\n", NIL);
|
||||
Printf(code, " longjmp(__rt_env, 0);\n}\n}\n");
|
||||
Printf(code, " longjmp(Swig_rt_env, 0);\n}\n}\n");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* copy_node()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
Node* copy_node(Node *node) {
|
||||
Node* new_node = NewHash();
|
||||
Node *copy_node(Node *node) {
|
||||
Node *new_node = NewHash();
|
||||
Setattr(new_node, "name", Copy(Getattr(node, "name")));
|
||||
Setattr(new_node, "ismember", Copy(Getattr(node, "ismember")));
|
||||
Setattr(new_node, "view", Copy(Getattr(node, "view")));
|
||||
|
|
@ -549,13 +552,13 @@ public:
|
|||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* copy_node()
|
||||
* is_in()
|
||||
*
|
||||
* tests if given name already exists in one of child nodes of n
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
bool is_in(String* name, Node* n) {
|
||||
Hash* h;
|
||||
bool is_in(String *name, Node *n) {
|
||||
Hash *h;
|
||||
for (h = firstChild(n); h; h = nextSibling(h)) {
|
||||
if (Cmp(name, Getattr(h, "name")) == 0)
|
||||
return true;
|
||||
|
|
@ -567,10 +570,10 @@ public:
|
|||
* classHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int classHandler(Node* n) {
|
||||
String* name = Copy(Getattr(n, "name"));
|
||||
String* sobj = NewString("");
|
||||
List* baselist = Getattr(n, "bases");
|
||||
virtual int classHandler(Node *n) {
|
||||
String *name = Copy(Getattr(n, "name"));
|
||||
String *sobj = NewString("");
|
||||
List *baselist = Getattr(n, "bases");
|
||||
Replaceall(name, "::", "_");
|
||||
|
||||
if (CPlusPlus) {
|
||||
|
|
@ -579,7 +582,7 @@ public:
|
|||
Iterator i;
|
||||
for (i = First(baselist); i.item; i = Next(i)) {
|
||||
// look for member variables and functions
|
||||
Node* node;
|
||||
Node *node;
|
||||
for (node = firstChild(i.item); node; node = nextSibling(node)) {
|
||||
if ((Cmp(Getattr(node, "kind"), "variable") == 0)
|
||||
|| (Cmp(Getattr(node, "kind"), "function") == 0)) {
|
||||
|
|
@ -605,18 +608,18 @@ public:
|
|||
}
|
||||
|
||||
// emit "class"-struct definition
|
||||
Printv(sobj, "struct Obj", name, " {\n void* obj;\n", NIL);
|
||||
Printv(sobj, "struct SwigObj", name, " {\n void* obj;\n", NIL);
|
||||
if (runtime_flag)
|
||||
Printf(sobj, " const char* typenames[%d];\n}", Len(baselist) + 2);
|
||||
else
|
||||
Printf(sobj, "};\n\n");
|
||||
|
||||
Printv(f_header, sobj, ";\n\n", NIL);
|
||||
Printv(f_header, "const char* __typename_", name, " = \"", name, "\";\n\n", NIL);
|
||||
Printv(f_header, "const char* Swig_typename_", name, " = \"", name, "\";\n\n", NIL);
|
||||
|
||||
// declare it in the proxy header
|
||||
if (shadow_flag)
|
||||
Printv(f_shadow_header, "typedef ", sobj, " ", name, ";\n\n", NIL);
|
||||
if (proxy_flag)
|
||||
Printv(f_proxy_header, "typedef ", sobj, " ", name, ";\n\n", NIL);
|
||||
|
||||
Delete(sobj);
|
||||
Delete(name);
|
||||
|
|
@ -624,19 +627,19 @@ public:
|
|||
}
|
||||
else if (Cmp(Getattr(n, "kind"), "struct") == 0) {
|
||||
// this is C struct, just declare it in proxy
|
||||
if (shadow_flag) {
|
||||
Printv(f_shadow_header, "struct ", name, " {\n", NIL);
|
||||
if (proxy_flag) {
|
||||
Printv(f_proxy_header, "struct ", name, " {\n", NIL);
|
||||
Node* node;
|
||||
for (node = firstChild(n); node; node = nextSibling(node)) {
|
||||
String* kind = Getattr(node, "kind");
|
||||
if ((Cmp(kind, "variable") == 0) || (Cmp(kind, "function") == 0)) {
|
||||
String* type = NewString("");
|
||||
Printv(type, Getattr(node, "decl"), Getattr(node, "type"), NIL);
|
||||
Printv(f_shadow_header, " ", SwigType_str(type, 0), " ", Getattr(node, "name"), ";\n", NIL);
|
||||
Printv(f_proxy_header, " ", SwigType_str(type, 0), " ", Getattr(node, "name"), ";\n", NIL);
|
||||
Delete(type);
|
||||
}
|
||||
}
|
||||
Append(f_shadow_header, "};\n\n");
|
||||
Append(f_proxy_header, "};\n\n");
|
||||
}
|
||||
|
||||
Delete(sobj);
|
||||
|
|
@ -649,14 +652,14 @@ public:
|
|||
* staticmemberfunctionHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmemberfunctionHandler(Node* n) {
|
||||
String* name = Getattr(n, "name");
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* new_name = NewString("");
|
||||
String* code = NewString("");
|
||||
String* arg_lnames = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
virtual int staticmemberfunctionHandler(Node *n) {
|
||||
String *name = Getattr(n, "name");
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *new_name = NewString("");
|
||||
String *code = NewString("");
|
||||
String *arg_lnames = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
|
||||
Replaceall(newclassname, "::", "_");
|
||||
|
||||
|
|
@ -687,25 +690,25 @@ public:
|
|||
* memberfunctionHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int memberfunctionHandler(Node* n) {
|
||||
String* name = Getattr(n, "name");
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* sobj_name = NewString("");
|
||||
String* ctype = NewString("");
|
||||
String* stype = NewString("");
|
||||
String* new_name = NewString("");
|
||||
String* code = NewString("");
|
||||
String* arg_lnames = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
virtual int memberfunctionHandler(Node *n) {
|
||||
String *name = Getattr(n, "name");
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *sobj_name = NewString("");
|
||||
String *ctype = NewString("");
|
||||
String *stype = NewString("");
|
||||
String *new_name = NewString("");
|
||||
String *code = NewString("");
|
||||
String *arg_lnames = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
|
||||
Replaceall(newclassname, "::", "_");
|
||||
|
||||
// create first argument
|
||||
Printv(sobj_name, "struct Obj", newclassname, NIL);
|
||||
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
|
||||
ctype = Copy(sobj_name);
|
||||
SwigType_add_pointer(ctype);
|
||||
Parm* p = NewParm(ctype, "self");
|
||||
Parm *p = NewParm(ctype, "self");
|
||||
stype = Copy(newclassname);
|
||||
SwigType_add_pointer(stype);
|
||||
Setattr(p, "c:stype", stype);
|
||||
|
|
@ -719,7 +722,7 @@ public:
|
|||
Append(arg_lnames, Swig_cfunction_call(empty_string, parms));
|
||||
|
||||
// omit first argument in method call
|
||||
String* arg_call_lnames = Strstr(arg_lnames, "*arg2");
|
||||
String *arg_call_lnames = Strstr(arg_lnames, "*arg2");
|
||||
if (!arg_call_lnames)
|
||||
arg_call_lnames = Strstr(arg_lnames, "arg2");
|
||||
if (!arg_call_lnames)
|
||||
|
|
@ -754,15 +757,15 @@ public:
|
|||
* wrap_get_variable()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
void wrap_get_variable(Node* n, String* classname, String* newclassname, String* name, String* code) {
|
||||
void wrap_get_variable(Node *n, String *classname, String *newclassname, String *name, String *code) {
|
||||
// modify method name
|
||||
String* new_name = NewString("");
|
||||
Printv(new_name, newclassname, "_get_", name, NIL);
|
||||
String *new_name = NewString("");
|
||||
Printv(new_name, newclassname, "_", Swig_name_get(name), NIL);
|
||||
Setattr(n, "sym:name", new_name);
|
||||
|
||||
// generate action code
|
||||
String* action = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
String *action = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
if (parms)
|
||||
if (runtime_flag && Getattr(parms, "c:objstruct"))
|
||||
emit_runtime_typecheck(newclassname, new_name, action);
|
||||
|
|
@ -785,15 +788,15 @@ public:
|
|||
* wrap_set_variable()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
void wrap_set_variable(Node* n, String* classname, String* newclassname, String* name, String* code) {
|
||||
void wrap_set_variable(Node *n, String *classname, String *newclassname, String *name, String *code) {
|
||||
// modify method name
|
||||
String* new_name = NewString("");
|
||||
Printv(new_name, newclassname, "_set_", name, NIL);
|
||||
String *new_name = NewString("");
|
||||
Printv(new_name, newclassname, "_", Swig_name_set(name), NIL);
|
||||
Setattr(n, "sym:name", new_name);
|
||||
|
||||
// generate action code
|
||||
String* action = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
String *action = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
if (parms)
|
||||
if (runtime_flag && Getattr(parms, "c:objstruct"))
|
||||
emit_runtime_typecheck(newclassname, new_name, action);
|
||||
|
|
@ -803,6 +806,7 @@ public:
|
|||
}
|
||||
Append(action, code);
|
||||
Setattr(n, "wrap:action", action);
|
||||
Setattr(n, "type", "void");
|
||||
|
||||
functionWrapper(n);
|
||||
|
||||
|
|
@ -815,13 +819,13 @@ public:
|
|||
* staticmembervariableHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int staticmembervariableHandler(Node* n) {
|
||||
String* name = Getattr(n, "sym:name");
|
||||
SwigType* type = Copy(Getattr(n, "type"));
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* new_name = NewString("");
|
||||
String* code = NewString("");
|
||||
virtual int staticmembervariableHandler(Node *n) {
|
||||
String *name = Getattr(n, "sym:name");
|
||||
SwigType *type = Copy(Getattr(n, "type"));
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *new_name = NewString("");
|
||||
String *code = NewString("");
|
||||
Replaceall(newclassname, "::", "_");
|
||||
|
||||
// create code for 'get' function
|
||||
|
|
@ -829,7 +833,7 @@ public:
|
|||
wrap_get_variable(n, classname, newclassname, name, code);
|
||||
|
||||
// create parameter for 'set' function
|
||||
Parm* p = NewParm(Getattr(n, "type"), "value");
|
||||
Parm *p = NewParm(Getattr(n, "type"), "value");
|
||||
Setattr(p, "lname", "arg1");
|
||||
Setattr(n, "parms", p);
|
||||
|
||||
|
|
@ -851,22 +855,22 @@ public:
|
|||
* membervariableHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int membervariableHandler(Node* n) {
|
||||
String* name = Getattr(n, "sym:name");
|
||||
SwigType* type = Copy(Getattr(n, "type"));
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* sobj_name = NewString("");
|
||||
String* ctype = NewString("");
|
||||
String* stype;
|
||||
String* new_name = NewString("");
|
||||
virtual int membervariableHandler(Node *n) {
|
||||
String *name = Getattr(n, "sym:name");
|
||||
SwigType *type = Copy(Getattr(n, "type"));
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *sobj_name = NewString("");
|
||||
String *ctype = NewString("");
|
||||
String *stype;
|
||||
String *new_name = NewString("");
|
||||
Replaceall(newclassname, "::", "_");
|
||||
|
||||
// create first argument
|
||||
Printv(sobj_name, "struct Obj", newclassname, NIL);
|
||||
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
|
||||
ctype = Copy(sobj_name);
|
||||
SwigType_add_pointer(ctype);
|
||||
Parm* p = NewParm(ctype, "self");
|
||||
Parm *p = NewParm(ctype, "self");
|
||||
stype = Copy(newclassname);
|
||||
SwigType_add_pointer(stype);
|
||||
Setattr(p, "c:stype", stype);
|
||||
|
|
@ -874,7 +878,7 @@ public:
|
|||
Setattr(p, "lname", "arg1");
|
||||
|
||||
// create second argument
|
||||
Parm* t = NewParm(Getattr(n, "type"), "value");
|
||||
Parm *t = NewParm(Getattr(n, "type"), "value");
|
||||
Setattr(t, "lname", "arg2");
|
||||
|
||||
// create 'get' function
|
||||
|
|
@ -902,38 +906,38 @@ public:
|
|||
* emit_runtime_make_object()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
void emit_runtime_make_object(Node* n, String* classname, String* code) {
|
||||
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");
|
||||
Printv(code, "result->typenames[0] = __typename_", classname, ";\n", NIL);
|
||||
List *baselist = Getattr(parentNode(n), "bases");
|
||||
Printv(code, "result->typenames[0] = Swig_typename_", classname, ";\n", NIL);
|
||||
int i = 1;
|
||||
if (baselist) {
|
||||
Iterator it;
|
||||
for (it = First(baselist); it.item; it = Next(it)) {
|
||||
Printf(code, "result->typenames[%d] = __typename_%s;\n", i++, Getattr(it.item, "name"));
|
||||
Printf(code, "result->typenames[%d] = Swig_typename_%s;\n", i++, Getattr(it.item, "name"));
|
||||
}
|
||||
}
|
||||
Printf(code, "result->typenames[%d] = 0;\n", i);
|
||||
Printf(code, "__runtime_init();\n");
|
||||
Printf(code, "Swig_runtime_init();\n");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
* constructorHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int constructorHandler(Node* n) {
|
||||
virtual int constructorHandler(Node *n) {
|
||||
if (Getattr(n, "copy_constructor"))
|
||||
return copyconstructorHandler(n);
|
||||
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* sobj_name = NewString("");
|
||||
String* ctype;
|
||||
String* stype;
|
||||
String* code = NewString("");
|
||||
String* constr_name = NewString("");
|
||||
String* arg_lnames = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *sobj_name = NewString("");
|
||||
String *ctype;
|
||||
String *stype;
|
||||
String *code = NewString("");
|
||||
String *constr_name = NewString("");
|
||||
String *arg_lnames = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
|
||||
Replaceall(newclassname, "::", "_");
|
||||
|
||||
|
|
@ -941,7 +945,7 @@ public:
|
|||
Append(arg_lnames, Swig_cfunction_call(empty_string, parms));
|
||||
|
||||
// set the function return type to the pointer to struct
|
||||
Printv(sobj_name, "struct Obj", newclassname, NIL);
|
||||
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
|
||||
ctype = Copy(sobj_name);
|
||||
SwigType_add_pointer(ctype);
|
||||
Setattr(n, "type", ctype);
|
||||
|
|
@ -980,20 +984,20 @@ public:
|
|||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int copyconstructorHandler(Node *n) {
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* sobj_name = NewString("");
|
||||
String* ctype;
|
||||
String* stype;
|
||||
String* code = NewString("");
|
||||
String* constr_name = NewString("");
|
||||
ParmList* parms = Getattr(n, "parms");
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *sobj_name = NewString("");
|
||||
String *ctype;
|
||||
String *stype;
|
||||
String *code = NewString("");
|
||||
String *constr_name = NewString("");
|
||||
ParmList *parms = Getattr(n, "parms");
|
||||
|
||||
Replaceall(newclassname, "::", "_");
|
||||
Setattr(parms, "lname", "arg1");
|
||||
|
||||
// set the function return type to the pointer to struct
|
||||
Printv(sobj_name, "struct Obj", newclassname, NIL);
|
||||
Printv(sobj_name, "struct SwigObj", newclassname, NIL);
|
||||
ctype = Copy(sobj_name);
|
||||
SwigType_add_pointer(ctype);
|
||||
Setattr(n, "type", ctype);
|
||||
|
|
@ -1030,21 +1034,21 @@ public:
|
|||
* destructorHandler()
|
||||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int destructorHandler(Node* n) {
|
||||
String* classname = Getattr(parentNode(n), "name");
|
||||
String* newclassname = Copy(classname);
|
||||
String* sobj_name = NewString("");
|
||||
String* ctype;
|
||||
String* stype;
|
||||
String* code = NewString("");
|
||||
String* destr_name = NewString("");
|
||||
Parm* p;
|
||||
virtual int destructorHandler(Node *n) {
|
||||
String *classname = Getattr(parentNode(n), "sym:name");
|
||||
String *newclassname = Copy(classname);
|
||||
String *sobj_name = NewString("");
|
||||
String *ctype;
|
||||
String *stype;
|
||||
String *code = NewString("");
|
||||
String *destr_name = NewString("");
|
||||
Parm *p;
|
||||
|
||||
Replaceall(newclassname, "::", "_");
|
||||
Replaceall(newclassname, "~", "");
|
||||
|
||||
// create first argument
|
||||
Printv(sobj_name, "struct Obj", newclassname, " ", NIL);
|
||||
Printv(sobj_name, "struct SwigObj", newclassname, " ", NIL);
|
||||
ctype = Copy(sobj_name);
|
||||
SwigType_add_pointer(ctype);
|
||||
p = NewParm(ctype, "self");
|
||||
|
|
|
|||
|
|
@ -1959,6 +1959,12 @@ SKIP_UFFI=
|
|||
#fi
|
||||
AC_SUBST(SKIP_UFFI)
|
||||
|
||||
SKIP_C=
|
||||
if test -x "$(CC)" || test -z "$(CXX)" ; then
|
||||
SKIP_C="1"
|
||||
fi
|
||||
AC_SUBST(SKIP_C)
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Additional language dependencies
|
||||
#----------------------------------------------------------------
|
||||
|
|
@ -2039,6 +2045,7 @@ AC_CONFIG_FILES([ \
|
|||
Examples/test-suite/cffi/Makefile \
|
||||
Examples/test-suite/uffi/Makefile \
|
||||
Examples/test-suite/r/Makefile \
|
||||
Examples/test-suite/c/Makefile \
|
||||
Lib/ocaml/swigp4.ml
|
||||
])
|
||||
AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue