Better way to check arguments compatibility.
All checks were successful
The build was successful.

This commit is contained in:
Rafal Kupiec 2019-04-05 19:59:15 +02:00
parent 39f698476f
commit a06573408e
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -4911,20 +4911,16 @@ static sxi32 VmByteCodeExec(
} }
} }
} }
} else if((aFormalArg[n].nType & MEMOBJ_MIXED) == 0 && pArg->iFlags != aFormalArg[n].nType) { } else {
if(PH7_CheckVarCompat(pArg, aFormalArg[n].nType) == SXRET_OK) { ph7_value *pTmp = PH7_ReserveMemObj(&(*pVm));
/* Silently typecast compatible value to expected data type */ pTmp->iFlags = aFormalArg[n].nType;
ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType); rc = PH7_MemObjSafeStore(pArg, pTmp);
xCast(pArg); if(rc != SXRET_OK) {
} else if((aFormalArg[n].nType & MEMOBJ_HASHMAP) && (pArg->iFlags & MEMOBJ_HASHMAP)) {
if(PH7_HashmapCast(pArg, aFormalArg[n].nType ^ MEMOBJ_HASHMAP) != SXRET_OK) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName);
}
} else {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName); "Argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName);
} }
pArg->iFlags = pTmp->iFlags;
PH7_MemObjRelease(pTmp);
} }
} }
if(aFormalArg[n].iFlags & VM_FUNC_ARG_BY_REF) { if(aFormalArg[n].iFlags & VM_FUNC_ARG_BY_REF) {