Skip to content

Commit

Permalink
simplify SWIG_SciString_AsChar()
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Marchetto committed Jun 23, 2015
1 parent b05f005 commit 078ad6c
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions Lib/scilab/scichar.swg
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,32 @@
SWIGINTERN int
SWIG_SciString_AsChar(void *pvApiCtx, int iVar, char *pcValue, char *fname) {
SciErr sciErr;
int iType = 0;
int iRows = 0;
int iCols = 0;
int *piAddrVar = NULL;
char *pstStrings = NULL;
int piLength = 0;
char *pstValue = NULL;
int iRet;

sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
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_strings) {
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, iVar);
return SWIG_ERROR;
if (isStringType(pvApiCtx, piAddrVar) == 0)
{
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A single string expected.\n"), fname, iVar);
return SWIG_TypeError;
}

pstStrings = (char *)malloc(sizeof(char));
sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&pstStrings);
if (sciErr.iErr) {
printError(&sciErr, 0);
return SWIG_ERROR;
}
if (iRows * iCols != 1) {
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, iVar);
iRet = getAllocatedSingleString(pvApiCtx, piAddrVar, &pstValue);
if (iRet) {
return SWIG_ERROR;
}
*pcValue = pstStrings[0];

free(pstStrings);
if (pcValue != NULL) {
*pcValue = pstValue[0];
}

freeAllocatedSingleString(pstValue);
return SWIG_OK;
}
}
Expand Down

0 comments on commit 078ad6c

Please sign in to comment.