Abort VM Execution and Release all resource acquired by the unqlite_context and frames when exception thrown by embedded functions
I embedded unqlite into my c# application, and from my c# call back function, an exception can be thrown that only c# can catch it. so on any exception thrown by my c# callback function I need away to free all acquired resources by the unqlite_context.
I managed to do so by providing a global callback that gives me the context and stack frame and top stack frame and arguments, I modified VmByteCodeExec and added calls to global callback :
xAbortFuncDelegate lxAbortFunc = xAbortFunc;
\\make c# have mapping from ctx->{aArgs,pStack,pTop} to be used to free resources
if (lxAbortFunc) lxAbortFunc(&sCtx, &aArg, pTos, pStack,\*before*\1);
\\the original line that calls the embedded c functions registered from c#
rc = pFunc->xFunc(&sCtx, (int)SySetUsed(&aArg), (jx9_value **)SySetBasePtr(&aArg));
\\to make c# free mapping info from ctx->{aArgs,pStack,pTop} after releasing the resource acquired by the unqlite_context execution
if (lxAbortFunc) lxAbortFunc(&sCtx, &aArg, pTos, pStack, \*after*\0);
and from my callback function if an exception is thrown, I call a c function that free all resources then re-throw the exception :
VmReleaseCallContext(sCtx);
SySetRelease(aArg);
while (pTos >= pStack) {
jx9MemObjRelease(pTos);
pTos--;
}
so what I need is a built in way to do the task.