diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 387d8034bb8c84a..7d16357a9f33933 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -519,10 +519,10 @@ dictionaries. The interpretation is similar to an integer *address*. 4. A two-tuple of an address description and a netmask, where the address - description is either a string, a 32-bits integer, a 4-bytes packed - integer, or an existing :class:`IPv4Address` object; and the netmask is either - an integer representing the prefix length (e.g. ``24``) or a string - representing the prefix mask (e.g. ``255.255.255.0``). + description is either a string, a 32-bit integer, a 4-byte packed + integer, or an existing :class:`IPv4Address` object; and the netmask is + either an integer representing the prefix length (e.g. ``24``) or a + string representing the prefix mask (e.g. ``255.255.255.0``). An :exc:`AddressValueError` is raised if *address* is not a valid IPv4 address. A :exc:`NetmaskValueError` is raised if the mask is not valid for @@ -769,9 +769,9 @@ dictionaries. The interpretation is similar to an integer *address*. 4. A two-tuple of an address description and a netmask, where the address - description is either a string, a 128-bits integer, a 16-bytes packed - integer, or an existing :class:`IPv6Address` object; and the netmask is an - integer representing the prefix length. + description is either a string, a 128-bit integer, a 16-byte packed + integer, or an existing :class:`IPv6Address` object; and the netmask is + an integer representing the prefix length. An :exc:`AddressValueError` is raised if *address* is not a valid IPv6 address. A :exc:`NetmaskValueError` is raised if the mask is not valid for diff --git a/Lib/idlelib/searchbase.py b/Lib/idlelib/searchbase.py index da96a047348094e..9bb247a6c178c82 100644 --- a/Lib/idlelib/searchbase.py +++ b/Lib/idlelib/searchbase.py @@ -139,7 +139,11 @@ def create_error_label(self): self.error_label = Label(self.frame, text=' ', foreground='red') self.error_label.grid(row=self.row, column=1, sticky="nw") self.row = self.row + 1 - self.engine.patvar.trace_add('write', lambda *args: self.show_error('')) + patvar = self.engine.patvar + trace = patvar.trace_add('write', lambda *args: self.show_error('')) + # The trace holds the dialog, remove it with the label. + self.error_label.bind('', + lambda e: patvar.trace_remove('write', trace)) def make_frame(self,labeltext=None): '''Return (frame, label). diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index de489c0ed034bb0..f160cc6a7ce900e 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1567,6 +1567,17 @@ def __init__(self, address, strict=True): IPv4Interface(int(IPv4Interface('192.0.2.1'))) == IPv4Interface('192.0.2.1') + The address can also be a two-tuple of an address description + and a netmask, where the address description is either a + string, a 32-bit integer, a 4-byte packed integer, or an + existing IPv4Address object; and the netmask is either an + integer representing the prefix length (e.g. 24) or a string + representing the prefix mask (e.g. '255.255.255.0'). + + strict: A boolean. If true, ensure that we have been passed + a true network address, for example, 192.0.2.0/24 and not an + IP address on a network, for example, 192.0.2.1/24. + Raises: AddressValueError: If ipaddress isn't a valid IPv4 address. NetmaskValueError: If the netmask isn't valid for @@ -2358,9 +2369,15 @@ def __init__(self, address, strict=True): IPv6Network(int(IPv6Network('2001:db8::'))) == IPv6Network('2001:db8::') + The address can also be a two-tuple of an address description and + a netmask, where the address description is either a string, a + 128-bit integer, a 16-byte packed integer, or an existing + IPv6Address object; and the netmask is an integer representing + the prefix length. + strict: A boolean. If true, ensure that we have been passed - A true network address, eg, 2001:db8::1000/124 and not an - IP address on a network, eg, 2001:db8::1/124. + a true network address, for example, 2001:db8::1000/124 and not an + IP address on a network, for example, 2001:db8::1/124. Raises: AddressValueError: If address isn't a valid IPv6 address. diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index a2e67726e959590..6c28947bdeabaaa 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -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: diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst new file mode 100644 index 000000000000000..096216f7e6c7b3c --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst @@ -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. diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index 21beead742a3a25..07aa8e769bf2d7d 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -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, diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index d90b789c2b57126..431ac2c3a778edb 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -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);