Skip to content

Instantly share code, notes, and snippets.

@swilly22
Last active September 15, 2019 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swilly22/db5f051f537a31aa5bae63b57475743b to your computer and use it in GitHub Desktop.
Save swilly22/db5f051f537a31aa5bae63b57475743b to your computer and use it in GitHub Desktop.
// ExecutionPlan.c
function Query_Execute() {
/* Set an exception-handling breakpoint to capture run-time errors.
* encountered_error will be set to 0 when setjmp is invoked, and will be nonzero if
* a downstream exception returns us to this breakpoint. */
QueryCtx *ctx = pthread_getspecific(_tlsQueryCtxKey);
if(!ctx->breakpoint) ctx->breakpoint = rm_malloc(sizeof(jmp_buf));
int encountered_error = setjmp(*ctx->breakpoint);
if(encountered_error) {
// Encountered a run-time error; return immediately.
reportError();
return;
}
/* Start executing, if an exception is thrown somewhere down the road
* we will resume execution at: if(encountered_error) above. */
ExecutionPlan_Execute();
}
/* ArithmeticExpression.c
* AR_EXP_Evaluate is called from various points in our code base
* all originating from Query_Execute. */
SIValue AR_EXP_Evaluate(AR_ExpNode *root, const Record r) {
SIValue result;
AR_EXP_Result res = _AR_EXP_Evaluate(root, r, &result);
if(res != EVAL_OK) {
/* An error was encountered during evaluation!
* Exit this routine and return to the point on the stack where the handler was
* instantiated. */
jmp_buf *env = _QueryCtx_GetExceptionHandler();
longjmp(*env, 1);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment