scilab: unsigned ints typemaps behave same as signed ints (1st commit: scalar)

This commit is contained in:
Simon Marchetto 2014-06-16 12:03:49 +02:00
commit 72c6552c2d
5 changed files with 175 additions and 91 deletions

View file

@ -1,8 +1,8 @@
/*
* C-type: unsigned char
* Scilab type: uint8 scalar
* Scilab type: double or uint8 scalar
*/
%fragment(SWIG_AsVal_frag(unsigned char), "header", fragment="SWIG_SciUint8_AsUnsignedChar") {
%fragment(SWIG_AsVal_frag(unsigned char), "header", fragment="SWIG_SciUint8_AsUnsignedChar", fragment="<limits.h>") {
#define SWIG_AsVal_unsigned_SS_char(scilabValue, valuePointer) SWIG_SciUint8_AsUnsignedChar(pvApiCtx, scilabValue, valuePointer, fname)
}
%fragment("SWIG_SciUint8_AsUnsignedChar", "header") {
@ -27,32 +27,60 @@ SWIG_SciUint8_AsUnsignedChar(void *_pvApiCtx, int _iVar, unsigned char *_pucValu
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned 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_UINT8) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_ints) {
if (_pucValue) {
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT8) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pucData);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, &iRows, &iCols, &pucData);
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 unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_pucValue = *pucData;
}
}
else if (iType == sci_matrix) {
if (_pucValue) {
double *pdData = NULL;
double dValue = 0.0f;
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 unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_TypeError;
}
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 unsigned integer.\n"), _fname, _iVar);
return SWIG_ValueError;
}
if ((dValue < 0) || (dValue > UCHAR_MAX)) {
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 8-bit unsigned integer.\n"), _fname, _iVar);
return SWIG_OverflowError;
}
*_pucValue = (unsigned char) dValue;
}
}
else {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 8-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_pucValue = *pucData;
return SWIG_OK;
}
@ -64,8 +92,8 @@ SWIG_SciUint8_AsUnsignedChar(void *_pvApiCtx, int _iVar, unsigned char *_pucValu
%fragment("SWIG_SciUint8_FromUnsignedChar", "header") {
SWIGINTERN int
SWIG_SciUint8_FromUnsignedChar(void *_pvApiCtx, int _iVarOut, unsigned char _ucValue) {
if (createScalarUnsignedInteger8(pvApiCtx,
SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _ucValue))
if (createScalarDouble(pvApiCtx,
SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, (double) _ucValue))
return SWIG_ERROR;
return SWIG_OK;
}

View file

@ -1,8 +1,8 @@
/*
* C-type: unsigned int
* Scilab type: uint32 scalar
* Scilab type: double or uint32 scalar
*/
%fragment(SWIG_AsVal_frag(unsigned int), "header", fragment="SWIG_SciUint32_AsUnsignedInt") {
%fragment(SWIG_AsVal_frag(unsigned int), "header", fragment="SWIG_SciUint32_AsUnsignedInt", fragment="<limits.h>") {
%#define SWIG_AsVal_unsigned_SS_int(scilabValue, valuePointer) SWIG_SciUint32_AsUnsignedInt(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname())
}
%fragment("SWIG_SciUint32_AsUnsignedInt", "header") {
@ -27,32 +27,60 @@ SWIG_SciUint32_AsUnsignedInt(void *_pvApiCtx, int _iVar, unsigned int *_puiValue
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned 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_UINT32) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_ints) {
if (_puiValue) {
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT32) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &puiData);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfUnsignedInteger32(_pvApiCtx, piAddrVar, &iRows, &iCols, &puiData);
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 unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_puiValue = *puiData;
}
}
else if (iType == sci_matrix) {
if (_puiValue) {
double *pdData = NULL;
double dValue = 0.0f;
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 unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_TypeError;
}
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 unsigned integer.\n"), _fname, _iVar);
return SWIG_ValueError;
}
if ((dValue < 0) || (dValue > UINT_MAX)) {
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 32-bit unsigned integer.\n"), _fname, _iVar);
return SWIG_OverflowError;
}
*_puiValue = (unsigned int) dValue;
}
}
else {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_puiValue = *puiData;
return SWIG_OK;
}
@ -64,8 +92,8 @@ SWIG_SciUint32_AsUnsignedInt(void *_pvApiCtx, int _iVar, unsigned int *_puiValue
%fragment("SWIG_SciUint32_FromUnsignedInt", "header") {
SWIGINTERN int
SWIG_SciUint32_FromUnsignedInt(void *_pvApiCtx, int _iVarOut, unsigned int _uiValue, char *_fname) {
if (createScalarUnsignedInteger32(_pvApiCtx,
SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _uiValue))
if (createScalarDouble(_pvApiCtx,
SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, (double) _uiValue))
return SWIG_ERROR;
return SWIG_OK;
}

View file

@ -1,8 +1,8 @@
/*
* C-type: unsigned short
* Scilab type: uint16 scalar
* Scilab type: double or uint16 scalar
*/
%fragment(SWIG_AsVal_frag(unsigned short), "header", fragment="SWIG_SciUint16_AsUnsignedShort") {
%fragment(SWIG_AsVal_frag(unsigned short), "header", fragment="SWIG_SciUint16_AsUnsignedShort", fragment="<limits.h>") {
%#define SWIG_AsVal_unsigned_SS_short(scilabValue, valuePointer) SWIG_SciUint16_AsUnsignedShort(pvApiCtx, scilabValue, valuePointer, SWIG_Scilab_GetFname())
}
%fragment("SWIG_SciUint16_AsUnsignedShort", "header") {
@ -27,32 +27,60 @@ SWIG_SciUint16_AsUnsignedShort(void *_pvApiCtx, int _iVar, unsigned short *_pusV
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned 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_UINT16) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_ints) {
if (_pusValue) {
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iPrec != SCI_UINT16) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, &iRows, &iCols, &pusData);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, &iRows, &iCols, &pusData);
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 unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_pusValue = *pusData;
}
}
else if (iType == sci_matrix) {
if (_pusValue) {
double *pdData = NULL;
double dValue = 0.0f;
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 unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_TypeError;
}
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 unsigned integer.\n"), _fname, _iVar);
return SWIG_ValueError;
}
if ((dValue < 0) || (dValue > USHRT_MAX)) {
Scierror(999, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a 16-bit unsigned integer.\n"), _fname, _iVar);
return SWIG_OverflowError;
}
*_pusValue = (unsigned short) dValue;
}
}
else {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit unsigned integer expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_pusValue = *pusData;
return SWIG_OK;
}
@ -65,7 +93,7 @@ SWIG_SciUint16_AsUnsignedShort(void *_pvApiCtx, int _iVar, unsigned short *_pusV
SWIGINTERN int
SWIG_SciUint16_FromUnsignedShort(void *_pvApiCtx, int _iVarOut, unsigned short _usValue, char *_fname) {
int iVarOut = SWIG_NbInputArgument(_pvApiCtx) + _iVarOut;
if (createScalarUnsignedInteger16(_pvApiCtx, iVarOut, _usValue))
if (createScalarDouble(_pvApiCtx, iVarOut, (double) _usValue))
return SWIG_ERROR;
return SWIG_OK;
}