Define include completion as void and reject file-open failures
Build / AerScript (push) Successful in 37s

This commit is contained in:
2026-10-29 22:44:18 +01:00
parent 54fd0cf7a6
commit 3c194e3fa6
2 changed files with 83 additions and 39 deletions
+34 -9
View File
@@ -5093,8 +5093,9 @@ Resume:
}
/*
* OP_INCLUDE P1 P2 P3
* Include another source file. If P1 is zero, 'include' statement was used, otherwise it was 'require'.
* Include another source file. If P1 is zero, 'include' was used, otherwise it was 'require'.
* P3 contains a path, or lexical include metadata when P2 is set.
* P2 == 2 consumes a string path operand and produces VOID on completion.
*/
case PH7_OP_INCLUDE:
{
@@ -5103,15 +5104,41 @@ Resume:
ph7_value sIncludeResult;
int iFlags = pInstr->iP1 ? PH7_AERSCRIPT_CODE : PH7_AERSCRIPT_CHNK;
SyString sFile;
if(SyStrlen(zFile) < 1) {
if(pInstr->iP2 == 2) {
if((pTos->nType & (MEMOBJ_STRING | MEMOBJ_HASHMAP)) != MEMOBJ_STRING) {
PH7_VmThrowError(pVm, PH7_CTX_ERR, "include expects one string argument");
}
/* Stream devices take a terminated path; retain its operand until
* execution and diagnostics no longer borrow these bytes. */
zFile = (char *)ph7_value_to_string(pTos, 0);
SyStringInitFromBuf(&sFile, zFile, SyBlobLength(&pTos->sBlob));
} else {
SyStringInitFromBuf(&sFile, zFile, SyStrlen(zFile));
}
if(pInstr->iP1 && sFile.nByte < 1) {
break;
}
SyStringInitFromBuf(&sFile, zFile, SyStrlen(zFile));
PH7_MemObjInit(pVm, &sIncludeResult);
rc = VmExecIncludedFile(&(*pVm), &sFile, iFlags | PH7_AERSCRIPT_FILE, &sIncludeResult, pInclude);
if(rc != SXRET_OK && rc != SXERR_EXISTS && rc != VM_INCLUDE_JUMP &&
(pInstr->iP1 || (rc != VM_INCLUDE_RETURN && rc != VM_RETURN_VOID)) &&
rc != VM_INCLUDE_EXCEPTION && rc != PH7_EXCEPTION &&
(pInstr->iP1 || rc != PH7_ABORT)) {
PH7_VmThrowError(pVm, PH7_CTX_ERR, "IO error while including file: '%z'", &sFile);
}
if(pInstr->iP2 == 2) {
PH7_MemObjRelease(pTos);
pTos--;
}
if(rc == VM_INCLUDE_JUMP) {
nTarget = (sxi32)sIncludeResult.x.iVal;
PH7_MemObjRelease(&sIncludeResult);
/* The transfer abandons this chunk's expression even when its
* target stays inside the same try. Restore its entry checkpoint;
* enclosing evaluations retain their own operand stacks. */
if(pTos - pStack > nTos) {
VmPopOperand(&pTos, (sxi32)(pTos - pStack) - nTos);
}
iTransfer = VM_TRANSFER_JUMP;
bExternalJump = FALSE;
goto Unwind;
@@ -5131,15 +5158,13 @@ Resume:
goto Unwind;
}
PH7_MemObjRelease(&sIncludeResult);
if(!pInstr->iP1 && rc == SXERR_NOTFOUND) {
PH7_VmThrowError(pVm, PH7_CTX_WARNING, "IO error while including file: '%z'", &sFile);
break;
}
if(!pInstr->iP1 && rc == PH7_ABORT) {
goto Abort;
}
if(rc != SXRET_OK && rc != SXERR_EXISTS) {
PH7_VmThrowError(pVm, PH7_CTX_ERR, "IO error while including file: '%z'", &sFile);
if(pInstr->iP2 == 2) {
++pTos;
MemObjSetType(pTos, MEMOBJ_VOID);
pTos->nIdx = SXU32_HIGH;
}
break;
}