diff --git a/CHANGES.current b/CHANGES.current index 1db9cbca1..5f0daee0b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2018-01-30: smarchetto + [Scilab] add type name argument in SWIG_ptr() function to cast from pointer adress to typed pointers + 2018-01-16: wsfulton Expressions following a preprocessor directive must now be separated by whitespace or non-numeric characters. This syntax change makes the SWIG preprocessor work like @@ -71,7 +74,7 @@ Version 4.0.0 (in progress) should make the generated code work with PHP 7.2.0. 2017-12-04: wsfulton - [Python] Add missing checks for failures in calls to PyUnicode_AsUTF8String. Previously a + [Python] Add missing checks for failures in calls to PyUnicode_AsUTF8String. Previously a seg fault could occur when passing invalid UTF8 strings (low surrogates), eg passing u"\udcff" to the C layer (Python 3). @@ -150,7 +153,7 @@ Version 4.0.0 (in progress) language as the C++ template name, for example, this is now possible: template struct X { ... }; - %template(X) X; + %template(X) X; 2017-09-23: wsfulton Issue #1098. Fix overloading of shared_ptr with underlying pointer types, eg: diff --git a/Lib/scilab/scirun.swg b/Lib/scilab/scirun.swg index 29f8096ef..a9e9d6351 100644 --- a/Lib/scilab/scirun.swg +++ b/Lib/scilab/scirun.swg @@ -446,36 +446,77 @@ int SWIG_this(SWIG_GatewayParameters) { extern "C" #endif int SWIG_ptr(SWIG_GatewayParameters) { - void *ptrValue = NULL; - double dValue = 0; - if (SwigScilabPtrToObject(pvApiCtx, 1, &ptrValue, NULL, 0, fname) == SWIG_OK) { - SWIG_Scilab_SetOutputPosition(1); - return SWIG_Scilab_SetOutput(pvApiCtx, - SwigScilabPtrFromObject(pvApiCtx, 1, ptrValue, NULL, 0, NULL)); - } - else { - int *piAddr; - SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); - if(sciErr.iErr) { + if (SWIG_NbInputArgument(pvApiCtx) > 0) { + int *piAddrVar1 = NULL; + int iTypeVar1 = 0; + char *pstInputPtrTypeName = NULL; + char *pstOutputMListTypeName = NULL; + if (SWIG_NbInputArgument(pvApiCtx) > 2) { + int *piAddrVar2 = NULL; + int *piAddrVar3 = NULL; + SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrVar2); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (getAllocatedSingleString(pvApiCtx, piAddrVar2, &pstInputPtrTypeName)) { + return SWIG_ERROR; + } + sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrVar3); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + if (getAllocatedSingleString(pvApiCtx, piAddrVar3, &pstOutputMListTypeName)) { + return SWIG_ERROR; + } + } + + SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrVar1); + if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } - if (getScalarDouble(pvApiCtx, piAddr, &dValue) == 0) { - if (dValue != (uintptr_t)dValue) { - Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); - return SWIG_ValueError; + sciErr = getVarType(pvApiCtx, piAddrVar1, &iTypeVar1); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if ((iTypeVar1 == sci_pointer) || (iTypeVar1 == sci_mlist)) { + void *ptrValue = NULL; + if (SwigScilabPtrToObject(pvApiCtx, 1, &ptrValue, SWIG_Scilab_TypeQuery(pstInputPtrTypeName), 0, (char *) "SWIG_ptr") == SWIG_OK) { + SWIG_Scilab_SetOutputPosition(1); + return SWIG_Scilab_SetOutput(pvApiCtx, + SwigScilabPtrFromObject(pvApiCtx, 1, ptrValue, SWIG_Scilab_TypeQuery(pstInputPtrTypeName), 0, pstOutputMListTypeName)); } - if ((dValue < 0) || (dValue > ULONG_MAX)) { - Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); - return SWIG_OverflowError; + } + else if (iTypeVar1 == sci_matrix) { + double dValue = 0; + if (getScalarDouble(pvApiCtx, piAddrVar1, &dValue) == 0) { + if (dValue != (uintptr_t)dValue) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); + return SWIG_ValueError; + } + if ((dValue < 0) || (dValue > ULONG_MAX)) { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1); + return SWIG_OverflowError; + } + SWIG_Scilab_SetOutputPosition(1); + return SWIG_Scilab_SetOutput(pvApiCtx, + SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, SWIG_Scilab_TypeQuery(pstInputPtrTypeName), 0, pstOutputMListTypeName)); + } + else { + return SWIG_TypeError; } - SWIG_Scilab_SetOutputPosition(1); - return SWIG_Scilab_SetOutput(pvApiCtx, - SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0, NULL)); } else { - Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A pointer or a double expected.\n"), "SWIG_ptr", 1); + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A mlist, pointer or a double expected.\n"), (char *) "SWIG_ptr", 1); return SWIG_TypeError; } } + else { + Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: A mlist, pointer, or a double expected.\n"), "SWIG_ptr", 1); + return SWIG_TypeError; + } } diff --git a/Lib/scilab/sciruntime.swg b/Lib/scilab/sciruntime.swg index 9abedfe3d..3de138e11 100644 --- a/Lib/scilab/sciruntime.swg +++ b/Lib/scilab/sciruntime.swg @@ -25,12 +25,14 @@ SWIG_Scilab_SetModule(swig_module_info *swig_module) { SWIGRUNTIME swig_type_info * SWIG_Scilab_TypeQuery(const char *name) { if (SWIG_Module_Initialized()) { - return SWIG_TypeQuery(name); + if (name) { + return SWIG_TypeQuery(name); + } } else { SWIG_Error(SWIG_RuntimeError, "the module is not initialized"); - return NULL; } + return NULL; } %}