scilab: check value and overflow errors in integer typemaps
This commit is contained in:
parent
e8fd0e506e
commit
ccab675c57
5 changed files with 97 additions and 42 deletions
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* C-type: int
|
||||
* Scilab type: double or 32-bit signed integer
|
||||
* Scilab type: double or int32
|
||||
*/
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int), "header", fragment="SWIG_SciDoubleOrInt32_AsInt") {
|
||||
%fragment(SWIG_AsVal_frag(int), "header", fragment="SWIG_SciDoubleOrInt32_AsInt", fragment="<limits.h>") {
|
||||
%#define SWIG_AsVal_int(scilabValue, valuePointer) SWIG_SciDoubleOrInt32_AsInt(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname())
|
||||
}
|
||||
%fragment("SWIG_SciDoubleOrInt32_AsInt", "header") {
|
||||
|
|
@ -39,9 +39,8 @@ SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &piData);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
|
|
@ -49,12 +48,13 @@ SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_piValue = *piData;
|
||||
}
|
||||
else if (iType == sci_matrix) {
|
||||
double *pdData = NULL;
|
||||
double dValue = 0.0f;
|
||||
|
||||
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
|
||||
if (sciErr.iErr) {
|
||||
|
|
@ -63,13 +63,22 @@ SWIG_SciDoubleOrInt32_AsInt(void *_pvApiCtx, SwigSciObject _iVar, int *_piValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_piValue = (int) *pdData;
|
||||
dValue = *pdData;
|
||||
if (dValue != floor(dValue)) {
|
||||
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_ValueError;
|
||||
}
|
||||
if ((dValue < INT_MIN) || (dValue > INT_MAX)) {
|
||||
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
*_piValue = (int) dValue;
|
||||
}
|
||||
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_TypeError;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* Scilab type: double or int32
|
||||
*/
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_SciDoubleOrInt32_AsLong") {
|
||||
%fragment(SWIG_AsVal_frag(long), "header", fragment="SWIG_SciDoubleOrInt32_AsLong", fragment="<limits.h>") {
|
||||
%#define SWIG_AsVal_long(scilabValue, valuePointer) SWIG_SciDoubleOrInt32_AsLong(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname());
|
||||
}
|
||||
%fragment("SWIG_SciDoubleOrInt32_AsLong", "header") {
|
||||
|
|
@ -38,9 +38,8 @@ SWIG_SciDoubleOrInt32_AsLong(void *_pvApiCtx, SwigSciObject _iVar, long *_plValu
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &piData);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
|
|
@ -48,12 +47,13 @@ SWIG_SciDoubleOrInt32_AsLong(void *_pvApiCtx, SwigSciObject _iVar, long *_plValu
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_plValue = (long) *piData;
|
||||
}
|
||||
else if (iType == sci_matrix) {
|
||||
double *pdData = NULL;
|
||||
double dValue = 0.0f;
|
||||
|
||||
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
|
||||
if (sciErr.iErr) {
|
||||
|
|
@ -62,13 +62,22 @@ SWIG_SciDoubleOrInt32_AsLong(void *_pvApiCtx, SwigSciObject _iVar, long *_plValu
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_plValue = (long) *pdData;
|
||||
dValue = *pdData;
|
||||
if (dValue != floor(dValue)) {
|
||||
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_ValueError;
|
||||
}
|
||||
if ((dValue < LONG_MIN) || (dValue > LONG_MAX)) {
|
||||
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
*_plValue = (long) dValue;
|
||||
}
|
||||
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_TypeError;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* Scilab type: double or int16
|
||||
*/
|
||||
|
||||
%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciDoubleOrInt16_AsShort") {
|
||||
%fragment(SWIG_AsVal_frag(short), "header", fragment="SWIG_SciDoubleOrInt16_AsShort", fragment="<limits.h>") {
|
||||
#define SWIG_AsVal_short(scilabValue, valuePointer) SWIG_SciDoubleOrInt16_AsShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname())
|
||||
}
|
||||
%fragment("SWIG_SciDoubleOrInt16_AsShort", "header") {
|
||||
|
|
@ -38,22 +38,22 @@ SWIG_SciDoubleOrInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char
|
|||
}
|
||||
if (iPrec != SCI_INT16) {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar);
|
||||
return SWIG_ERROR;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
sciErr = getMatrixOfInteger16(_pvApiCtx, piAddrVar, &iRows, &iCols, &psData);
|
||||
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;
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar);
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_psValue = *psData;
|
||||
}
|
||||
else if (iType == sci_matrix) {
|
||||
double *pdData = NULL;
|
||||
double dValue = 0.0f;
|
||||
|
||||
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
|
||||
if (sciErr.iErr) {
|
||||
|
|
@ -62,13 +62,22 @@ SWIG_SciDoubleOrInt16_AsShort(void *_pvApiCtx, int _iVar, short *_psValue, char
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_psValue = (short) *pdData;
|
||||
dValue = *pdData;
|
||||
if (dValue != floor(dValue)) {
|
||||
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 16-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_ValueError;
|
||||
}
|
||||
if ((dValue < SHRT_MIN) || (dValue > SHRT_MAX)) {
|
||||
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 16-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
*_psValue = (short) dValue;
|
||||
}
|
||||
else {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit signed integer or a double expected.\n"), _fname, _iVar);
|
||||
return SWIG_ERROR;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* C-type: signed char
|
||||
* Scilab type: int8 scalar
|
||||
* Scilab type: int8
|
||||
*/
|
||||
%fragment(SWIG_AsVal_frag(signed char), "header", fragment="SWIG_SciDoubleOrInt8_AsShort") {
|
||||
%fragment(SWIG_AsVal_frag(signed char), "header", fragment="SWIG_SciDoubleOrInt8_AsShort", fragment="<limits.h>") {
|
||||
#define SWIG_AsVal_signed_SS_char(scilabValue, valuePointer) SWIG_SciDoubleOrInt8_AsShort(pvApiCtx, scilabValue, valuePointer, fname)
|
||||
}
|
||||
%fragment("SWIG_SciDoubleOrInt8_AsShort", "header") {
|
||||
|
|
@ -37,9 +37,8 @@ SWIG_SciDoubleOrInt8_AsShort(void *_pvApiCtx, int _iVar, signed char *_pscValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
sciErr = getMatrixOfInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pcData);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
|
|
@ -47,12 +46,13 @@ SWIG_SciDoubleOrInt8_AsShort(void *_pvApiCtx, int _iVar, signed char *_pscValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_pscValue = *pcData;
|
||||
}
|
||||
else if (iType == sci_matrix) {
|
||||
double *pdData = NULL;
|
||||
double dValue = 0.0f;
|
||||
|
||||
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, &iRows, &iCols, &pdData);
|
||||
if (sciErr.iErr) {
|
||||
|
|
@ -61,13 +61,22 @@ SWIG_SciDoubleOrInt8_AsShort(void *_pvApiCtx, int _iVar, signed char *_pscValue,
|
|||
}
|
||||
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;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
*_pscValue = (short) *pdData;
|
||||
dValue = *pdData;
|
||||
if (dValue != floor(dValue)) {
|
||||
Scierror(999, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a 8-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_ValueError;
|
||||
}
|
||||
if ((dValue < SCHAR_MIN) || (dValue > SCHAR_MAX)) {
|
||||
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 8-bit signed integer.\n"), _fname, _iVar);
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
*_pscValue = (signed char) dValue;
|
||||
}
|
||||
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_TypeError;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue