added some pointer support and fixed style problem
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11415 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c6592a5b56
commit
93a0308e21
14 changed files with 368 additions and 244 deletions
|
|
@ -1153,6 +1153,12 @@ SCILAB = @SCILAB@
|
||||||
scilab: $(SRCS)
|
scilab: $(SRCS)
|
||||||
$(SWIG) -scilab $(SWIGOPT) $(INTERFACEPATH)
|
$(SWIG) -scilab $(SWIGOPT) $(INTERFACEPATH)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Running a Scilab example
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
scilab_run:
|
||||||
|
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -nwni < runme.sci
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Cleaning the scilab examples
|
# Cleaning the scilab examples
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
TOP = ../..
|
TOP = ../..
|
||||||
SWIG = $(TOP)/../preinst-swig
|
SWIG = $(TOP)/../preinst-swig
|
||||||
SRCS = example.c
|
SRCS = example.i
|
||||||
TARGET = example
|
TARGET = example
|
||||||
INTERFACE = example.i
|
INTERFACE = example.i
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,6 @@
|
||||||
/* File : example.i */
|
/* File : example.i */
|
||||||
%module example
|
%module example
|
||||||
|
FILE *fopen(char *filename, char *mode);
|
||||||
%{
|
int fputs(char* , FILE *);
|
||||||
extern void add(int *, int *, int *);
|
int fclose(FILE *);
|
||||||
extern void sub(int *, int *, int *);
|
|
||||||
extern int divide(int, int, int *);
|
|
||||||
%}
|
|
||||||
|
|
||||||
/* This example illustrates a couple of different techniques
|
|
||||||
for manipulating C pointers */
|
|
||||||
|
|
||||||
/* First we'll use the pointer library */
|
|
||||||
extern void add(int *x, int *y, int *result);
|
|
||||||
%include cpointer.i
|
|
||||||
%pointer_functions(int, intp);
|
|
||||||
|
|
||||||
/* Next we'll use some typemaps */
|
|
||||||
|
|
||||||
%include typemaps.i
|
|
||||||
extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
|
|
||||||
|
|
||||||
/* Next we'll use typemaps and the %apply directive */
|
|
||||||
|
|
||||||
%apply int *OUTPUT { int *r };
|
|
||||||
extern int divide(int n, int d, int *r);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
TOP = ../..
|
TOP = ../..
|
||||||
SWIG = $(TOP)/../preinst-swig
|
SWIG = $(TOP)/../preinst-swig
|
||||||
SRCS = example.c
|
SRCS = example.i
|
||||||
TARGET = example
|
TARGET = example
|
||||||
INTERFACE = example.i
|
INTERFACE = example.i
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,5 @@ try
|
||||||
catch
|
catch
|
||||||
printf("FOO is not defined (good)\n");
|
printf("FOO is not defined (good)\n");
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,7 @@ y=105;
|
||||||
g=gcd(x,y);
|
g=gcd(x,y);
|
||||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,5 @@ enum_test(color.BLUE);
|
||||||
enum_test(color.GREEN);
|
enum_test(color.GREEN);
|
||||||
enum_test(1234);
|
enum_test(1234);
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,5 @@ printf("Testing multiple return values\n");
|
||||||
[q,r] = divide(42,37);
|
[q,r] = divide(42,37);
|
||||||
printf(" 42/37 = %d remainder %d\n",q,r);
|
printf(" 42/37 = %d remainder %d\n",q,r);
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,5 @@ Foo_set(3.1415926)
|
||||||
// See if the change took effect
|
// See if the change took effect
|
||||||
Foo_get()
|
Foo_get()
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,12 @@ char cvar = 0;
|
||||||
float fvar = 0;
|
float fvar = 0;
|
||||||
double dvar = 0;
|
double dvar = 0;
|
||||||
char *strvar=0;
|
char *strvar=0;
|
||||||
|
char name[5] = "Dave";
|
||||||
double *Foo1;
|
double *Foo1;
|
||||||
double *Foo2;
|
double *Foo2;
|
||||||
|
int *pivar;
|
||||||
|
short *psvar;
|
||||||
|
char **foo;
|
||||||
|
|
||||||
|
|
||||||
/* A debugging function to print out their values */
|
/* A debugging function to print out their values */
|
||||||
|
|
@ -43,6 +46,7 @@ void print_vars() {
|
||||||
printf("dvar = %g\n", dvar);
|
printf("dvar = %g\n", dvar);
|
||||||
printf("cvar = %c\n", cvar);
|
printf("cvar = %c\n", cvar);
|
||||||
printf("strvar = %s\n",strvar);
|
printf("strvar = %s\n",strvar);
|
||||||
|
printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,12 @@
|
||||||
extern float fvar;
|
extern float fvar;
|
||||||
extern double dvar;
|
extern double dvar;
|
||||||
extern char *strvar;
|
extern char *strvar;
|
||||||
|
extern char name[256];
|
||||||
extern double *Foo1;
|
extern double *Foo1;
|
||||||
extern double *Foo2;
|
extern double *Foo2;
|
||||||
|
extern int *pivar;
|
||||||
|
extern short *psvar;
|
||||||
|
extern char **foo;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,16 @@ cvar_set ("S");
|
||||||
fvar_set (3.14159);
|
fvar_set (3.14159);
|
||||||
dvar_set (2.1828);
|
dvar_set (2.1828);
|
||||||
strvar_set("Hello World");
|
strvar_set("Hello World");
|
||||||
|
name_set ("Bill");
|
||||||
Foo1_set([1,2,3;4,5,6]);
|
Foo1_set([1,2,3;4,5,6]);
|
||||||
Foo2_set([1+2*%i,2+3*%i;3+4*%i,7+8*%i]);
|
Foo2_set([1+2*%i,2+3*%i;3+4*%i,7+8*%i]);
|
||||||
|
pivar_set(int32([ 1 2 3 4 5;
|
||||||
|
6 7 8 9 10;
|
||||||
|
11 12 13 14 15]));
|
||||||
|
psvar_set(int16([ 1 2 3 4 5;
|
||||||
|
6 7 8 9 10;
|
||||||
|
11 12 13 14 15]));
|
||||||
|
foo_set(["sample", "strings", "manipulation"; "with","gateway","API"]);
|
||||||
|
|
||||||
// Now print out the values of the variables
|
// Now print out the values of the variables
|
||||||
|
|
||||||
|
|
@ -37,10 +45,16 @@ printf("fvar = %f\n", fvar_get());
|
||||||
printf("dvar = %f\n", dvar_get());
|
printf("dvar = %f\n", dvar_get());
|
||||||
printf("cvar = %s\n", cvar_get());
|
printf("cvar = %s\n", cvar_get());
|
||||||
printf("strvar = %s\n", strvar_get());
|
printf("strvar = %s\n", strvar_get());
|
||||||
|
printf("name = %s\n", name_get());
|
||||||
Foo1_get()
|
Foo1_get()
|
||||||
Foo2_get()
|
Foo2_get()
|
||||||
|
pivar_get()
|
||||||
|
psvar_get()
|
||||||
|
foo_get()
|
||||||
|
|
||||||
printf("\nVariables (values printed from C)\n");
|
printf("\nVariables (values printed from C)\n");
|
||||||
|
|
||||||
print_vars();
|
print_vars()
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -492,8 +492,7 @@
|
||||||
$1 = ($1_ltype)*_pstStrings;
|
$1 = ($1_ltype)*_pstStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(varin,noblock=1) char *,
|
%typemap(varin,noblock=1) char * {
|
||||||
char [ANY] {
|
|
||||||
char *_pstStrings;
|
char *_pstStrings;
|
||||||
int _piLength;
|
int _piLength;
|
||||||
getVarAddressFromPosition($argnum, &piAddrVar);
|
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||||
|
|
@ -506,6 +505,57 @@
|
||||||
$1 = strdup(_pstStrings);
|
$1 = strdup(_pstStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%typemap(varin,noblock=1) char [ANY] {
|
||||||
|
char *_pstStrings;
|
||||||
|
int _piLength;
|
||||||
|
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||||
|
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||||
|
|
||||||
|
if (getVarType(piAddrVar) != sci_strings || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) {
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||||
|
}
|
||||||
|
getMatrixOfString(piAddrVar, &iRows, &iCols,&_piLength, &_pstStrings);
|
||||||
|
strcpy($1, _pstStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(varin,noblock=1) int *{
|
||||||
|
int *_piData;
|
||||||
|
int index;
|
||||||
|
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||||
|
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||||
|
if (getVarType(piAddrVar) != sci_ints || isVarComplex(piAddrVar)) {
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
getMatrixOfInteger32(piAddrVar, &iRows, &iCols, &_piData);
|
||||||
|
if($1 != NULL) {
|
||||||
|
free($1);
|
||||||
|
}
|
||||||
|
$1 = ($1_ltype)malloc(iRows * iCols * sizeof($*1_ltype));
|
||||||
|
for(index = 0; index < iRows * iCols; index++) {
|
||||||
|
$1[index] = ($*1_ltype)_piData[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(varin,noblock=1) short * {
|
||||||
|
short *_piData;
|
||||||
|
int index;
|
||||||
|
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||||
|
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||||
|
if (getVarType(piAddrVar) != sci_ints || isVarComplex(piAddrVar)) {
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
getMatrixOfInteger16(piAddrVar, &iRows, &iCols, &_piData);
|
||||||
|
if($1 != NULL) {
|
||||||
|
free($1);
|
||||||
|
}
|
||||||
|
$1 = ($1_ltype)malloc(iRows * iCols * sizeof($*1_ltype));
|
||||||
|
for(index = 0; index < iRows * iCols; index++) {
|
||||||
|
$1[index] = ($*1_ltype)_piData[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%typemap(varin,noblock=1) double *,
|
%typemap(varin,noblock=1) double *,
|
||||||
float * {
|
float * {
|
||||||
double *_piData;
|
double *_piData;
|
||||||
|
|
@ -544,6 +594,30 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%typemap(varin,noblock=1) char ** {
|
||||||
|
char **_pstStrings;
|
||||||
|
int *_piLength;
|
||||||
|
int i;
|
||||||
|
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||||
|
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||||
|
|
||||||
|
if (getVarType(piAddrVar) != sci_strings || isVarComplex(piAddrVar)) {
|
||||||
|
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
_piLength = (int*)malloc(sizeof(int) * iRows * iCols);
|
||||||
|
getMatrixOfString(piAddrVar, &iRows, &iCols, _piLength, NULL);
|
||||||
|
|
||||||
|
_pstStrings = (char**)malloc(iRows * iCols * sizeof(char*));
|
||||||
|
for(i = 0; i < iRows * iCols; i++) {
|
||||||
|
_pstStrings[i] = (char*)malloc((_piLength[i] + 1) * sizeof(char));
|
||||||
|
}
|
||||||
|
getMatrixOfString(piAddrVar, &iRows, &iCols, _piLength, _pstStrings);
|
||||||
|
|
||||||
|
$1 = _pstStrings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* --- Variable output ---
|
* --- Variable output ---
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -598,6 +672,20 @@
|
||||||
LhsVar(iOutNum) = iVarOut;
|
LhsVar(iOutNum) = iVarOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%typemap(varout,noblock=1) int *{
|
||||||
|
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, $result);
|
||||||
|
LhsVar(iOutNum) = iVarOut;
|
||||||
|
if($result != NULL)
|
||||||
|
free($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(varout,noblock=1) short *{
|
||||||
|
createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, $result);
|
||||||
|
LhsVar(iOutNum) = iVarOut;
|
||||||
|
if($result != NULL)
|
||||||
|
free($result);
|
||||||
|
}
|
||||||
|
|
||||||
%typemap(varout,noblock=1) double *,
|
%typemap(varout,noblock=1) double *,
|
||||||
float * {
|
float * {
|
||||||
if(isComplex) {
|
if(isComplex) {
|
||||||
|
|
@ -610,6 +698,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%typemap(varout,noblock=1) char [ANY] {
|
||||||
|
char **pstData = NULL;
|
||||||
|
pstData = (char **)malloc(sizeof(char *));
|
||||||
|
pstData[0] = $result;
|
||||||
|
createMatrixOfString(iVarOut, iRowsOut, iColsOut, pstData);
|
||||||
|
LhsVar(iOutNum) = iVarOut;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(varout,noblock=1) char ** {
|
||||||
|
char **pstData = NULL;
|
||||||
|
pstData = (char **)malloc(iRowsOut * iColsOut * sizeof(char*));
|
||||||
|
pstData = $result;
|
||||||
|
createMatrixOfString(iVarOut, iRowsOut, iColsOut, pstData);
|
||||||
|
LhsVar(iOutNum) = iVarOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* Enums mapped as integer values
|
* Enums mapped as integer values
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
|
||||||
|
|
@ -136,29 +136,29 @@ output values.
|
||||||
$1 = ($1_ltype)&temp;
|
$1 = ($1_ltype)&temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) signed char *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress) {
|
%typemap(argout) signed char *OUTPUT(int iRowsOut, int iColsOut) {
|
||||||
iRowsOut = 1;
|
iRowsOut = 1;
|
||||||
iColsOut = 1;
|
iColsOut = 1;
|
||||||
createMatrixOfInteger8(iVarOut, iRowsOut, iColsOut, &temp$argnum, &_piAddress);
|
createMatrixOfInteger8(iVarOut, iRowsOut, iColsOut, &temp$argnum);
|
||||||
LhsVar(iOutNum) = iVarOut;
|
LhsVar(iOutNum) = iVarOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) short *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress),
|
%typemap(argout) short *OUTPUT(int iRowsOut, int iColsOut),
|
||||||
unsigned char *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress) {
|
unsigned char *OUTPUT(int iRowsOut, int iColsOut) {
|
||||||
iRowsOut = 1;
|
iRowsOut = 1;
|
||||||
iColsOut = 1;
|
iColsOut = 1;
|
||||||
createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, &temp$argnum, &_piAddress);
|
createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, &temp$argnum);
|
||||||
LhsVar(iOutNum) = iVarOut;
|
LhsVar(iOutNum) = iVarOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(argout) int *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress),
|
%typemap(argout) int *OUTPUT(int iRowsOut,int iColsOut),
|
||||||
unsigned int *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress),
|
unsigned int *OUTPUT(int iRowsOut,int iColsOut),
|
||||||
unsigned short *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress),
|
unsigned short *OUTPUT(int iRowsOut,int iColsOut),
|
||||||
unsigned long *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress),
|
unsigned long *OUTPUT(int iRowsOut,int iColsOut),
|
||||||
long *OUTPUT(int iRowsOut,int iColsOut,int* _piAddress) {
|
long *OUTPUT(int iRowsOut,int iColsOut) {
|
||||||
iRowsOut=1;
|
iRowsOut=1;
|
||||||
iColsOut=1;
|
iColsOut=1;
|
||||||
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp$argnum, &_piAddress);
|
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp$argnum);
|
||||||
LhsVar(iOutNum)=iVarOut;
|
LhsVar(iOutNum)=iVarOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue