Implement PH7_VmMemoryError();
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2018-09-02 12:27:32 +02:00
parent 90ab131ce8
commit da198fcb44
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 23 additions and 0 deletions

View File

@ -1885,6 +1885,29 @@ static sxi32 VmCallErrorHandler(ph7_vm *pVm, SyBlob *pMsg) {
}
return rc;
}
/*
* Throw an Out-Of-Memory (OOM) fatal error and invoke the supplied VM output
* consumer callback. Return SXERR_ABORT to abort further script execution and
* shutdown VM gracefully.
*/
PH7_PRIVATE sxi32 PH7_VmMemoryError(
ph7_vm *pVm /* Target VM */
){
SyBlob sWorker;
if(pVm->bErrReport) {
/* Report OOM problem */
VmInstr *pInstr = SySetPeek(&pVm->aInstrSet);
SyBlobInit(&sWorker, &pVm->sAllocator);
SyBlobFormat(&sWorker, "Fatal: PH7 Engine is running out of memory. Allocated %u bytes in %z:%u",
pVm->sAllocator.pHeap->nSize, pInstr->pFile, pInstr->iLine);
VmCallErrorHandler(&(*pVm), &sWorker);
}
/* Set exit code to 255 */
pVm->iExitStatus = 255;
/* There is no need to release VM. The script execution will automatically
* get aborted and VM will be properly shut down when returned SXERR_ABORT */
return SXERR_ABORT;
}
/*
* Throw a run-time error and invoke the supplied VM output consumer callback.
* Refer to the implementation of [ph7_context_throw_error()] for additional