8000 bpo-40222: Remove PyTryblock struct by markshannon · Pull Request #26059 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40222: Remove PyTryblock struct #26059

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

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Include/cpython/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
43 changes: 17 additions & 26 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand All @@ -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);
}
4C6C res.b_handler = -1;
return res;
return 0;
}

PyFrameObject *
Expand Down
0