diff --git a/SWIG/Examples/test-suite/r/Makefile.in b/SWIG/Examples/test-suite/r/Makefile.in index 142bc25a2..955387b23 100644 --- a/SWIG/Examples/test-suite/r/Makefile.in +++ b/SWIG/Examples/test-suite/r/Makefile.in @@ -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 diff --git a/SWIG/Examples/test-suite/r/copy_struct.i b/SWIG/Examples/test-suite/r/copy_struct.i new file mode 100644 index 000000000..cab5aeb6e --- /dev/null +++ b/SWIG/Examples/test-suite/r/copy_struct.i @@ -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); +} + +%} + + + diff --git a/SWIG/Examples/test-suite/r/copyStruct_runme.R b/SWIG/Examples/test-suite/r/copy_struct_runme.R similarity index 91% rename from SWIG/Examples/test-suite/r/copyStruct_runme.R rename to SWIG/Examples/test-suite/r/copy_struct_runme.R index 8c9b2c52f..d29ae10c8 100644 --- a/SWIG/Examples/test-suite/r/copyStruct_runme.R +++ b/SWIG/Examples/test-suite/r/copy_struct_runme.R @@ -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() diff --git a/SWIG/Examples/test-suite/r/funcptr.i b/SWIG/Examples/test-suite/r/funcptr.i new file mode 100644 index 000000000..1797d979d --- /dev/null +++ b/SWIG/Examples/test-suite/r/funcptr.i @@ -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; +%} \ No newline at end of file diff --git a/SWIG/Examples/test-suite/r/legacy.i b/SWIG/Examples/test-suite/r/legacy.i new file mode 100644 index 000000000..0c82fcbe2 --- /dev/null +++ b/SWIG/Examples/test-suite/r/legacy.i @@ -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 + +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'); +} +%} diff --git a/SWIG/Examples/test-suite/r/simple_array.i b/SWIG/Examples/test-suite/r/simple_array.i new file mode 100644 index 000000000..9419b5447 --- /dev/null +++ b/SWIG/Examples/test-suite/r/simple_array.i @@ -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; +} + +%} \ No newline at end of file diff --git a/SWIG/Examples/test-suite/r/simpleArray_runme.R b/SWIG/Examples/test-suite/r/simple_array_runme.R similarity index 51% rename from SWIG/Examples/test-suite/r/simpleArray_runme.R rename to SWIG/Examples/test-suite/r/simple_array_runme.R index 025f8f04d..c7885f69f 100644 --- a/SWIG/Examples/test-suite/r/simpleArray_runme.R +++ b/SWIG/Examples/test-suite/r/simple_array_runme.R @@ -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()