Skip to content

Instantly share code, notes, and snippets.

@rokob
Last active May 2, 2019 05:24
Show Gist options
  • Save rokob/f13908f81e03186a19ab80b0f3199a42 to your computer and use it in GitHub Desktop.
Save rokob/f13908f81e03186a19ab80b0f3199a42 to your computer and use it in GitHub Desktop.
on_error:
if (why == WHY_NOT) {
if (err == 0 && x != NULL) {
continue; /* Normal, fast path */
}
why = WHY_EXCEPTION;
x = Py_None;
err = 0;
}
/* Double-check exception status */
if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_SystemError,
"error return without exception set");
why = WHY_EXCEPTION;
}
}
/* Log traceback info if this is a real exception */
if (why == WHY_EXCEPTION) {
PyTraceBack_Here(f);
if (tstate->c_tracefunc != NULL)
call_exc_trace(tstate->c_tracefunc,
tstate->c_traceobj, f);
}
/* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
if (why == WHY_RERAISE)
why = WHY_EXCEPTION;
fast_block_end:
while (why != WHY_NOT && f->f_iblock > 0) {
/* Peek at the current block. */
PyTryBlock *b = &f->f_blockstack[f->f_iblock - 1];
assert(why != WHY_YIELD);
if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {
why = WHY_NOT;
JUMPTO(PyInt_AS_LONG(retval));
Py_DECREF(retval);
break;
}
/* Now we have to pop the block. */
f->f_iblock--;
while (STACK_LEVEL() > b->b_level) {
v = POP();
Py_XDECREF(v);
}
if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {
why = WHY_NOT;
JUMPTO(b->b_handler);
break;
}
if (b->b_type == SETUP_FINALLY ||
(b->b_type == SETUP_EXCEPT &&
why == WHY_EXCEPTION) ||
b->b_type == SETUP_WITH) {
if (why == WHY_EXCEPTION) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
if (val == NULL) {
val = Py_None;
Py_INCREF(val);
}
/* Make the raw exception data
available to the handler,
so a program can emulate the
Python main loop. Don't do
this for 'finally'. */
if (b->b_type == SETUP_EXCEPT ||
b->b_type == SETUP_WITH) {
PyErr_NormalizeException(
&exc, &val, &tb);
set_exc_info(tstate,
exc, val, tb);
}
if (tb == NULL) {
Py_INCREF(Py_None);
PUSH(Py_None);
} else
PUSH(tb);
PUSH(val);
PUSH(exc);
}
else {
if (why & (WHY_RETURN | WHY_CONTINUE))
PUSH(retval);
v = PyInt_FromLong((long)why);
PUSH(v);
}
why = WHY_NOT;
JUMPTO(b->b_handler);
break;
}
} /* unwind stack */
/* End the loop if we still have an error (or return) */
if (why != WHY_NOT)
break;
} /* main loop */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment