diff options
author | Mark Shannon <mark@hotpy.org> | 2021-05-07 15:19:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 15:19:19 +0100 |
commit | adcd2205565f91c6719f4141ab4e1da6d7086126 (patch) | |
tree | 0953b285944eccde57b05b8f3c7e30fb501a3d64 /Python/marshal.c | |
parent | b32c8e97951db46484ba3b646b988bcdc4062199 (diff) | |
download | cpython-adcd2205565f91c6719f4141ab4e1da6d7086126.tar.gz cpython-adcd2205565f91c6719f4141ab4e1da6d7086126.zip |
bpo-40222: "Zero cost" exception handling (GH-25729)
"Zero cost" exception handling.
* Uses a lookup table to determine how to handle exceptions.
* Removes SETUP_FINALLY and POP_TOP block instructions, eliminating (most of) the runtime overhead of try statements.
* Reduces the size of the frame object by about 60%.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r-- | Python/marshal.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index fa4ec9eb605..f8ec7789a38 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -525,6 +525,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p) w_object(co->co_name, p); w_long(co->co_firstlineno, p); w_object(co->co_linetable, p); + w_object(co->co_exceptiontable, p); } else if (PyObject_CheckBuffer(v)) { /* Write unknown bytes-like objects as a bytes object */ @@ -1313,6 +1314,7 @@ r_object(RFILE *p) PyObject *name = NULL; int firstlineno; PyObject *linetable = NULL; + PyObject *exceptiontable = NULL; idx = r_ref_reserve(flag, p); if (idx < 0) @@ -1370,6 +1372,10 @@ r_object(RFILE *p) linetable = r_object(p); if (linetable == NULL) goto code_error; + exceptiontable = r_object(p); + if (exceptiontable == NULL) + goto code_error; + if (PySys_Audit("code.__new__", "OOOiiiiii", code, filename, name, argcount, posonlyargcount, @@ -1382,7 +1388,7 @@ r_object(RFILE *p) nlocals, stacksize, flags, code, consts, names, varnames, freevars, cellvars, filename, name, - firstlineno, linetable); + firstlineno, linetable, exceptiontable); v = r_ref_insert(v, idx, flag, p); code_error: @@ -1395,6 +1401,7 @@ r_object(RFILE *p) Py_XDECREF(filename); Py_XDECREF(name); Py_XDECREF(linetable); + Py_XDECREF(exceptiontable); } retval = v; break; |