Fix int matrix typemap (accept empty matrix as input)

This commit is contained in:
Simon Marchetto 2013-06-03 12:31:28 +02:00
commit 2847765ddf

View file

@ -115,8 +115,8 @@ SWIG_From_dec(size_t)(size_t _iValue)
}
}
/*
* C-type: int[ANY]
* Scilab type: int32 vector
* C-type: int
* Scilab type: 32-bit signed integer matrix
*/
%fragment("SWIG_SciInt32_AsIntArrayAndSize", "header") {
SWIGINTERN int
@ -127,37 +127,58 @@ SWIG_SciInt32_AsIntArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows, int *_i
int *piAddrVar = NULL;
sciErr = getVarAddressFromPosition(_pvApiCtx, _iVar, &piAddrVar);
if (sciErr.iErr) {
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
sciErr = getVarType(_pvApiCtx, piAddrVar, &iType);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
// Accepts 32-bit signed integer matrix for input
if (isIntegerType(_pvApiCtx, piAddrVar))
{
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 matrix expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _piValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
else if (isDoubleType(_pvApiCtx, piAddrVar))
{
double **dblValue;
sciErr = getMatrixOfIntegerPrecision(_pvApiCtx, piAddrVar, &iPrec);
if (sciErr.iErr) {
printError(&sciErr, 0);
// Check if input matrix is not empty (empty matrix type is double)
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, _iRows, _iCols, dblValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
if ((*_iRows > 0) || (*_iCols > 0))
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer matrix expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_piValue = (int*) malloc(sizeof(int*));
return SWIG_OK;
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer matrix expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iPrec != SCI_INT32) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit signed integer vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _piValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
return SWIG_OK;
}
}