From e8fd0e506ede5de7aa92a5ce20bba44eaafb84af Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 31 Jan 2014 15:34:00 +0100 Subject: [PATCH] scilab: fix and optimize integer typemaps --- Lib/scilab/sciint.swg | 52 +++++++++++----------- Lib/scilab/scilong.swg | 84 ++++++++++++++++++++++++++++++------ Lib/scilab/scishort.swg | 64 ++++++++++++++------------- Lib/scilab/scisignedchar.swg | 82 +++++++++++++++++++++-------------- 4 files changed, 181 insertions(+), 101 deletions(-) diff --git a/Lib/scilab/sciint.swg b/Lib/scilab/sciint.swg index 60aa1f942..b3e6f0269 100644 --- a/Lib/scilab/sciint.swg +++ b/Lib/scilab/sciint.swg @@ -27,47 +27,48 @@ SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue, printError(&sciErr, 0); return SWIG_ERROR; } + if (iType == sci_ints) { int iPrec = 0; int *piData = NULL; - sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; + sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; } if (iPrec != SCI_INT32) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar); - return SWIG_ERROR; + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; } sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &piData); if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; + printError(&sciErr, 0); + return SWIG_ERROR; } if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar); - return SWIG_ERROR; + Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; } *_piValue = *piData; } else if (iType == sci_matrix) { - double *pdData = NULL; + double *pdData = NULL; - sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - *_piValue = (int) *pdData; + sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_piValue = (int) *pdData; } else { - Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or double expected.\n"), _fname, _iVar); + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); return SWIG_ERROR; } @@ -80,10 +81,9 @@ SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue, } %fragment("SWIG_SciDouble_FromInt", "header") { SWIGINTERN int -SWIG_SciDouble_FromInt(void *_pvApiCtx, int _iVarOut, int _iValue, char *_fname) -{ - int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + SWIG_Scilab_GetOutputPosition(); - if (createScalarDouble(_pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + _iVarOut, (double) _iValue)) +SWIG_SciDouble_FromInt(void *_pvApiCtx, int _iVarOut, int _iValue, char *_fname){ + int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + _iVarOut; + if (createScalarDouble(_pvApiCtx, iVarOut, (double) _iValue)) return SWIG_ERROR; return iVarOut; } diff --git a/Lib/scilab/scilong.swg b/Lib/scilab/scilong.swg index 19eeac6fc..caa48f259 100644 --- a/Lib/scilab/scilong.swg +++ b/Lib/scilab/scilong.swg @@ -3,28 +3,88 @@ * Scilab type: double or int32 */ -%fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_Int_AsLong") { -%#define SWIG_AsVal_long(scilabValue, valuePointer) SWIG_Int_AsLong(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname()); +%fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_SciDoubleOrInt32_AsLong") { +%#define SWIG_AsVal_long(scilabValue, valuePointer) SWIG_SciDoubleOrInt32_AsLong(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname()); } -%fragment("SWIG_Int_AsLong", "header", fragment=SWIG_AsVal_frag(int)) { +%fragment("SWIG_SciDoubleOrInt32_AsLong", "header") { SWIGINTERN int -SWIG_Int_AsLong(void *_pvApiCtx, SwigSciObject _iVar, long *_plValue, char *_fname) { - int iValue = 0.0; - if(SWIG_AsVal_dec(int)(_iVar, &iValue) != SWIG_OK) { +SWIG_SciDoubleOrInt32_AsLong(void *_pvApiCtx, SwigSciObject _iVar, long *_plValue, char *_fname) { + SciErr sciErr; + int iType = 0; + int iRows = 0; + int iCols = 0; + int *piAddrVar = NULL; + + sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); + if (sciErr.iErr) { + printError(&sciErr, 0); return SWIG_ERROR; } - *_plValue = (long) iValue; + + sciErr = getVarType(_pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_ints) { + int iPrec = 0; + int *piData = NULL; + + sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT32) { + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + + sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &piData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_plValue = (long) *piData; + } + else if (iType == sci_matrix) { + double *pdData = NULL; + + sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_plValue = (long) *pdData; + } + else { + Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + return SWIG_OK; } } -%fragment(SWIG_From_frag(long), "header", fragment="SWIG_Int_FromLong") { -%#define SWIG_From_long(scilabValue) SWIG_Int_FromLong(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFname()) +%fragment(SWIG_From_frag(long), "header", fragment="SWIG_SciDouble_FromLong") { +%#define SWIG_From_long(scilabValue) SWIG_SciDouble_FromLong(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFname()) } -%fragment("SWIG_Int_FromLong", "header", fragment=SWIG_From_frag(int)) { +%fragment("SWIG_SciDouble_FromLong", "header") { SWIGINTERN int -SWIG_Int_FromLong(void *_pvApiCtx, int _iVarOut, long _lValue, char *_fname) { - return SWIG_From_dec(int)((int)_lValue); +SWIG_SciDouble_FromLong(void *_pvApiCtx, int _iVarOut, long _lValue, char *_fname) { + int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + _iVarOut; + if (createScalarDouble(_pvApiCtx, iVarOut, (double) _lValue)) + return SWIG_ERROR; + return iVarOut; } } diff --git a/Lib/scilab/scishort.swg b/Lib/scilab/scishort.swg index 55267b956..696e2714e 100644 --- a/Lib/scilab/scishort.swg +++ b/Lib/scilab/scishort.swg @@ -3,12 +3,12 @@ * Scilab type: double or int16 */ -%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciInt16_AsShort") { -#define SWIG_AsVal_short(scilabValue, valuePointer) SWIG_SciInt16_AsShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname()) +%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciDoubleOrInt16_AsShort") { +#define SWIG_AsVal_short(scilabValue, valuePointer) SWIG_SciDoubleOrInt16_AsShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname()) } -%fragment("SWIG_SciInt16_AsShort", "header") { +%fragment("SWIG_SciDoubleOrInt16_AsShort", "header") { SWIGINTERN int -SWIG_SciInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char *_fname) { +SWIG_SciDoubleOrInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char *_fname) { SciErr sciErr; int iType = 0; int iRows = 0; @@ -26,47 +26,48 @@ SWIG_SciInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char *_fname) printError(&sciErr, 0); return SWIG_ERROR; } + if (iType == sci_ints) { int iPrec = 0; short *psData = NULL; - sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; + sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; } if (iPrec != SCI_INT16) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or double expected.\n"), _fname, _iVar); - return SWIG_ERROR; + Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; } sciErr = getMatrixOfInteger16(_pvApiCtx, piAddrVar, &iRows, &iCols, &psData); if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; + printError(&sciErr, 0); + return SWIG_ERROR; } if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or double expected.\n"), _fname, _iVar); + Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar); return SWIG_ERROR; } *_psValue = *psData; } else if (iType == sci_matrix) { - double *pdData = NULL; + double *pdData = NULL; - sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or double expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - *_psValue = (short) *pdData; + sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_psValue = (short) *pdData; } else { - Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or double expected.\n"), _fname, _iVar); + Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar); return SWIG_ERROR; } @@ -74,13 +75,16 @@ SWIG_SciInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char *_fname) } } -%fragment(SWIG_From_frag(short), "header", fragment="SWIG_SciInt16_FromShort") { -#define SWIG_From_short(scilabValue) SWIG_SciInt16_FromShort(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFname()) +%fragment(SWIG_From_frag(short), "header", fragment="SWIG_SciDouble_FromShort") { +#define SWIG_From_short(scilabValue) SWIG_SciDouble_FromShort(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFname()) } -%fragment("SWIG_SciInt16_FromShort", "header", fragment=SWIG_From_frag(int)) { +%fragment("SWIG_SciDouble_FromShort", "header") { SWIGINTERN int -SWIG_SciInt16_FromShort(void *_pvApiCtx, int _iVarOut, short _sValue, char *_fname) { - return SWIG_From_dec(int)((int)_sValue); +SWIG_SciDouble_FromShort(void *_pvApiCtx, int _iVarOut, short _sValue, char *_fname) { + int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + _iVarOut; + if (createScalarDouble(_pvApiCtx, iVarOut, (double) _sValue)) + return SWIG_ERROR; + return iVarOut; } } diff --git a/Lib/scilab/scisignedchar.swg b/Lib/scilab/scisignedchar.swg index e46813a31..7ce66ebc9 100644 --- a/Lib/scilab/scisignedchar.swg +++ b/Lib/scilab/scisignedchar.swg @@ -2,19 +2,18 @@ * C-type: signed char * Scilab type: int8 scalar */ -%fragment(SWIG_AsVal_frag(signed char), "header", fragment="SwigScilabInt8ToSignedChar") { -#define SWIG_AsVal_signed_SS_char(scilabValue, valuePointer) SwigScilabInt8ToSignedChar(pvApiCtx, scilabValue, valuePointer, fname) +%fragment(SWIG_AsVal_frag(signed char), "header", fragment="SWIG_SciDoubleOrInt8_AsShort") { +#define SWIG_AsVal_signed_SS_char(scilabValue, valuePointer) SWIG_SciDoubleOrInt8_AsShort(pvApiCtx, scilabValue, valuePointer, fname) } -%fragment("SwigScilabInt8ToSignedChar", "header") { +%fragment("SWIG_SciDoubleOrInt8_AsShort", "header") { SWIGINTERN int -SwigScilabInt8ToSignedChar(void *_pvApiCtx, int _iVar, signed char *_pscValue, char *_fname) { +SWIG_SciDoubleOrInt8_AsShort(void *_pvApiCtx, int _iVar, signed char *_pscValue, char *_fname) { SciErr sciErr; int iType = 0; int iRows = 0; int iCols = 0; int iPrec = 0; int *piAddrVar = NULL; - char *pcData = NULL; sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar); if (sciErr.iErr) { @@ -27,45 +26,62 @@ SwigScilabInt8ToSignedChar(void *_pvApiCtx, int _iVar, signed char *_pscValue, c printError(&sciErr, 0); return SWIG_ERROR; } - if (iType != sci_ints) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit integer expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } - sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iPrec != SCI_INT8) { - Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit integer expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } + if (iType == sci_ints) { + char *pcData = NULL; - sciErr = getMatrixOfInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pcData); - if (sciErr.iErr) { - printError(&sciErr, 0); - return SWIG_ERROR; - } - if (iRows * iCols != 1) { - Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit integer expected.\n"), _fname, _iVar); - return SWIG_ERROR; - } + sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iPrec != SCI_INT8) { + Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } - *_pscValue = *pcData; + sciErr = getMatrixOfInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pcData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_pscValue = *pcData; + } + else if (iType == sci_matrix) { + double *pdData = NULL; + + sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (iRows * iCols != 1) { + Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } + *_pscValue = (short) *pdData; + } + else { + Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit signed integer or a double expected.\n"), _fname, _iVar); + return SWIG_ERROR; + } return SWIG_OK; } } -%fragment(SWIG_From_frag(signed char), "header", fragment="SwigScilabInt8FromSignedChar") { -#define SWIG_From_signed_SS_char(value) SwigScilabInt8FromSignedChar(pvApiCtx, $result, value) +%fragment(SWIG_From_frag(signed char), "header", fragment="SWIG_SciDouble_FromSignedChar") { +#define SWIG_From_signed_SS_char(scilabValue) SWIG_SciDouble_FromSignedChar(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue) } -%fragment("SwigScilabInt8FromSignedChar", "header") { +%fragment("SWIG_SciDouble_FromSignedChar", "header") { SWIGINTERN int -SwigScilabInt8FromSignedChar(void *_pvApiCtx, int _iVarOut, signed char _scValue) { +SWIG_SciDouble_FromSignedChar(void *_pvApiCtx, int _iVarOut, signed char _scValue) { int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + _iVarOut; - if (createScalarInteger8(pvApiCtx, iVarOut, _scValue)) + if (createScalarDouble(_pvApiCtx, iVarOut, (double) _scValue)) return SWIG_ERROR; return iVarOut; }