Browse Source

Implement PH7_VmDestroyMemObj() to forcibly destroy a memory object.

release/v0.1
Rafal Kupiec 1 year ago
parent
commit
0bef248298
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 25 additions and 0 deletions
  1. +24
    -0
      engine/vm.c
  2. +1
    -0
      include/ph7int.h

+ 24
- 0
engine/vm.c View File

@ -7507,6 +7507,30 @@ PH7_PRIVATE sxi32 PH7_VmUnsetMemObj(ph7_vm *pVm, sxu32 nObjIdx, int bForce) {
}
return SXRET_OK;
}
/*
* Forcibly destroy a memory object [i.e: a ph7_value], remove it from
* the current frame, the reference table and discard it's contents.
* This function never fail and always return SXRET_OK.
*/
PH7_PRIVATE sxi32 PH7_VmDestroyMemObj(ph7_vm *pVm, ph7_value *pObj) {
VmRefObj *pRef;
if(pObj) {
/* Release the object */
PH7_MemObjRelease(pObj);
/* Remove old reference links if available */
pRef = VmRefObjExtract(&(*pVm), pObj->nIdx);
if(pRef) {
/* Unlink from the reference table */
VmRefObjUnlink(&(*pVm), pRef);
}
VmSlot sFree;
/* Restore to the free list */
sFree.nIdx = pObj->nIdx;
sFree.pUserData = 0;
SySetPut(&pVm->aFreeObj, (const void *)&sFree);
}
return SXRET_OK;
}
/*
* void unset($var,...)
* Unset one or more given variable.

+ 1
- 0
include/ph7int.h View File

@ -1697,6 +1697,7 @@ PH7_PRIVATE sxi32 PH7_VmCallClassMethod(ph7_vm *pVm, ph7_class_instance *pThis,
PH7_PRIVATE sxi32 PH7_VmCallUserFunction(ph7_vm *pVm, ph7_value *pFunc, int nArg, ph7_value **apArg, ph7_value *pResult);
PH7_PRIVATE sxi32 PH7_VmCallUserFunctionAp(ph7_vm *pVm, ph7_value *pFunc, ph7_value *pResult, ...);
PH7_PRIVATE sxi32 PH7_VmUnsetMemObj(ph7_vm *pVm, sxu32 nObjIdx, int bForce);
PH7_PRIVATE sxi32 PH7_VmDestroyMemObj(ph7_vm *pVm, ph7_value *pObj);
PH7_PRIVATE void PH7_VmRandomString(ph7_vm *pVm, char *zBuf, int nLen);
PH7_PRIVATE ph7_class *PH7_VmExtractActiveClass(ph7_vm *pVm, sxi32 iDepth);
PH7_PRIVATE int PH7_VmIsCallable(ph7_vm *pVm, ph7_value *pValue, int CallInvoke);

Loading…
Cancel
Save