Scilab: refactor SwigScilabStringToCharPtrAndSize (use String API getAllocatedString)
This commit is contained in:
parent
1efaa1ae67
commit
347dee5cda
1 changed files with 11 additions and 35 deletions
|
|
@ -123,57 +123,33 @@ SwigScilabStringToCharPtr(void *_pvApiCtx, int _iVar, char *_pcValue, int _iLeng
|
|||
SWIGINTERN int
|
||||
SwigScilabStringToCharPtrAndSize(void *_pvApiCtx, int _iVar, char **_pcValue, size_t *_piLength, int *alloc, char *_fname) {
|
||||
SciErr sciErr;
|
||||
int iRows = 0;
|
||||
int iCols = 0;
|
||||
int iType = 0;
|
||||
int *piAddrVar = NULL;
|
||||
char *_pstStrings = NULL;
|
||||
int piLength = 0;
|
||||
int iRet;
|
||||
char *pstStrings = NULL;
|
||||
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddrVar);
|
||||
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(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), _fname, _iVar);
|
||||
iRet = getAllocatedSingleString(_pvApiCtx, piAddrVar, &pstStrings);
|
||||
if (iRet) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, NULL);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (iRows * iCols != 1) {
|
||||
Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), _fname, _iVar);
|
||||
return SWIG_ERROR;
|
||||
// TODO: return SWIG_ERROR if _pcValue NULL (now returning SWIG_ERROR fails some typechecks)
|
||||
if (_pcValue)
|
||||
{
|
||||
*_pcValue = pstStrings;
|
||||
}
|
||||
|
||||
_pstStrings = (char *)malloc(sizeof(char) * (piLength + 1));
|
||||
sciErr = getMatrixOfString(pvApiCtx, piAddrVar, &iRows, &iCols, &piLength, (char **)&_pstStrings);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if (alloc) {
|
||||
*_pcValue = %new_copy_array(_pstStrings, piLength + 1, char);
|
||||
if (alloc != NULL) {
|
||||
*alloc = SWIG_NEWOBJ;
|
||||
} else if (_pcValue) {
|
||||
*_pcValue = _pstStrings;
|
||||
}
|
||||
|
||||
free(_pstStrings);
|
||||
|
||||
if (_piLength != NULL) {
|
||||
*_piLength = (size_t) piLength;
|
||||
*_piLength = strlen(*_pcValue);
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue