add type name argument in SWIG_ptr() function to cast from pointer adress to typed pointers

This commit is contained in:
Simon Marchetto 2018-01-30 16:34:31 +01:00
commit 862501480e
3 changed files with 72 additions and 26 deletions

View file

@ -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) 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 2018-01-16: wsfulton
Expressions following a preprocessor directive must now be separated by whitespace Expressions following a preprocessor directive must now be separated by whitespace
or non-numeric characters. This syntax change makes the SWIG preprocessor work like or non-numeric characters. This syntax change makes the SWIG preprocessor work like

View file

@ -446,21 +446,54 @@ int SWIG_this(SWIG_GatewayParameters) {
extern "C" extern "C"
#endif #endif
int SWIG_ptr(SWIG_GatewayParameters) { int SWIG_ptr(SWIG_GatewayParameters) {
void *ptrValue = NULL; if (SWIG_NbInputArgument(pvApiCtx) > 0) {
double dValue = 0; int *piAddrVar1 = NULL;
if (SwigScilabPtrToObject(pvApiCtx, 1, &ptrValue, NULL, 0, fname) == SWIG_OK) { int iTypeVar1 = 0;
SWIG_Scilab_SetOutputPosition(1); char *pstInputPtrTypeName = NULL;
return SWIG_Scilab_SetOutput(pvApiCtx, char *pstOutputMListTypeName = NULL;
SwigScilabPtrFromObject(pvApiCtx, 1, ptrValue, NULL, 0, NULL)); if (SWIG_NbInputArgument(pvApiCtx) > 2) {
} int *piAddrVar2 = NULL;
else { int *piAddrVar3 = NULL;
int *piAddr; SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrVar2);
SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) {
if(sciErr.iErr) {
printError(&sciErr, 0); printError(&sciErr, 0);
return SWIG_ERROR; return SWIG_ERROR;
} }
if (getScalarDouble(pvApiCtx, piAddr, &dValue) == 0) { 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;
}
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));
}
}
else if (iTypeVar1 == sci_matrix) {
double dValue = 0;
if (getScalarDouble(pvApiCtx, piAddrVar1, &dValue) == 0) {
if (dValue != (uintptr_t)dValue) { 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); 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; return SWIG_ValueError;
@ -471,11 +504,19 @@ int SWIG_ptr(SWIG_GatewayParameters) {
} }
SWIG_Scilab_SetOutputPosition(1); SWIG_Scilab_SetOutputPosition(1);
return SWIG_Scilab_SetOutput(pvApiCtx, return SWIG_Scilab_SetOutput(pvApiCtx,
SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0, NULL)); SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, SWIG_Scilab_TypeQuery(pstInputPtrTypeName), 0, pstOutputMListTypeName));
} }
else { else {
Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A pointer or a double expected.\n"), "SWIG_ptr", 1);
return SWIG_TypeError; return SWIG_TypeError;
} }
} }
else {
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;
}
} }

View file

@ -25,12 +25,14 @@ SWIG_Scilab_SetModule(swig_module_info *swig_module) {
SWIGRUNTIME swig_type_info * SWIGRUNTIME swig_type_info *
SWIG_Scilab_TypeQuery(const char *name) { SWIG_Scilab_TypeQuery(const char *name) {
if (SWIG_Module_Initialized()) { if (SWIG_Module_Initialized()) {
if (name) {
return SWIG_TypeQuery(name); return SWIG_TypeQuery(name);
} }
}
else { else {
SWIG_Error(SWIG_RuntimeError, "the module is not initialized"); SWIG_Error(SWIG_RuntimeError, "the module is not initialized");
return NULL;
} }
return NULL;
} }
%} %}