[Python-checkins] Remove PyTryblock struct (GH-26059)
markshannon
webhook-mailer at python.org
Wed May 12 09:04:46 EDT 2021
https://github.com/python/cpython/commit/117bfd2b7141127b18d5ca4d6bbc4b3068bbce33
commit: 117bfd2b7141127b18d5ca4d6bbc4b3068bbce33
branch: main
author: Mark Shannon <mark at hotpy.org>
committer: markshannon <mark at hotpy.org>
date: 2021-05-12T14:04:38+01:00
summary:
Remove PyTryblock struct (GH-26059)
files:
M Include/cpython/frameobject.h
M Python/ceval.c
diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h
index 0c2206c0b92b6d..581664775cdedc 100644
--- a/Include/cpython/frameobject.h
+++ b/Include/cpython/frameobject.h
@@ -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 */
diff --git a/Python/ceval.c b/Python/ceval.c
index 8e1c5bdf033074..2e15eea48003e0 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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 *
More information about the Python-checkins
mailing list