summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-12 13:04:38 (GMT)
committerGitHub <noreply@github.com>2021-05-12 13:04:38 (GMT)
commit117bfd2b7141127b18d5ca4d6bbc4b3068bbce33 (patch)
treea41aa3969f119f6adfe37294edae5792d2c3537f /Python
parent78b2abca8e96b43f56ab1b9ad673aaa6bbe7e790 (diff)
downloadcpython-117bfd2b7141127b18d5ca4d6bbc4b3068bbce33.zip
cpython-117bfd2b7141127b18d5ca4d6bbc4b3068bbce33.tar.gz
cpython-117bfd2b7141127b18d5ca4d6bbc4b3068bbce33.tar.bz2
Remove PyTryblock struct (GH-26059)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 8e1c5bd..2e15eea 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 @@ error:
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 *