Skip to content

Commit 078ad6c

Browse files
author
Simon Marchetto
committed
simplify SWIG_SciString_AsChar()
1 parent b05f005 commit 078ad6c

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

Lib/scilab/scichar.swg

+12-23
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,32 @@
1414
SWIGINTERN int
1515
SWIG_SciString_AsChar(void *pvApiCtx, int iVar, char *pcValue, char *fname) {
1616
SciErr sciErr;
17-
int iType = 0;
18-
int iRows = 0;
19-
int iCols = 0;
2017
int *piAddrVar = NULL;
21-
char *pstStrings = NULL;
22-
int piLength = 0;
18+
char *pstValue = NULL;
19+
int iRet;
2320

2421
sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
2522
if (sciErr.iErr) {
2623
printError(&sciErr, 0);
2724
return SWIG_ERROR;
2825
}
2926

30-
sciErr = getVarType(pvApiCtx, piAddrVar, &iType);
31-
if (sciErr.iErr) {
32-
printError(&sciErr, 0);
33-
return SWIG_ERROR;
34-
}
35-
if (iType != sci_strings) {
36-
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, iVar);
37-
return SWIG_ERROR;
27+
if (isStringType(pvApiCtx, piAddrVar) == 0)
28+
{
29+
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A single string expected.\n"), fname, iVar);
30+
return SWIG_TypeError;
3831
}
3932

40-
pstStrings = (char *)malloc(sizeof(char));
41-
sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&pstStrings);
42-
if (sciErr.iErr) {
43-
printError(&sciErr, 0);
44-
return SWIG_ERROR;
45-
}
46-
if (iRows * iCols != 1) {
47-
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, iVar);
33+
iRet = getAllocatedSingleString(pvApiCtx, piAddrVar, &pstValue);
34+
if (iRet) {
4835
return SWIG_ERROR;
4936
}
50-
*pcValue = pstStrings[0];
5137

52-
free(pstStrings);
38+
if (pcValue != NULL) {
39+
*pcValue = pstValue[0];
40+
}
5341

42+
freeAllocatedSingleString(pstValue);
5443
return SWIG_OK;
5544
}
5645
}

0 commit comments

Comments
 (0)