mirror of
https://github.com/python/cpython
synced 2024-09-15 23:57:10 +00:00
Remove PyTryblock struct (GH-26059)
This commit is contained in:
parent
78b2abca8e
commit
117bfd2b71
|
@ -19,12 +19,6 @@ enum _framestate {
|
|||
|
||||
typedef signed char PyFrameState;
|
||||
|
||||
typedef struct {
|
||||
int b_type; /* what kind of block this is */
|
||||
int b_handler; /* where to jump to find handler */
|
||||
int b_level; /* value stack level to pop to */
|
||||
} PyTryBlock;
|
||||
|
||||
struct _frame {
|
||||
PyObject_VAR_HEAD
|
||||
struct _frame *f_back; /* previous frame, or NULL */
|
||||
|
|
|
@ -95,7 +95,7 @@ static PyObject * special_lookup(PyThreadState *, PyObject *, _Py_Identifier *);
|
|||
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
|
||||
static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
|
||||
static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int);
|
||||
static PyTryBlock get_exception_handler(PyCodeObject *, int);
|
||||
static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
|
||||
|
||||
#define NAME_ERROR_MSG \
|
||||
"name '%.200s' is not defined"
|
||||
|
@ -4461,21 +4461,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
|
|||
exception_unwind:
|
||||
f->f_state = FRAME_UNWINDING;
|
||||
/* We can't use f->f_lasti here, as RERAISE may have set it */
|
||||
int lasti = INSTR_OFFSET()-1;
|
||||
PyTryBlock from_table = get_exception_handler(co, lasti);
|
||||
if (from_table.b_handler < 0) {
|
||||
int offset = INSTR_OFFSET()-1;
|
||||
int level, handler, lasti;
|
||||
if (get_exception_handler(co, offset, &level, &handler, &lasti) == 0) {
|
||||
// No handlers, so exit.
|
||||
break;
|
||||
}
|
||||
|
||||
assert(STACK_LEVEL() >= from_table.b_level);
|
||||
while (STACK_LEVEL() > from_table.b_level) {
|
||||
assert(STACK_LEVEL() >= level);
|
||||
while (STACK_LEVEL() > level) {
|
||||
PyObject *v = POP();
|
||||
Py_XDECREF(v);
|
||||
}
|
||||
PyObject *exc, *val, *tb;
|
||||
int handler = from_table.b_handler;
|
||||
if (from_table.b_type) {
|
||||
if (lasti) {
|
||||
PyObject *lasti = PyLong_FromLong(f->f_lasti);
|
||||
if (lasti == NULL) {
|
||||
goto exception_unwind;
|
||||
|
@ -4811,21 +4810,11 @@ parse_range(unsigned char *p, int *start, int*end)
|
|||
return p;
|
||||
}
|
||||
|
||||
static inline void
|
||||
parse_block(unsigned char *p, PyTryBlock *block) {
|
||||
int depth_and_lasti;
|
||||
p = parse_varint(p, &block->b_handler);
|
||||
p = parse_varint(p, &depth_and_lasti);
|
||||
block->b_level = depth_and_lasti >> 1;
|
||||
block->b_type = depth_and_lasti & 1;
|
||||
}
|
||||
|
||||
#define MAX_LINEAR_SEARCH 40
|
||||
|
||||
static PyTryBlock
|
||||
get_exception_handler(PyCodeObject *code, int index)
|
||||
static int
|
||||
get_exception_handler(PyCodeObject *code, int index, int *level, int *handler, int *lasti)
|
||||
{
|
||||
PyTryBlock res;
|
||||
unsigned char *start = (unsigned char *)PyBytes_AS_STRING(code->co_exceptiontable);
|
||||
unsigned char *end = start + PyBytes_GET_SIZE(code->co_exceptiontable);
|
||||
/* Invariants:
|
||||
|
@ -4837,8 +4826,7 @@ get_exception_handler(PyCodeObject *code, int index)
|
|||
int offset;
|
||||
parse_varint(start, &offset);
|
||||
if (offset > index) {
|
||||
res.b_handler = -1;
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
do {
|
||||
unsigned char * mid = start + ((end-start)>>1);
|
||||
|
@ -4862,13 +4850,16 @@ get_exception_handler(PyCodeObject *code, int index)
|
|||
}
|
||||
scan = parse_varint(scan, &size);
|
||||
if (start_offset + size > index) {
|
||||
parse_block(scan, &res);
|
||||
return res;
|
||||
scan = parse_varint(scan, handler);
|
||||
int depth_and_lasti;
|
||||
parse_varint(scan, &depth_and_lasti);
|
||||
*level = depth_and_lasti >> 1;
|
||||
*lasti = depth_and_lasti & 1;
|
||||
return 1;
|
||||
}
|
||||
scan = skip_to_next_entry(scan, end);
|
||||
}
|
||||
res.b_handler = -1;
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyFrameObject *
|
||||
|
|
Loading…
Reference in a new issue