summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaozeng Ding <sploving1@163.com>2009-07-30 09:41:11 +0000
committerBaozeng Ding <sploving1@163.com>2009-07-30 09:41:11 +0000
commita19aea6b4b8ad622701088426193b0ea594524bf (patch)
tree86cf5bc2b034fee24af15a6a4be67b77d6af7e64
parent8217f59d551c2a3e1a1cccbed38c551e894d95e9 (diff)
downloadswig-a19aea6b4b8ad622701088426193b0ea594524bf.tar.gz
add array example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11478 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Examples/scilab/funcptr/Makefile17
-rw-r--r--Examples/scilab/funcptr/example.c20
-rw-r--r--Examples/scilab/funcptr/example.h9
-rw-r--r--Examples/scilab/funcptr/example.i11
-rw-r--r--Examples/scilab/funcptr/runme.sci20
-rw-r--r--Examples/scilab/matrix/Makefile17
-rw-r--r--Examples/scilab/matrix/example.c61
-rw-r--r--Examples/scilab/matrix/example.i36
-rw-r--r--Examples/scilab/matrix/runme.sci41
-rw-r--r--Examples/scilab/pointer/example.i4
-rw-r--r--Examples/scilab/pointer/runme.sci24
-rw-r--r--Examples/scilab/variables/example.c58
-rw-r--r--Examples/scilab/variables/example.i29
-rw-r--r--Examples/scilab/variables/runme.sci22
-rw-r--r--Lib/scilab/scitypemaps.swg319
-rw-r--r--Source/Modules/scilab.cxx12
16 files changed, 458 insertions, 242 deletions
diff --git a/Examples/scilab/funcptr/Makefile b/Examples/scilab/funcptr/Makefile
new file mode 100644
index 000000000..b22d383ba
--- /dev/null
+++ b/Examples/scilab/funcptr/Makefile
@@ -0,0 +1,17 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
+
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile scilab_clean
+ rm -f *.sce *.so lib*lib.c *_wrap.c
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile scilab_run
diff --git a/Examples/scilab/funcptr/example.c b/Examples/scilab/funcptr/example.c
new file mode 100644
index 000000000..9d3926583
--- /dev/null
+++ b/Examples/scilab/funcptr/example.c
@@ -0,0 +1,20 @@
+/* File : example.c */
+
+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;
+
diff --git a/Examples/scilab/funcptr/example.h b/Examples/scilab/funcptr/example.h
new file mode 100644
index 000000000..9936e24fc
--- /dev/null
+++ b/Examples/scilab/funcptr/example.h
@@ -0,0 +1,9 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/scilab/funcptr/example.i b/Examples/scilab/funcptr/example.i
new file mode 100644
index 000000000..e8af50e6f
--- /dev/null
+++ b/Examples/scilab/funcptr/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/scilab/funcptr/runme.sci b/Examples/scilab/funcptr/runme.sci
new file mode 100644
index 000000000..ad4c9d046
--- /dev/null
+++ b/Examples/scilab/funcptr/runme.sci
@@ -0,0 +1,20 @@
+// builder the *.so
+exec builder.sce;
+
+// loader the *.so
+exec loader.sce;
+
+a = 37
+b = 42
+
+// Now call our C function with a bunch of callbacks
+
+printf("Trying some C callback functions\n");
+printf(" a = %i\n", a);
+printf(" b = %i\n", b);
+printf(" ADD(a,b) = %i\n", do_op(a,b,funcvar_get()));
+
+exit
+
+
+
diff --git a/Examples/scilab/matrix/Makefile b/Examples/scilab/matrix/Makefile
new file mode 100644
index 000000000..b22d383ba
--- /dev/null
+++ b/Examples/scilab/matrix/Makefile
@@ -0,0 +1,17 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
+
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile scilab_clean
+ rm -f *.sce *.so lib*lib.c *_wrap.c
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile scilab_run
diff --git a/Examples/scilab/matrix/example.c b/Examples/scilab/matrix/example.c
new file mode 100644
index 000000000..6ce10098b
--- /dev/null
+++ b/Examples/scilab/matrix/example.c
@@ -0,0 +1,61 @@
+/* FILE : matrix.c : some simple 4x4 matrix operations */
+#include <stdlib.h>
+#include <stdio.h>
+
+double **new_matrix() {
+
+ int i;
+ double **M;
+
+ M = (double **) malloc(4*sizeof(double *));
+ M[0] = (double *) malloc(16*sizeof(double));
+
+ for (i = 0; i < 4; i++) {
+ M[i] = M[0] + 4*i;
+ }
+ return M;
+}
+
+void destroy_matrix(double **M) {
+
+ free(M[0]);
+ free(M);
+
+}
+
+void print_matrix(double **M) {
+
+ int i,j;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ printf("%10g ", M[i][j]);
+ }
+ printf("\n");
+ }
+
+}
+
+void mat_mult(double **m1, double **m2, double **m3) {
+
+ int i,j,k;
+ double temp[4][4];
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++) {
+ temp[i][j] = 0;
+ for (k = 0; k < 4; k++)
+ temp[i][j] += m1[i][k]*m2[k][j];
+ }
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ m3[i][j] = temp[i][j];
+}
+
+
+
+
+
+
+
diff --git a/Examples/scilab/matrix/example.i b/Examples/scilab/matrix/example.i
new file mode 100644
index 000000000..c930e92f5
--- /dev/null
+++ b/Examples/scilab/matrix/example.i
@@ -0,0 +1,36 @@
+%module example
+// FILE : matrix.i
+
+%{
+
+void set_m(double **M, int i, int j, double val) {
+ M[i][j] = val;
+}
+
+double get_m(double **M, int i, int j) {
+ return M[i][j];
+}
+%}
+
+%inline {
+/*** Matrix Operations ***/
+
+extern double **new_matrix();
+/* Creates a new matrix and returns a pointer to it */
+
+extern void destroy_matrix(double **M);
+/* Destroys the matrix M */
+
+extern void print_matrix(double **M);
+/* Prints out the matrix M */
+
+extern void set_m(double **M, int i, int j, double val);
+/* Sets M[i][j] = val*/
+
+extern double get_m(double **M, int i, int j);
+/* Returns M[i][j] */
+
+extern void mat_mult(double **a, double **b, double **c);
+/* Multiplies matrix a by b and places the result in c*/
+
+}
diff --git a/Examples/scilab/matrix/runme.sci b/Examples/scilab/matrix/runme.sci
new file mode 100644
index 000000000..20dddb258
--- /dev/null
+++ b/Examples/scilab/matrix/runme.sci
@@ -0,0 +1,41 @@
+// builder the *.so
+exec builder.sce
+
+// loader the *.so
+exec loader.sce
+
+// creat a new matrix
+x = new_matrix();
+for i = 0 : 3;
+ for j = 0 : 3;
+ set_m(x, i, j, i+j);
+ end;
+end;
+
+// print the matrix
+print_matrix(x);
+
+// another matrix
+y = new_matrix();
+ for i = 0 : 3;
+ for j = 0 : 3;
+ set_m(y, i, j, i-j);
+ end;
+ end;
+
+// print the matrix
+print_matrix(y);
+
+// mat_mult the two matrix, and the result is stored in a new matrix
+z = new_matrix();
+
+mat_mult(x, y, z);
+
+print_matrix(z);
+
+//destroy the matrix
+destroy_matrix(x);
+destroy_matrix(y);
+destroy_matrix(z);
+
+exit
diff --git a/Examples/scilab/pointer/example.i b/Examples/scilab/pointer/example.i
index aea3769fe..a8ac79499 100644
--- a/Examples/scilab/pointer/example.i
+++ b/Examples/scilab/pointer/example.i
@@ -10,10 +10,10 @@ 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
+/* First we'll use the pointer library */
extern void add(int *x, int *y, int *result);
%include cpointer.i
-%pointer_functions(int, intp);*/
+%pointer_functions(int, intp);
/* Next we'll use some typemaps */
diff --git a/Examples/scilab/pointer/runme.sci b/Examples/scilab/pointer/runme.sci
index 461e2dd38..308217d9d 100644
--- a/Examples/scilab/pointer/runme.sci
+++ b/Examples/scilab/pointer/runme.sci
@@ -1,9 +1,31 @@
// builder the *.so
exec builder.sce
-//loader the *.so
+// loader the *.so
exec loader.sce
+// First create some objects using the pointer library.
+printf("Testing the pointer library\n");
+a = new_intp();
+b = new_intp();
+c = new_intp();
+intp_assign(a,37);
+intp_assign(b,42);
+
+a,b,c
+
+// Call the add() function with some pointers
+add(a,b,c);
+
+// Now get the result
+r = intp_value(c);
+printf(" 37 + 42 = %i\n",r);
+
+// Clean up the pointers
+delete_intp(a);
+delete_intp(b);
+delete_intp(c);
+
//Now try the typemap library
//This should be much easier. Now how it is no longer
//necessary to manufacture pointers.
diff --git a/Examples/scilab/variables/example.c b/Examples/scilab/variables/example.c
index c665c3e3b..1b3eeaff0 100644
--- a/Examples/scilab/variables/example.c
+++ b/Examples/scilab/variables/example.c
@@ -9,7 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "sciprint.h"
+#include "example.h"
int ivar = 0;
short svar = 0;
@@ -22,15 +22,20 @@ unsigned char ucvar = 0;
char cvar = 0;
float fvar = 0;
double dvar = 0;
-char *strvar=0;
+char *strvar = 0;
+const char cstrvar[] = "Goodbye";
+int *iptrvar = 0;
char name[5] = "Dave";
-double *Foo1;
-double *Foo2;
-int *pivar;
-short *psvar;
-char **foo;
+char path[256] = "/home/beazley";
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
/* A debugging function to print out their values */
void print_vars() {
@@ -45,9 +50,46 @@ void print_vars() {
printf("fvar = %g\n", fvar);
printf("dvar = %g\n", dvar);
printf("cvar = %c\n", cvar);
- printf("strvar = %s\n",strvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
+ printf("iptrvar = %p\n", iptrvar);
printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]);
+ //printf("ptptr = %p %s\n", ptptr, Point_print( ptptr ) );
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
}
+int value_int(int *value) {
+ return *value;
+}
+/* A function to create a point */
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d,%d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/scilab/variables/example.i b/Examples/scilab/variables/example.i
index 399c3fa2f..c5e39f6ab 100644
--- a/Examples/scilab/variables/example.i
+++ b/Examples/scilab/variables/example.i
@@ -1,5 +1,8 @@
/* File : example.i */
%module example
+%{
+#include "example.h"
+%}
#pragma SWIG nowarn=SWIGWARN_TYPEMAP_SWIGTYPELEAK
@@ -17,17 +20,33 @@
extern float fvar;
extern double dvar;
extern char *strvar;
+ // extern const char cstrvar[];
+ extern int *iptrvar;
extern char name[256];
- extern double *Foo1;
- extern double *Foo2;
- extern int *pivar;
- extern short *psvar;
- extern char **foo;
+
+ extern Point *ptptr;
+ extern Point pt;
+
+%}
+
+
+/* Some read-only variables */
+
+%immutable;
+
+%inline %{
+extern int status;
+extern char path[256];
%}
+%mutable;
/* Some helper functions to make it easier to test */
%inline %{
extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
%}
diff --git a/Examples/scilab/variables/runme.sci b/Examples/scilab/variables/runme.sci
index 6e9ede1bb..d7db519de 100644
--- a/Examples/scilab/variables/runme.sci
+++ b/Examples/scilab/variables/runme.sci
@@ -18,17 +18,10 @@ cvar_set ("S");
fvar_set (3.14159);
dvar_set (2.1828);
strvar_set("Hello World");
-name_set ("Bill");
-Foo1_set([1,2,3;4,5,6]);
-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"]);
+iptrvar= new_int(37);
+ptptr = new_Point(37,42);
+name_set ("Bill");
// Now print out the values of the variables
printf("Variables (values printed from Scilab)\n");
@@ -45,13 +38,10 @@ printf("fvar = %f\n", fvar_get());
printf("dvar = %f\n", dvar_get());
printf("cvar = %s\n", cvar_get());
printf("strvar = %s\n", strvar_get());
-printf("name = %s\n", name_get());
-Foo1_get()
-Foo2_get()
-pivar_get()
-psvar_get()
-foo_get()
+iptrvar
+printf("name = %s\n", name_get());
+printf("ptptr = %s\n", Point_print(ptptr));
printf("\nVariables (values printed from C)\n");
print_vars()
diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg
index d2a5ca214..919693cf8 100644
--- a/Lib/scilab/scitypemaps.swg
+++ b/Lib/scilab/scitypemaps.swg
@@ -50,67 +50,28 @@
$1 = ($1_ltype)*_pstStrings;
}
-
/* Pointers */
-%typemap(in) signed char *(int *piAddrVar, int iRows, int iCols) {
- char *_piData;
- int index;
+%typemap(in) signed char * (int *piAddrVar),
+ short * (int *piAddrVar),
+ unsigned char * (int *piAddrVar),
+ unsigned short * (int *piAddrVar),
+ int * (int *piAddrVar),
+ unsigned int * (int *piAddrVar),
+ long * (int *piAddrVar),
+ unsigned long * (int *piAddrVar),
+ double * (int *piAddrVar),
+ float * (int *piAddrVar) {
+ void *_piData = NULL;
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);
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
}
- getMatrixOfInteger8(piAddrVar, &iRows, &iCols, &_piData);
- $1 = ($1_ltype)_piData;
-}
-
-%typemap(in) short *(int *piAddrVar, int iRows, int iCols),
- unsigned char *(int *piAddrVar, int iRows, int iCols) {
- 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);
+ getPointer(piAddrVar, &_piData);
$1 = ($1_ltype)_piData;
}
-%typemap(in) unsigned short *(int *piAddrVar, int iRows, int iCols),
- int *(int *piAddrVar, int iRows, int iCols),
- unsigned int *(int *piAddrVar, int iRows, int iCols),
- long *(int *piAddrVar, int iRows, int iCols),
- unsigned long *(int *piAddrVar, int iRows, int iCols) {
- 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);
- $1 = ($1_ltype)_piData;
-}
-
-%typemap(in) double *(int *piAddrVar, int iRows, int iCols),
- float *(int *piAddrVar, int iRows, int iCols) {
- double *_piData;
- int index;
- getVarAddressFromPosition($argnum, &piAddrVar);
- getVarDimension(piAddrVar, &iRows, &iCols);
-
- if (getVarType(piAddrVar) != sci_matrix || isVarComplex(piAddrVar)) {
- Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
- }
- getMatrixOfDouble(piAddrVar, &iRows, &iCols, &_piData);
- $1 = ($1_ltype)_piData;
-}
-
-%typemap(in) char *(int *piAddrVar, int iRows, int iCols){
+%typemap(in) char * (int *piAddrVar, int iRows, int iCols){
char *_pstStrings;
int _piLength;
getVarAddressFromPosition($argnum, &piAddrVar);
@@ -205,8 +166,6 @@
}
}
-
-
%typemap(in) char [ANY] (int *piAddrVar, int iRows, int iCols){
char *_pstStrings;
int _piLength;
@@ -220,7 +179,6 @@
$1 = strdup(_pstStrings);
}
-
/* Arrays */
%typemap(in) signed char [ANY][ANY] (int *piAddrVar, int iRows, int iCols) {
char *_piData;
@@ -317,20 +275,26 @@
}
}
-%typemap(in) SWIGTYPE *(int *piAddrVar, int iRows, int iCols) {
- $&1_ltype _piData = ($&1_ltype)0;
+%typemap(in) SWIGTYPE * (int *piAddrVar) {
+ void *_piData = NULL;
getVarAddressFromPosition($argnum, &piAddrVar);
- getVarDimension(piAddrVar, &iRows, &iCols);
- if (getVarType(piAddrVar) != sci_matrix || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) {
- Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
}
- getMatrixOfDouble(piAddrVar, &iRows, &iCols, &_piData);
- $1 = ($1_ltype)*_piData;
+ getPointer(piAddrVar, &_piData);
+ $1 = ($1_ltype)_piData;
}
%typemap(in) SWIGTYPE {
+ void *_piData = NULL;
+ getVarAddressFromPosition($argnum, &piAddrVar);
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
+ }
+ getPointer(piAddrVar, &_piData);
+ $1 = *(($&1_ltype)_piData);
}
/* -----------------------------------------------------------------------------
@@ -409,48 +373,18 @@
}
/* Pointers */
-%typemap(out) signed char *(int iRowsOut, int iColsOut) {
- char *temp;
- temp = (char *)($result);
- iRowsOut = 1;
- iColsOut = 1;
- createMatrixOfInteger8(iVarOut, iRowsOut, iColsOut, temp);
- LhsVar(iOutNum) = iVarOut;
-}
-
-%typemap(out) short *(int iRowsOut, int iColsOut),
- unsigned char *(int iRowsOut, int iColsOut) {
- short *temp;
- temp = (short *)($result);
- iRowsOut = 1;
- iColsOut = 1;
- createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, temp);
- LhsVar(iOutNum) = iVarOut;
-}
-
-%typemap(out) int *(int iRowsOut, int iColsOut),
- unsigned int *(int iRowsOut, int iColsOut),
- unsigned short *(int iRowsOut, int iColsOut),
- unsigned long *(int iRowsOut, int iColsOut),
- long *(int iRowsOut, int iColsOut) {
- int *temp;
- temp = (int *)($result);
- iRowsOut = 1;
- iColsOut = 1;
- createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, temp);
- LhsVar(iOutNum) = iVarOut;
-}
-
-%typemap(out) double *,
+%typemap(out) signed char *,
+ short *,
+ unsigned char *,
+ unsigned short *,
+ int *,
+ unsigned int *,
+ long *,
+ unsigned long *,
+ double *,
float * {
- double *temp;
- temp = (double *)($result);
- iRowsOut = 1;
- iColsOut = 1;
- createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, temp);
+ createPointer(iVarOut, (void *)$result);
LhsVar(iOutNum) = iVarOut;
- iOutNum++;
- iVarOut++;
}
%typemap(out) char *(int iRowsOut, int iColsOut) {
@@ -464,10 +398,13 @@
if ($1) free($1);
}
-%typemap(out) SWIGTYPE *(int iRowsOut, int iColsOut) {
- iRowsOut = 1;
- iColsOut = 1;
- createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, &$result);
+%typemap(out) SWIGTYPE * {
+ createPointer(iVarOut, (void *)$result);
+ LhsVar(iOutNum) = iVarOut;
+}
+
+%typemap(out) SWIGTYPE {
+ createPointer(iVarOut, (void *)&$result);
LhsVar(iOutNum) = iVarOut;
}
@@ -518,8 +455,11 @@
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);
+ getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, NULL);
+ _pstStrings = (char *)malloc(sizeof(char) * _piLength);
+ getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, &_pstStrings);
$1 = strdup(_pstStrings);
+ free(_pstStrings);
}
%typemap(varin,noblock=1) char [ANY] {
@@ -531,84 +471,32 @@
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 *,
+ getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, NULL);
+ _pstStrings = (char *)malloc(sizeof(char) * _piLength);
+ getMatrixOfString(piAddrVar, &iRows, &iCols, &_piLength, &_pstStrings);
+ strcpy($1, _pstStrings);
+ free(_pstStrings);
+}
+
+%typemap(varin,noblock=1) signed char *,
+ short *,
+ unsigned char *,
+ unsigned short *,
+ int *,
+ unsigned int *,
+ long *,
+ unsigned long *,
+ double *,
float * {
- double *_piData;
- int index;
+ void *_piData = NULL;
getVarAddressFromPosition($argnum, &piAddrVar);
- getVarDimension(piAddrVar, &iRows, &iCols);
- if (getVarType(piAddrVar) == sci_matrix ){
- if(!isVarComplex(piAddrVar)) {
- isComplex = 0;
- getMatrixOfDouble(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];
- }
- }
- else {
- isComplex = 1;
- double *_pdblImg;
- getComplexMatrixOfDouble(piAddrVar, &iRows, &iCols, &_piData, &_pdblImg);
- if($1 != NULL) {
- free($1);
- }
- $1 = ($1_ltype)malloc(2 * iRows * iCols * sizeof($*1_ltype));
- for(index = 0; index < iRows * iCols; index++){
- $1[index] = ($*1_ltype)_piData[index];
- $1[index + iRows * iCols] = (double)_pdblImg[index];
- }
- }
- }
- else {
- Scierror(999, _("%s: Wrong type for input argument #%d: double matrix expected.\n"), fname, $argnum);
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
}
+ getPointer(piAddrVar, &_piData);
+ $1 = ($1_ltype)_piData;
}
%typemap(varin,noblock=1) char ** {
@@ -634,6 +522,27 @@
$1 = _pstStrings;
}
+%typemap(varin,noblock=1) SWIGTYPE *(int *piAddrVar) {
+ void *_piData = NULL;
+ getVarAddressFromPosition($argnum, &piAddrVar);
+
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
+ }
+ getPointer(piAddrVar, &_piData);
+ $1 = ($1_ltype)_piData;
+}
+
+%typemap(varin,nobloack=1) SWIGTYPE {
+ void *_piData = NULL;
+ getVarAddressFromPosition($argnum, &piAddrVar);
+
+ if (getVarType(piAddrVar) != sci_lufact_pointer) {
+ Scierror(999, _("%s: Wrong type for input argument #%d: Pointer expected.\n"), fname, $argnum);
+ }
+ getPointer(piAddrVar, &_piData);
+ $1 = *(($&1_ltype)_piData);
+}
/* -----------------------------------------------------------------------------
* --- Variable output ---
@@ -690,35 +599,23 @@
LhsVar(iOutNum) = iVarOut;
}
-%typemap(varout,noblock=1) char *{
+%typemap(varout,noblock=1) char * {
createMatrixOfString(iVarOut, iRowsOut, iColsOut, &($result));
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) signed char *,
+ short *,
+ unsigned char *,
+ unsigned short *,
+ int *,
+ unsigned int *,
+ long *,
+ unsigned long *,
+ double *,
float * {
- if(isComplex) {
- createComplexMatrixOfDouble(iVarOut, iRowsOut, iColsOut, $result, &$result[iRowsOut * iColsOut]);
- LhsVar(iOutNum) = iVarOut;
- }
- else {
- createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, $result);
- LhsVar(iOutNum) = iVarOut;
- }
+ createPointer(iVarOut, (void *)$result);
+ LhsVar(iOutNum) = iVarOut;
}
%typemap(varout,noblock=1) char [ANY] {
@@ -738,9 +635,17 @@
LhsVar(iOutNum) = iVarOut;
}
+%typemap(varout,noblock=1) SWIGTYPE * {
+ createPointer(iVarOut, (void *)$result);
+ LhsVar(iOutNum) = iVarOut;
+}
-
+%typemap(varout,noblock=1) SWIGTYPE {
+ createPointer(iVarOut, (void *)&$result);
+ LhsVar(iOutNum) = iVarOut;
+}
+
/* ------------------------------------------------------------
* Enums mapped as integer values
* ------------------------------------------------------------ */
diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx
index 896cca271..0b581623e 100644
--- a/Source/Modules/scilab.cxx
+++ b/Source/Modules/scilab.cxx
@@ -393,6 +393,7 @@ public:
}
}
else {
+ Append(setf->code, "SWIG_Error(999, \"attempt to set immutable member variable\");");
}
Append(setf->code, "}\n");
Wrapper_print(setf, f_wrappers);
@@ -412,9 +413,14 @@ public:
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$result", name);
- Replaceall(tm, "iRowsOut", rowname);
- Replaceall(tm, "iColsOut", colname);
- Replaceall(tm, "isComplex", iscomplexname);
+ if (is_assignable(n)) {
+ Replaceall(tm, "iRowsOut", rowname);
+ Replaceall(tm, "iColsOut", colname);
+ } else {
+ Replaceall(tm, "iRowsOut", "1");
+ Replaceall(tm, "iColsOut", "1");
+ }
+ Replaceall(tm, "isComplex", iscomplexname);
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
} else {