unqlite icon indicating copy to clipboard operation
unqlite copied to clipboard

Abort VM Execution and Release all resource acquired by the unqlite_context and frames when exception thrown by embedded functions

Open AlaaAlHallaq opened this issue 8 years ago • 0 comments

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.

AlaaAlHallaq avatar Mar 31 '18 21:03 AlaaAlHallaq