scilab: unsigned ints typemaps behave same as ints (2nd commit: arrays)

This commit is contained in:
Simon Marchetto 2014-06-16 16:25:49 +02:00
commit 8a2472c649
6 changed files with 203 additions and 108 deletions

View file

@ -2,53 +2,43 @@ exec("swigtest.start", -1);
// bool
a = [%T %F %F %T %F %T %T %T];
if arr_bool(a, 8) <> 5 then swigtesterror(); end
if typeof(arr_bool(a, 8)) <> "constant" then swigtesterror(); end
checkequal(arr_bool(a, 8), 5, "arr_bool");
// char
a = ["charptr"]
if arr_char(a, 7) <> 756 then swigtesterror(); end
if typeof(arr_char(a, 7)) <> "constant" then swigtesterror(); end
checkequal(arr_char(a, 7), 756, "arr_char");
// signed char
a = int8([1, 2, 3, 4]);
if arr_schar(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_schar(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_schar(a, 4), 10, "arr_schar");
// unsigned char
a = uint8([1, 2, 3, 4]);
if arr_uchar(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_uchar(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_uchar(a, 4), 10, "arr_uchar");
// short
a = int16([1, 2, 3, 4]);
if arr_short(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_short(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_short(a, 4), 10, "arr_short");
// unsigned short
a = uint16([1, 2, 3, 4]);
if arr_ushort(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_ushort(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_ushort(a, 4), 10, "arr_ushort");
// int
a = int32([1, 2, 3, 4]);
if arr_int(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_int(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_int(a, 4), 10, "arr_int");
// unsigned int
a = uint32([1, 2, 3, 4]);
if arr_uint(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_uint(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_uint(a, 4), 10, "");
// long
a = [1, 2, 3, 4];
if arr_long(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_long(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_long(a, 4), 10, "arr_long");
// unsigned long
a = [1, 2, 3, 4];
if arr_ulong(uint32(a), 4) <> 10 then swigtesterror(); end
if typeof(arr_ulong(uint32(a), 4)) <> "constant" then swigtesterror(); end
checkequal(arr_ulong(uint32(a), 4), 10, "arr_ulong");
// long long
// No equivalent in Scilab 5
@ -58,12 +48,10 @@ if typeof(arr_ulong(uint32(a), 4)) <> "constant" then swigtesterror(); end
// float
a = [1, 2, 3, 4];
if arr_float(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_float(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_float(a, 4), 10, "arr_float");
// double
a = [1, 2, 3, 4];
if arr_double(a, 4) <> 10 then swigtesterror(); end
if typeof(arr_double(a, 4)) <> "constant" then swigtesterror(); end
checkequal(arr_double(a, 4), 10, "arr_double");
exec("swigtest.quit", -1);

View file

@ -19,37 +19,36 @@ um = [10, 20];
testArray("array_c", array_c_set, array_c_get, ['ab'], ['ab']);
testArray("array_sc", array_sc_set, array_sc_get, m, m);
testArray("array_sc", array_sc_set, array_sc_get, int8(m), m);
testArray("array_uc", array_uc_set, array_uc_get, uint8(um), uint8(um));
testArray("array_uc", array_uc_set, array_uc_get, uint8(um), um);
testArray("array_s", array_s_set, array_s_get, m, m);
testArray("array_s", array_s_set, array_s_get, int16(m), m);
testArray("array_us", array_us_set, array_us_get, uint16(um), uint16(um));
testArray("array_us", array_us_set, array_us_get, uint16(um), um);
testArray("array_i", array_i_set, array_i_get, m, m);
testArray("array_i", array_i_set, array_i_get, int32(m), m);
testArray("array_ui", array_ui_set, array_ui_get, uint32(um), uint32(um));
testArray("array_ui", array_ui_set, array_ui_get, uint32(um), um);
testArray("array_l", array_l_set, array_l_get, m, m);
testArray("array_l", array_l_set, array_l_get, int32(m), m);
testArray("array_ul", array_ul_set, array_ul_get, uint32(um), uint32(um));
testArray("array_ul", array_ul_set, array_ul_get, uint32(um), um);
testArray("array_f", array_f_set, array_f_get, [-2.5, 2.5], [-2.5, 2.5]);
testArray("array_d", array_d_set, array_d_get, [-10.5, 20.4], [-10.5, 20.4]);
if array_const_i_get() <> [10, 20] then swigtesterror(); end
checkequal(array_const_i_get(), [10, 20], "array_const_i_get()");
ierr = execstr('array_i_set([0:10]', 'errcatch');
if ierr == 0 then swigtesterror("Overflow error expected"); end
if BeginString_FIX44a_get() <> "FIX.a.a" then swigtesterror(); end
if BeginString_FIX44b_get() <> "FIX.b.b" then swigtesterror(); end
if BeginString_FIX44c_get() <> "FIX.c.c" then swigtesterror(); end
if BeginString_FIX44d_get() <> "FIX.d.d" then swigtesterror(); end
if BeginString_FIX44d_get() <> "FIX.d.d" then swigtesterror(); end
checkequal(BeginString_FIX44a_get(), "FIX.a.a", "BeginString_FIX44a_get()");
checkequal(BeginString_FIX44b_get(), "FIX.b.b", "BeginString_FIX44b_get()");
checkequal(BeginString_FIX44c_get(), "FIX.c.c", "BeginString_FIX44c_get()");
checkequal(BeginString_FIX44d_get(), "FIX.d.d", "BeginString_FIX44d_get()");
BeginString_FIX44b_set(strcat(["12","\0","45"]));
if BeginString_FIX44b_get() <> "12\045" then swigtesterror(); end
if BeginString_FIX44d_get() <> "FIX.d.d" then swigtesterror(); end
if BeginString_FIX44e_get() <> "FIX.e.e" then swigtesterror(); end
if BeginString_FIX44f_get() <> "FIX.f.f" then swigtesterror(); end
checkequal(BeginString_FIX44b_get(), "12\045", "BeginString_FIX44b_get()");
checkequal(BeginString_FIX44d_get(), "FIX.d.d", "BeginString_FIX44d_get()");
checkequal(BeginString_FIX44e_get(), "FIX.e.e", "BeginString_FIX44e_get()");
checkequal(BeginString_FIX44f_get(), "FIX.f.f", "BeginString_FIX44f_get()");
if test_a("hello","hi","chello","chi") <> "hi" then swigtesterror(); end
checkequal(test_a("hello","hi","chello","chi"), "hi", "test_a()");
checkequal(test_b("1234567","hi"), "1234567", "test_b()");
if test_b("1234567","hi") <> "1234567" then swigtesterror(); end
exit
exec("swigtest.quit", -1);

View file

@ -122,41 +122,77 @@ SWIG_SciUint8_AsUnsignedCharArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer vector 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 vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_matrix)
{
double *pdData = NULL;
int size = 0;
int i;
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, _iRows, _iCols, _pucValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, _iRows, _iCols, &pdData);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
size = (*_iRows) * (*_iCols);
*_pucValue = (unsigned char*) malloc(size * sizeof(int*));
for (i = 0; i < size; i++)
(*_pucValue)[i] = (unsigned char) pdData[i];
}
else if (iType == sci_ints)
{
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 vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger8(_pvApiCtx, piAddrVar, _iRows, _iCols, _pucValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 8-bit unsigned integer or a double vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciUint8_FromUnsignedCharArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint8_FromUnsignedCharArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const unsigned char *_puscValue) {
SWIG_SciUint8_FromUnsignedCharArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const unsigned char *_pucValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
sciErr = createMatrixOfUnsignedInteger8(pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, _puscValue);
if (sciErr.iErr) {
pdValues = (double*) malloc(_iRows * _iCols * sizeof(double));
for (i=0; i<_iRows * _iCols; i++)
pdValues[i] = _pucValues[i];
sciErr = createMatrixOfDouble(pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, pdValues);
if (sciErr.iErr)
{
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}

View file

@ -36,7 +36,7 @@ SWIG_SciUint32_AsUnsignedInt(void *_pvApiCtx, int _iVar, unsigned int *_puiValue
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);
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
@ -46,7 +46,7 @@ SWIG_SciUint32_AsUnsignedInt(void *_pvApiCtx, int _iVar, unsigned int *_puiValue
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);
Scierror(999, _("%s: Wrong size for input argument #%d: A 32-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_puiValue = *puiData;
@ -122,41 +122,76 @@ SWIG_SciUint32_AsUnsignedIntArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRows
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer vector 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 vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_matrix)
{
double *pdData = NULL;
int size = 0;
int i;
sciErr = getMatrixOfUnsignedInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _puiValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, _iRows, _iCols, &pdData);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
size = (*_iRows) * (*_iCols);
*_puiValue = (unsigned int*) malloc(size * sizeof(int*));
for (i = 0; i < size; i++)
(*_puiValue)[i] = (unsigned int) pdData[i];
}
else if (iType == sci_ints)
{
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 or a double vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger32(_pvApiCtx, piAddrVar, _iRows, _iCols, _puiValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 32-bit unsigned integer or a double vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciUint32_FromUnsignedIntArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint32_FromUnsignedIntArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, unsigned int *_puiValue) {
SWIG_SciUint32_FromUnsignedIntArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, unsigned int *_puiValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
sciErr = createMatrixOfUnsignedInteger32(_pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + _iVarOut, _iRows, _iCols, _puiValue);
pdValues = (double*) malloc(_iRows * _iCols * sizeof(double));
for (i=0; i<_iRows * _iCols; i++)
pdValues[i] = _puiValues[i];
sciErr = createMatrixOfDouble(_pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + _iVarOut, _iRows, _iCols, pdValues);
if (sciErr.iErr) {
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}

View file

@ -30,23 +30,24 @@ SWIG_UnsignedInt_FromUnsignedLong(void *_pvApiCtx, int _iVarOut, unsigned long _
%fragment("SWIG_SciUint32_FromUnsignedLongArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint32_FromUnsignedLongArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const unsigned long *_pulData) {
SWIG_SciUint32_FromUnsignedLongArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, const unsigned long *_pulValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
unsigned int *puiValues = NULL;
puiValues = (unsigned int*) malloc(_iRows * _iCols * sizeof(unsigned int));
pdValues = (double*) malloc(_iRows * _iCols * sizeof(double));
for (i=0; i<_iRows * _iCols; i++) {
puiValues[i] = _pulData[i];
pdValues[i] = _pulValues[i];
}
sciErr = createMatrixOfUnsignedInteger32(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, puiValues);
sciErr = createMatrixOfDouble(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, pdValues);
if (sciErr.iErr) {
printError(&sciErr, 0);
free(puiValues);
free(pdValues);
return SWIG_ERROR;
}
free(puiValues);
free(pdValues);
return SWIG_OK;
}
}

View file

@ -36,7 +36,7 @@ SWIG_SciUint16_AsUnsignedShort(void *_pvApiCtx, int _iVar, unsigned short *_pusV
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);
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
@ -46,7 +46,7 @@ SWIG_SciUint16_AsUnsignedShort(void *_pvApiCtx, int _iVar, unsigned short *_pusV
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);
Scierror(999, _("%s: Wrong size for input argument #%d: A 16-bit unsigned integer or a double expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
*_pusValue = *pusData;
@ -122,41 +122,77 @@ SWIG_SciUint16_AsUnsignedShortArrayAndSize(void *_pvApiCtx, int _iVar, int *_iRo
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iType != sci_ints) {
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer vector 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 vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
if (iType == sci_matrix)
{
double *pdData = NULL;
int size = 0;
int i;
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, _iRows, _iCols, _pusValue);
if (sciErr.iErr) {
printError(&sciErr, 0);
sciErr = getMatrixOfDouble(_pvApiCtx, piAddrVar, _iRows, _iCols, &pdData);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
size = (*_iRows) * (*_iCols);
*_pusValue = (unsigned short*) malloc(size * sizeof(int*));
for (i = 0; i < size; i++)
(*_pusValue)[i] = (unsigned short) pdData[i];
}
else if (iType == sci_ints)
{
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 or a double vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
sciErr = getMatrixOfUnsignedInteger16(_pvApiCtx, piAddrVar, _iRows, _iCols, _pusValue);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return SWIG_ERROR;
}
}
else
{
Scierror(999, _("%s: Wrong type for input argument #%d: A 16-bit unsigned integer or a double vector expected.\n"), _fname, _iVar);
return SWIG_ERROR;
}
return SWIG_OK;
}
}
%fragment("SWIG_SciUint16_FromUnsignedShortArrayAndSize", "header") {
SWIGINTERN int
SWIG_SciUint16_FromUnsignedShortArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, unsigned short *_pusValue) {
SWIG_SciUint16_FromUnsignedShortArrayAndSize(void *_pvApiCtx, int _iVarOut, int _iRows, int _iCols, unsigned short *_pusValues) {
SciErr sciErr;
double *pdValues = NULL;
int i;
sciErr = createMatrixOfUnsignedInteger16(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, _pusValue);
if (sciErr.iErr) {
pdValues = (double*) malloc(_iRows * _iCols * sizeof(double));
for (i=0; i<_iRows * _iCols; i++)
pdValues[i] = _pusValues[i];
sciErr = createMatrixOfDouble(_pvApiCtx, SWIG_NbInputArgument(_pvApiCtx) + _iVarOut, _iRows, _iCols, pdValues);
if (sciErr.iErr)
{
printError(&sciErr, 0);
free(pdValues);
return SWIG_ERROR;
}
free(pdValues);
return SWIG_OK;
}
}