Commit graph

15935 commits

Author SHA1 Message Date
sobolevn
a6c2d4ae3b
gh-151763: Fix crash in _interpqueues.create on MemoryError (#152131) 2026-06-25 07:04:02 +00:00
Serhiy Storchaka
a52f428fba
gh-151776: Add curses state-query functions (GH-151778)
Add window methods and module functions that report curses state which could
previously only be set: the window getters is_cleared(), is_idcok(),
is_idlok(), is_immedok(), is_keypad(), is_leaveok(), is_nodelay(),
is_notimeout(), is_pad(), is_scrollok(), is_subwin(), is_syncok(),
getdelay(), getparent() and getscrreg(), and the functions is_cbreak(),
is_echo(), is_nl() and is_raw().  They are available when built against an
ncurses with NCURSES_EXT_FUNCS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 22:31:50 +03:00
Serhiy Storchaka
3cd4283ba6
gh-151774: Add curses dynamic color-pair functions (GH-151775)
Add alloc_pair(), find_pair(), free_pair() and reset_color_pairs(),
wrapping the ncurses extended-color dynamic pair management.  They are
available only when built against a wide-character ncurses with
extended-color support.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 21:24:11 +03:00
Zain Nadeem
ce8b81fff4
gh-151763: Fix NULL dereference in os._path_normpath() under OOM (#151779) 2026-06-24 16:56:10 +01:00
Stan Ulbrych
15696a69d6
gh-90949: Fix copy-paste typo in pyexpat capsule API initialization (#151147) 2026-06-24 15:10:46 +01:00
Timofei
ad2cabfccb
gh-152020: Fix asyncio.all_tasks() loosing eager tasks on FT-build (#152022)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2026-06-24 17:51:42 +05:30
Stan Ulbrych
c61307222e
gh-151814: Fix unbounded memory growth from repeated empty writes to io.TextIOWrapper (#151817) 2026-06-24 12:47:52 +01:00
Serhiy Storchaka
ac023ea48f
gh-90092: Support multiple terminals in the curses module (GH-151748)
Add the X/Open Curses SCREEN API for driving more than one terminal:
newterm() and set_term(), plus the ncurses extension new_prescr().

A new screen object wraps the C SCREEN.  It exposes the terminal's
standard window as screen.stdscr.  Each window keeps a reference to its
screen (like a subwindow does to its parent window), so the screen is
deleted automatically once it and all of its windows are unreferenced.

The ncurses use_screen()/use_window() locking helpers are exposed as
the screen.use() and window.use() methods.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 11:33:02 +00:00
Serhiy Storchaka
560ff8e202
gh-87904: Document curses classes (GH-151643)
Add docstrings for the curses.window, curses.error, curses.panel.panel
and curses.panel.error classes.  Document the panel class and its error
exception in curses.panel.rst, using the real lowercase panel name.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 06:08:34 +00:00
Serhiy Storchaka
124c7cd91b
gh-126219: Fix crash in tkinter.Tk with non-BMP className on Tcl/Tk 8.x (GH-151980)
Tcl 8.x crashes when title-casing a non-BMP character during Tk
initialization, so such a className is now rejected with a ValueError.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 08:59:42 +03:00
Serhiy Storchaka
a5677bff84
gh-151757: Support wide and combining characters in the curses module (GH-151758)
The character-cell window methods now accept a full character cell -- a
spacing character optionally followed by combining characters (up to
CCHARW_MAX wide characters) -- in addition to a single int or byte
character.  This affects addch(), bkgd(), bkgdset(), border(), box(),
echochar(), hline(), insch() and vline(); they dispatch to the ncursesw
wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(),
wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a
string.  border() and box() cannot mix integer or byte characters with
wide string characters in a single call.  A cell is one spacing character
optionally followed by combining characters, so an extra spacing or
control character (such as "ab") is rejected with ValueError rather than
being silently truncated by setcchar().

Also add the wide-character read methods get_wstr() and in_wstr(), the
counterparts of getstr() and instr() that return a str rather than a
bytes object, and the module functions erasewchar(), killwchar() and
wunctrl(), the wide-character counterparts of erasechar(), killchar()
and unctrl().

All of this is available only when built against the wide-character
ncursesw library.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 08:52:10 +03:00
Serhiy Storchaka
fde4cf862c
gh-152033: Optimize category escapes outside character sets (GH-152035)
Character class escapes (``\d``, ``\D``, ``\s``, ``\S``, ``\w`` and
``\W``) that occur outside a character set are now compiled directly to a
single CATEGORY opcode instead of being wrapped in an IN block.  This
removes the IN wrapper (three code words) and an indirect charset() call,
and makes such an escape a simple repeatable unit so that, for example,
``\d+`` uses the REPEAT_ONE fast path; a CATEGORY case is added to
SRE(count).

The transformation preserves behaviour exactly.  For category-heavy
patterns the compiled byte code is about 20% smaller and matching is up
to ~2x faster, with no effect on patterns that do not use bare category
escapes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 08:49:14 +03:00
Amrutha
5e0747db2f
gh-151842: Fix crash upon OOM in _interpreters.capture_exception (GH-151843) 2026-06-23 16:31:47 -04:00
Ivy Xu
4448205d95
gh-151126: Fix missing PyErr_NoMemory in getpath.c (#151590) 2026-06-22 14:59:22 +01:00
tonghuaroot (童话)
1fb874cc07
gh-151770: Fix datetime.fromisoformat() on an out-of-range month w/ a 24:00 time (#151771)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-20 17:33:16 +01:00
Serhiy Storchaka
2e5843e13f
gh-151744: Add curses.nofilter() (GH-151747)
Wrap the ncurses nofilter() function, which undoes the effect of
filter().  Without it there is no way to restore normal screen sizing
after a curses.filter() call in the same process.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 17:49:26 +00:00
Jonathan J. Helmus
c4eb3adbb4
gh-150836: Mount embedded Tk ZIP in _tkinter on Windows (GH-151562)
Tcl/Tk 9 may embed the Tk script library in the Tk DLL on Windows. This embedded library is not found by Tcl by default.

Mount the loaded Tk DLL as a zipfs archive before calling Tk_Init(), so Tk can find its embedded tk_library using its existing library discovery logic.

Preserve Tk_Init()'s normal path if the library is not embedded.
2026-06-19 14:23:01 +00:00
Serhiy Storchaka
551f8e16f8
gh-151695: Fix use-after-free of the curses screen encoding (GH-151696)
The module-global curses_screen_encoding stored a borrowed pointer to the
encoding owned by the window returned by the first initscr() call.  That
window can be deallocated while unctrl() and ungetch(), which have no window
of their own, still use the pointer to encode non-ASCII characters.

Keep a private copy of the encoding instead.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 08:38:15 +00:00
Mark Shannon
ad1513a263
GH-150516: Reduce the work done to spill and reload the stack around calls (GH-151587) 2026-06-18 15:14:30 +01:00
Donghee Na
3fa92e7c55
gh-151229: Finalize JIT tracer in test eval-frame stub (gh-151609) 2026-06-18 20:58:12 +09:00
Serhiy Storchaka
12add3822f
gh-151623: Add missing curses docstrings and document intrflush() (#151632) 2026-06-18 13:52:26 +03:00
Serhiy Storchaka
65afcdd8df
gh-151623: Improve curses documentation and docstrings (GH-151625)
Fix errors and clarify the curses, curses.panel and curses.ascii docs
against X/Open Curses and ncurses, and sync the affected docstrings.
2026-06-18 11:20:03 +03:00
Donghee Na
8d7c6dcde0
gh-150942: Optimize PicklerMemoProxy.copy() with _PyDict_SetItem_Take2 (gh-151608) 2026-06-18 09:08:00 +09:00
Maurycy Pawłowski-Wieroński
a8d74c062f
gh-151436: Fix missing tstate->last_profiled_frame updates (#151437) 2026-06-17 16:49:23 -04:00
AN Long
eff805b7a7
gh-151510: Fix __lazy_import__ without frame (#151511) 2026-06-17 14:09:51 -04:00
Petr Viktorin
16185e9fe2
gh-149044: Improve Py_tp_base[s] docs & error message for non-type bases (GH-151252)
The initial implementation of PEP 820 worsened the error message
when non-types are given as base types in Py_tp_bases & Py_tp_base.
Bring back the 'bases must be types' wording and add a 'got' note for
easier debugging.

Improve slot ID documentation, and soft-deprecate Py_tp_base
(as per the PEP).
2026-06-17 15:27:02 +02:00
sobolevn
a173a6d65b
gh-151584: Remove PyUnstable_Module_SetGIL call in _remote_debugging (#151585) 2026-06-17 15:37:08 +03:00
Steve Dower
9e863fab28
gh-151544: Fixes CVE-2026-12003 by removing the fallback to %VPATH%/Modules/Setup.local for discovering sources in getpath.py (GH-151545) 2026-06-17 00:16:06 +01:00
Kumar Aditya
e9d5280f6c
gh-151223: fix tsan data races in load global specializations (#151393) 2026-06-15 22:09:49 +05:30
Serhiy Storchaka
90748760d3
gh-149079: Optimize sorting in unicodedata.normalize() (GH-150782)
Sort the Py_UCS4 buffer instead of PyUnicodeObject. This allows to avoid
the use of PyUnicode_READ() and PyUnicode_WRITE().
2026-06-15 16:36:50 +02:00
Victor Stinner
b6a2eef2c1
Fix issues reported by cpython-review-toolkit in faulthandler (#151341)
* snprintf() is not async-signal-safe: replace it with
  _Py_DumpDecimal().
* Fix tid type from 'long' to 'unsigned long'.
* Replace PyLong_AsLong() with PyLong_AsInt().
* Avoid unnecessary narrowing cast on _Py_write_noraise() call.
2026-06-15 13:11:26 +02:00
JasonMendoza2008
ecbd31ee39
gh-137759: Replace _PyObject_HashFast() with PyObject_Hash() in setobject.c (#137828)
Replace also _PyObject_HashFast() with PyObject_Hash()
in _collections._count_elements().

Rename _PyObject_HashFast() to _PyObject_HashDictKey(),
and mark it as Py_ALWAYS_INLINE.

Only use _PyObject_HashDictKey() on dictionaries.
2026-06-15 11:31:04 +02:00
Maurycy Pawłowski-Wieroński
6ce088e20a
gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss (#151426) 2026-06-14 00:10:56 +01:00
tonghuaroot (童话)
6679ac07d8
gh-151403: Fix use-after-free when an argv item's __fspath__ mutates args (GH-151404)
---------

Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
2026-06-13 10:23:44 -07:00
sobolevn
6b217ea90b
gh-151126: Fix crash on unset memory error in ctypes.get_errno (#151382) 2026-06-12 14:03:21 +03:00
Matt Wozniski
c37599200f
gh-151297: Fix undefined behavior in _PyObject_MiRealloc (GH-151358)
The standard says that a call to `memcpy` must pass a valid source and
destination pointer even if the size is 0, so we must avoid calling
`memcpy` when our source pointer is NULL. If we don't, an optimizing
compiler can decide that the pointer must be non-NULL based on the
presence of UB, and optimize out checks for null pointers.

Specifically, note that the standard says:

    Where an argument declared as size_t n specifies the length of the
    array for a function, n can have the value zero on a call to that
    function. Unless explicitly stated otherwise in the description of
    a particular function in this subclause, pointer arguments on such
    a call shall still have valid values, as described in 7.1.4.

And section 7.1.4 says:

    If an argument to a function has an invalid value (such as a value
    outside the domain of the function, or a pointer outside the address
    space of the program, or a null pointer, or a pointer to
    non-modifiable storage when the corresponding parameter is not
    const-qualified) or a type (after default argument promotion) not
    expected by a function with a variable number of arguments, the
    behavior is undefined.

The specification for `memcpy` doesn't state that it's allowed to be
called with null pointers, and Linux's `/usr/include/string.h` declares
`memcpy` as `__nonnull ((1, 2))`.
2026-06-11 21:21:04 -04:00
Ivy Xu
71805db429
gh-151337: Avoid possible memory leak in _tkinter.c on Windows. (GH-151340) 2026-06-11 22:55:11 +03:00
Pieter Eendebak
36fe7784b0
gh-150942: Speed up json.loads array and object decoding (GH-150945)
Append parsed values to the result list with _PyList_AppendTakeRef and
insert key/value pairs with _PyDict_SetItem_Take2, which take ownership of
the references instead of incref-ing on insert and then decref-ing the
local.  This removes a reference-count round-trip per element (and, on the
free-threaded build, a per-append lock).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 17:38:49 +01:00
Dino Viehland
efb2fffae1
gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
Raise PyType_Modified for insertion into split dictionary
2026-06-11 09:38:31 -07:00
sobolevn
10595b1cb7
gh-151126: Fix missing memory error in os._path_splitroot (#151339) 2026-06-11 15:48:08 +00:00
sobolevn
9fd1a125bc
gh-151126: Fix missing memory errors in _interpchannelsmodule.c (#151239) 2026-06-10 18:59:11 +03:00
tonghuaroot (童话)
896f7fdc7d
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (#143987)
Fix crashes in socket.sendmsg() and socket.recvmsg_into() that could
occur if buffer sequences are mutated re-entrantly during argument
parsing via __buffer__ protocol callbacks.

The bug occurs because:

1. PySequence_Fast() returns the original list object when the input
   is already a list (not a copy).
2. During iteration, PyObject_GetBuffer() triggers __buffer__
   callbacks which may clear the list.
3. Subsequent iterations access invalid memory (heap OOB read).

The fix replaces PySequence_Fast() with PySequence_Tuple() which
always creates a new tuple, ensuring the sequence cannot be mutated
during iteration.

Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
2026-06-10 13:03:49 +00:00
sobolevn
8d94fa7b86
gh-151126: Add missing PyErr_NoMemory in _winapi module (#151154) 2026-06-09 19:42:08 +03:00
sobolevn
9fdbade99e
gh-151039: Fix a crash when _datetime types outlive _datetime module (#151044) 2026-06-09 11:44:37 +00:00
Serhiy Storchaka
c3cd75afdf
gh-151130: Add more tests for PyWeakref_* C API (GH-151131) 2026-06-09 11:11:17 +00:00
Cody Maloney
db4b1948bc
gh-143008: Fix Null pointer dereferences in TextIOWrapper underlying stream access (#145957)
TextIOWrapper keeps its underlying stream in a member called
`self->buffer`. That stream can be detached by user code, such as custom
`.flush` implementations resulting in `self->buffer` being set to NULL.
The implementation often checked at the start of functions if
`self->buffer` is in a good state, but did not always recheck after
other Python code was called which could modify `self->buffer`.

The cases which need to be re-checked are hard to spot so rather than
rely on reviewer effort create better safety by making all self->buffer
access go through helper functions.

Thank you yihong0618 for the test, NEWS and initial implementation in
gh-143041.

Co-authored-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-09 12:31:44 +02:00
Pieter Eendebak
537702d570
gh-151059: [perf] Use PyObject_CallMethodOneArg in datetime's call_tzinfo_method (#151062) 2026-06-08 14:11:36 +03:00
Stan Ulbrych
5755d0f083
gh-150599: Prevent bz2 decompressor reuse after errors (#150600) 2026-06-07 08:19:05 -07:00
esadomer
f2cab7b0cf
gh-151021: Fix mmap empty searches past the end (GH-151023) 2026-06-07 16:01:24 +03:00
Pieter Eendebak
0f7dc2fefa
gh-150942: Speed up re.findall and re.sub/subn result building (gh-150943) 2026-06-07 21:06:36 +09:00