|
14 | 14 | SWIGINTERN int
|
15 | 15 | SWIG_SciString_AsChar(void *pvApiCtx, int iVar, char *pcValue, char *fname) {
|
16 | 16 | SciErr sciErr;
|
17 |
| - int iType = 0; |
18 |
| - int iRows = 0; |
19 |
| - int iCols = 0; |
20 | 17 | int *piAddrVar = NULL;
|
21 |
| - char *pstStrings = NULL; |
22 |
| - int piLength = 0; |
| 18 | + char *pstValue = NULL; |
| 19 | + int iRet; |
23 | 20 |
|
24 | 21 | sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
|
25 | 22 | if (sciErr.iErr) {
|
26 | 23 | printError(&sciErr, 0);
|
27 | 24 | return SWIG_ERROR;
|
28 | 25 | }
|
29 | 26 |
|
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; |
38 | 31 | }
|
39 | 32 |
|
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) { |
48 | 35 | return SWIG_ERROR;
|
49 | 36 | }
|
50 |
| - *pcValue = pstStrings[0]; |
51 | 37 |
|
52 |
| - free(pstStrings); |
| 38 | + if (pcValue != NULL) { |
| 39 | + *pcValue = pstValue[0]; |
| 40 | + } |
53 | 41 |
|
| 42 | + freeAllocatedSingleString(pstValue); |
54 | 43 | return SWIG_OK;
|
55 | 44 | }
|
56 | 45 | }
|
|
0 commit comments