Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def baz():
"Address should contain only hex characters",
)

@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
def test_trampoline_with_unencodable_name(self):
code = """if 1:
import sys

sys.activate_stack_trampoline("perf")
eval(compile("pass", "bad\\ud800file", "exec"))
"""
assert_python_ok("-c", code, PYTHON_JIT="0")

@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT instrumented binaries")
def test_trampoline_works_with_forks(self):
code = """if 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in the perf trampoline when a code object has a name or filename
that cannot be encoded to UTF-8. Patched by Shamil Abdulaev.
6 changes: 6 additions & 0 deletions Python/perf_jit_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,15 @@ static void perf_map_jit_write_entry(void *state, const void *code_addr,
if (co != NULL) {
if (co->co_qualname != NULL) {
entry = PyUnicode_AsUTF8(co->co_qualname);
if (entry == NULL) {
PyErr_Clear();
}
}
if (co->co_filename != NULL) {
filename = PyUnicode_AsUTF8(co->co_filename);
if (filename == NULL) {
PyErr_Clear();
}
}
}
perf_map_jit_write_entry_with_name(state, code_addr, code_size,
Expand Down
8 changes: 8 additions & 0 deletions Python/perf_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,18 @@ perf_map_write_entry(void *state, const void *code_addr,
const char *entry = "";
if (co->co_qualname != NULL) {
entry = PyUnicode_AsUTF8(co->co_qualname);
if (entry == NULL) {
PyErr_Clear();
entry = "";
}
}
const char *filename = "";
if (co->co_filename != NULL) {
filename = PyUnicode_AsUTF8(co->co_filename);
if (filename == NULL) {
PyErr_Clear();
filename = "";
}
}
size_t perf_map_entry_size = snprintf(NULL, 0, "py::%s:%s", entry, filename) + 1;
char* perf_map_entry = (char*) PyMem_RawMalloc(perf_map_entry_size);
Expand Down
Loading