Skip to content

bpo-32604: [_xxsubinterpreters] Propagate exceptions. #19768

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Extract __traceback__ with the proper order.
  • Loading branch information
ericsnowcurrently committed Apr 28, 2020
commit 6d9e383b2f60eb36f5bbb991b22311fd92849606
9 changes: 5 additions & 4 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,11 @@ def assertTracebacksEqual(self, tb, expected):
elif not isinstance(expected, Traceback):
self.assertEqual(tb, expected)
else:
self.assertEqual(tb.tb_lineno, expected.tb_lineno)
self.assertEqual(tb.tb_frame.f_code.co_filename,
expected.tb_frame.f_code.co_filename)
self.assertEqual(tb.tb_frame.f_code.co_name,
expected.tb_frame.f_code.co_name)
self.assertEqual(tb.tb_frame.f_code.co_filename,
expected.tb_frame.f_code.co_filename)
self.assertEqual(tb.tb_lineno, expected.tb_lineno)
self.assertTracebacksEqual(tb.tb_next, expected.tb_next)

# XXX Move this to TestBase?
Expand Down Expand Up @@ -1304,14 +1304,15 @@ def main():
exec(script, ns, ns)
except Exception as exc:
expected = exc
expectedtb = exc.__traceback__.tb_next

interpid = interpreters.create()
with self.expected_run_failure(expected) as caught:
interpreters.run_string(interpid, script)
exc = caught.exception

self.assertTracebacksEqual(exc.__cause__.__traceback__,
expected.__traceback__)
expectedtb)

def test_chained_exceptions(self):
script = dedent("""
Expand Down
55 changes: 42 additions & 13 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,12 @@ _tbsnapshot_is_clear(_tbsnapshot *tbs)
&& _rawstring_is_clear(&tbs->tbs_filename);
}

static void _tbsnapshot_extract(_tbsnapshot *, PyTracebackObject *);
static void
_tbsnapshot_extract(_tbsnapshot *tbs, PyTracebackObject *pytb)
static int
_tbsnapshot_from_pytb(_tbsnapshot *tbs, PyTracebackObject *pytb)
{
assert(_tbsnapshot_is_clear(tbs));
assert(pytb != NULL);

if (pytb->tb_next != NULL) {
tbs->tbs_next = _tbsnapshot_new();
if (tbs->tbs_next == NULL) {
goto error;
}
_tbsnapshot_extract(tbs->tbs_next, pytb->tb_next);
}
PyCodeObject *pycode = pytb->tb_frame->f_code;
const char *funcname = PyUnicode_AsUTF8(pycode->co_name);
if (_rawstring_strcpy(&tbs->tbs_funcname, funcname, 0) != 0) {
Expand All @@ -708,10 +700,44 @@ _tbsnapshot_extract(_tbsnapshot *tbs, PyTracebackObject *pytb)
}
tbs->tbs_lineno = pytb->tb_lineno;

return 0;

error:
_tbsnapshot_clear(tbs);
// XXX Emit a warning?
PyErr_Clear();
return -1;
}

static int
_tbsnapshot_extract(_tbsnapshot *tbs, PyTracebackObject *pytb)
{
assert(_tbsnapshot_is_clear(tbs));
assert(pytb != NULL);

_tbsnapshot *next = NULL;
while (pytb->tb_next != NULL) {
_tbsnapshot *_next = _tbsnapshot_new();
if (_next == NULL) {
goto error;
}
if (_tbsnapshot_from_pytb(_next, pytb) != 0) {
goto error;
}
if (next != NULL) {
_next->tbs_next = next;
}
next = _next;
pytb = pytb->tb_next;
}
if (_tbsnapshot_from_pytb(tbs, pytb) != 0) {
goto error;
}
tbs->tbs_next = next;

return 0;

error:
_tbsnapshot_clear(tbs);
return -1;
}

static PyObject *
Expand Down Expand Up @@ -836,7 +862,10 @@ _excsnapshot_extract(_excsnapshot *es, PyObject *excobj)
}
if (tb != NULL) {
es->es_traceback = _tbsnapshot_new();
_tbsnapshot_extract(es->es_traceback, (PyTracebackObject *)tb);
if (_tbsnapshot_extract(es->es_traceback,
(PyTracebackObject *)tb) != 0) {
IGNORE_FAILURE("could not extract __traceback__");
}
}
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy