Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlaaAlHallaq opened this issue Mar 31, 2018 · 0 comments

Comments

@AlaaAlHallaq
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant