From 8d2ce8c8a8be6c1be5eaf2fae12e91be55bdd44c Mon Sep 17 00:00:00 2001 From: Baozeng Ding Date: Thu, 25 Jun 2009 03:14:26 +0000 Subject: [PATCH] Some change:getVarAddressFromPosition,createMatrixOfDouble,createMatrixOfString and add argument number checking git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11315 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/Makefile.in | 4 +- Lib/scilab/scitypemaps.swg | 237 ++++++++++++++++++++++++++++++++----- Lib/scilab/typemaps.i | 10 +- Makefile.in | 6 +- Source/Modules/scilab.cxx | 38 +++++- 5 files changed, 252 insertions(+), 43 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index e1b4c2108..8aa4fed21 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -1139,7 +1139,7 @@ r_clean: ##### SCILAB ###### ################################################################## -# Make sure these locate your Octave installation +# Make sure these locate your Scilab installation SCILAB_INCLUDE= $(DEFS) @SCILABINCLUDE@ SCILAB_LIB = @SCILABLIB@ SCILAB = @SCILAB@ @@ -1158,5 +1158,5 @@ scilab: $(SRCS) # ----------------------------------------------------------------- scilab_clean: - rm -f *_wrap* + rm -f *.sce *.so lib*lib.c diff --git a/Lib/scilab/scitypemaps.swg b/Lib/scilab/scitypemaps.swg index 29ffe5045..1229a6c6e 100644 --- a/Lib/scilab/scitypemaps.swg +++ b/Lib/scilab/scitypemaps.swg @@ -27,7 +27,7 @@ float (int *piAddrVar, int iRows, int iCols), double (int *piAddrVar, int iRows, int iCols) { double* _piData; - getVarAddressFromNumber($argnum, &piAddrVar); + getVarAddressFromPosition($argnum, &piAddrVar); getVarDimension(piAddrVar, &iRows, &iCols); if (getVarType(piAddrVar) != sci_matrix || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) { @@ -40,7 +40,7 @@ %typemap(in) char (int *piAddrVar, int iRows, int iCols) { char* _pstStrings; int _piLength; - getVarAddressFromNumber($argnum, &piAddrVar); + getVarAddressFromPosition($argnum, &piAddrVar); getVarDimension(piAddrVar, &iRows, &iCols); if (getVarType(piAddrVar) != sci_strings || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) { @@ -51,18 +51,82 @@ } /* Pointers */ -%typemap(in) signed char *(int *piAddrVar, int iRows, int iCols, signed char temp), - unsigned char *(int *piAddrVar, int iRows, int iCols, unsigned char temp), - short *(int *piAddrVar, int iRows, int iCols, short temp), - unsigned short *(int *piAddrVar, int iRows, int iCols, unsigned short temp), - int *(int *piAddrVar, int iRows, int iCols, int temp), - unsigned int *(int *piAddrVar, int iRows, int iCols, unsigned int temp), - long *(int *piAddrVar, int iRows, int iCols, long temp), - unsigned long *(int *piAddrVar, int iRows, int iCols, unsigned long temp), - float *(int *piAddrVar, int iRows, int iCols, float temp), - double *(int *piAddrVar, int iRows, int iCols, double temp) { +%typemap(in) signed char *(int *piAddrVar, int iRows, int iCols) { + char* _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, 1); + } + getMatrixOfInteger8(piAddrVar, &iRows, &iCols, &_piData); + if($1!=NULL) { + free($1); + } + $1=($1_ltype)malloc(iRows*iCols*sizeof($*1_ltype)); + for(index=0;indexdef, "int ", overname, " (char *fname,unsigned long fname_len) {\nint iOutNum=1;\nint iVarOut=Rhs+1;", NIL); + Printv(f->def, "int ", overname, " (char *fname,unsigned long fname_len) {\n", NIL); /* Emit all of the local variables for holding arguments */ emit_parameter_variables(l, f); @@ -199,8 +199,12 @@ public: /* Get number of required and total arguments */ int num_arguments = emit_num_arguments(l); int num_required = emit_num_required(l); + + /* the number of the output */ + int out_required = 0; //int varargs = emit_isvarargs(l); + if (constructor && num_arguments == 1 && num_required == 1) { if (Cmp(storage, "explicit") == 0) { Node *parent = Swig_methodclass(n); @@ -252,7 +256,8 @@ public: if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) { Replaceall(tm, "$result", "result"); Printf(f->code, "%s\n", tm); - + if(strlen(Char(tm))!=0) + out_required++; } else { Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), iname); @@ -264,11 +269,20 @@ public: if ((tm = Getattr(p, "tmap:argout"))) { Printv(outarg, tm, "\n", NIL); p = Getattr(p, "tmap:argout:next"); + out_required++; } else { p = nextSibling(p); } } Printv(f->code, outarg, NIL); + + /* Insert the code checking for the number of input and output */ + if(out_required==0) out_required=1; + Printf(f->def,"CheckRhs(%d,%d);\n",num_required,num_required); + Printf(f->def,"CheckLhs(%d,%d);\n",out_required,out_required); + + /* Insert the order of output parameters*/ + Printf(f->def,"\nint iOutNum=1;\nint iVarOut=Rhs+1;"); /* Finish the the code for the function */ Printf(f->code, "return 0;\n"); @@ -312,7 +326,14 @@ public: String *getname = Swig_name_get(iname); String *setname = Swig_name_set(iname); - Printv(setf->def, "int ", setname, " (char *fname,unsigned long fname_len) {\nint iOutNum=1;\nint iVarOut=Rhs+1;", NIL); + Printv(setf->def, "int ", setname, " (char *fname,unsigned long fname_len) {\n", NIL); + + /* Check the number of input and output */ + Printf(setf->def,"CheckRhs(1,1);\n"); + Printf(setf->def,"CheckLhs(1,1);\n"); + + /* Insert the order of output parameters*/ + Printf(setf->def,"\nint iOutNum=1;\nint iVarOut=Rhs+1;"); /* add the local variable */ Wrapper_add_local(setf, "piAddrVar", "int *piAddrVar"); @@ -339,7 +360,14 @@ public: /* deal with the get function */ Setattr(n, "wrap:name", getname); int addfail = 0; - Printv(getf->def, "int ", getname, " (char *fname,unsigned long fname_len){\nint iOutNum=1;\nint iVarOut=Rhs+1;", NIL); + Printv(getf->def, "int ", getname, " (char *fname,unsigned long fname_len){\n", NIL); + + /* Check the number of input and output */ + Printf(getf->def,"CheckRhs(0,0);\n"); + Printf(getf->def,"CheckLhs(1,1);\n"); + + /* Insert the order of output parameters*/ + Printf(getf->def,"\nint iOutNum=1;\nint iVarOut=Rhs+1;"); /* add local variabe */ Wrapper_add_local(getf, "piAddrOut", "int* _piAddress");