add missing files from initial check in

change camel case to match SWIG conventions


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9182 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2006-06-30 05:48:54 +00:00
commit dc15f0a6f8
7 changed files with 328 additions and 5 deletions

View file

@ -11,7 +11,7 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
C_TEST_CASES = copyStruct simpleArray legacy
C_TEST_CASES = copy_struct simple_array legacy
CPP_TEST_CASES = funcptr double_delete
include $(srcdir)/../common.mk

View file

@ -0,0 +1,131 @@
%module copy_struct
%insert("snamespace") %{ # Just checking %}
struct A {
int i;
unsigned int ui;
double d;
char* str;
int **tmp;
};
struct A getA();
struct A* getARef();
typedef struct {
int invisible;
} B;
struct C {
int invisible;
double blind;
};
typedef B C;
B* getBRef();
struct C* getCRef();
C* getCCRef();
%feature("opaque", "yes") B;
%feature("opaque", "yes") C;
typedef struct
{
int x;
double u;
} D;
%inline %{
struct A {
int i;
unsigned int ui;
double d;
char* str;
int **tmp;
};
struct A getA();
struct A* getARef();
typedef struct {
int invisible;
} B;
struct C {
int invisible;
double blind;
};
typedef B C;
B* getBRef();
struct C* getCRef();
C* getCCRef();
typedef struct
{
int x;
double u;
} D;
struct A
getA()
{
struct A a;
a.i = 10;
a.d = 3.1415;
return a;
}
static struct A fixed = {20, 3.010101, 42};
struct A *
getARef()
{
return(&fixed);
}
static B bb = {101};
B*
getBRef()
{
return(&bb);
}
struct C cc = {201, 3.14159};
struct C *
getCRef()
{
return(&cc);
}
C*
getCCRef()
{
return(&bb);
}
D
bar()
{ D a;
a.x = 1;
a.u = 0;
return(a);
}
%}

View file

@ -1,6 +1,6 @@
source('unittest.R')
dyn.load('copyStruct_wrap.so')
source('copyStruct_wrap.R')
dyn.load('copy_struct_wrap.so')
source('copy_struct_wrap.R')
cacheMetaData(1)
a <- getA()

View file

@ -0,0 +1,48 @@
%module funcptr
/*
Works if we use the typedef or the inline function pointer.
int (*op)(int i,int j));
*/
/*
typedef struct B (*Bar)(int i, struct C a);
typedef struct A *(*Foo)(int i, struct B a);
*/
/*
Complicated one that should defeat just reading , to find
the number of arguments expected in the function pointer.
extern void do(int (*op)(int (*i)(double, double), int j));
*/
%inline %{
typedef double (*DistFun)(double* data, int r, int c, int i, int j,
void *xdata);
void distance(double *data, int *dim, DistFun fun, double *output) {
}
typedef int (*Operator)(int i,int j);
int do_op(int a, int b, int (*op)(int,int)) {
return (*op)(a,b);
}
int add(int a, int b) {
return a+b;
}
int sub(int a, int b) {
return a-b;
}
int mul(int a, int b) {
return a*b;
}
int (*funcvar)(int,int) = add;
%}

View file

@ -0,0 +1,95 @@
%module legacy
%inline %{
typedef char *String;
typedef struct {
int i;
double d;
char *str;
String s;
} Obj;
Obj *getObject(int i, double d);
#include <string.h>
Obj *
getObject(int i, double d)
{
Obj *obj;
obj = (Obj *) calloc(1, sizeof(Obj));
obj->i = i;
obj->d = d;
obj->str = strdup("a test string");
return(obj);
}
%}
char *getString();
int getInt();
double getDouble();
float getFloat();
long getLong();
unsigned long getUnsignedLong();
char getChar();
extern unsigned long MyULong;
extern const double PiSquared;
#if 0
extern float *MyFloatRef;
#endif
%inline %{
#define PI 3.14159265358979
unsigned long MyULong = 20;
static float MyFloat = 1.05;
float *MyFloatRef = &MyFloat;
const double PiSquared = PI * PI;
char *getString()
{
return "This is a literal string";
}
int
getInt()
{
return 42;
}
double
getDouble()
{
return PI;
}
float
getFloat()
{
return PI/2;
}
long getLong()
{
return -321313L;
}
unsigned long
getUnsignedLong()
{
return 23123L;
}
char
getChar()
{
return('A');
}
%}

View file

@ -0,0 +1,49 @@
%module simple_array
extern int x[10];
extern double y[7];
struct BarArray {
int i;
double d;
};
extern struct BarArray bars[2];
void initArray();
%inline %{
struct BarArray {
int i;
double d;
};
int x[10];
double y[7];
struct BarArray bars[2];
void
initArray()
{
int i, n;
n = sizeof(x)/sizeof(x[0]);
for(i = 0; i < n; i++)
x[i] = i;
n = sizeof(y)/sizeof(y[0]);
for(i = 0; i < n; i++)
y[i] = ((double) i)/ ((double) n);
n = sizeof(bars)/sizeof(bars[0]);
for(i = 0; i < n; i++) {
bars[i].i = x[i+2];
bars[i].d = y[i+2];
}
return;
}
%}

View file

@ -1,6 +1,6 @@
source('unittest.R')
dyn.load('simpleArray_wrap.so')
source('simpleArray_wrap.R')
dyn.load('simple_array_wrap.so')
source('simple_array_wrap.R')
cacheMetaData(1)
initArray()