FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-149122: Fix segfault in compiler when certain builtin functions are passed a coroutine as arg (GH-149138) by miss-islington · Pull Request #149151 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 21 additions & 0 deletions Lib/test/test_builtin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ def f_tuple():
self.assertEqual(overridden_outputs, ['all', 'any', 'tuple'])


def test_builtin_call_async_genexpr_no_crash(self):
async def f_all():
return all(await 2 for _ in [])

async def f_any():
return any(await 2 for _ in [])

async def f_tuple():
return tuple(await 2 for _ in [])

async def f_list():
return list(await 2 for _ in [])

async def f_set():
return set(await 2 for _ in [])

for f in (f_all, f_any, f_tuple, f_list, f_set):
with self.subTest(func=f.__name__):
with self.assertRaises(TypeError):
run_yielding_async_fn(f)

def test_ascii(self):
self.assertEqual(ascii(''), '\'\'')
self.assertEqual(ascii(0), '0')
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix a crash in optimized calls to :func:`all`, :func:`any`, :func:`tuple`,
:func:`list`, and :func:`set` with an async generator expression argument
(for example, ``tuple(await x for x in y)``). These calls now correctly raise
``TypeError`` instead of crashing.
7 changes: 6 additions & 1 deletion Python/codegen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3861,6 +3861,12 @@ maybe_optimize_function_call(compiler *c, expr_ty e, jump_target_label end)
return 0;
}

expr_ty generator_exp = asdl_seq_GET(args, 0);
PySTEntryObject *generator_entry = _PySymtable_Lookup(SYMTABLE(c), (void *)generator_exp);
if (generator_entry->ste_coroutine) {
return 0;
}

location loc = LOC(func);

int optimized = 0;
Expand Down Expand Up @@ -3892,7 +3898,6 @@ maybe_optimize_function_call(compiler *c, expr_ty e, jump_target_label end)
if (const_oparg == CONSTANT_BUILTIN_TUPLE) {
ADDOP_I(c, loc, BUILD_LIST, 0);
}
expr_ty generator_exp = asdl_seq_GET(args, 0);
VISIT(c, expr, generator_exp);

NEW_JUMP_TARGET_LABEL(c, loop);
Expand Down
Loading

Back | FazBrowse Home | New Git URL