gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (GH-151260)
Return 0 if the object is not tracked by the GC.
(cherry picked from commit 72e7eddce6)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-151278: Fix test_faulthandler on UBSan (GH-151279)
* Py_FatalError() no longer calls _PyFaulthandler_Fini() if it
doesn't hold the GIL.
* Skip test_faulthandler tests raising signals if run with UBSan.
* Enable test_faulthandler in GitHub Action "Reusable Sanitizer".
(cherry picked from commit e60c42dc3f)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)
If "import encodings" fails at Python startup, dump the Python path
configuration to help users debugging their configuration. The
encodings module is the first module imported during Python startup.
(cherry picked from commit 7b6e98911e)
GHA: Display output when a sanitizer test fails (GH-151268)
Modify GitHub Action "Reusable Sanitizer" to display output when a
test fails: pass -W option.
(cherry picked from commit 3a8bebd86f)
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (GH-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.
(cherry picked from commit 896f7fdc7d)
Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
Add yet one assertion in test_set_text_charset_cp949 (GH-151224)
Check bytes(m), not only str(m).
(cherry picked from commit 3ca93ab198)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Docs: Fix typos in the "Memory Management" section (GH-151243)
(cherry picked from commit 8c0e2515bb)
Co-authored-by: Manoj K M <manojkm24dev@gmail.com>
gh-89554: Document socket.SocketType as a class (GH-150683)
socket.SocketType is a class (re-exported from _socket as an alias of
_socket.socket, the base class of socket.socket), but was documented with
the ".. data::" directive, so ":class:" cross-references to it cannot
resolve against a py:class target.
Switch the entry to ".. class::", correct the misleading description
(SocketType is the base class of the socket type, not "type(socket(...))"
which is socket.socket; addresses gh-88427), move it into the Socket
Objects section, and document the socket object methods and attributes
nested under the socket class, dropping the redundant "socket." prefix.
(cherry picked from commit a621e8ad81)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82282)
Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-98894: Fix DTrace test_check_probes for shared builds (GH-151122)
When building with --enable-shared, the SystemTap/DTrace notes
live in libpython. Add detection logic to be used by readelf.
Force the C locale on readelf output.
(cherry picked from commit 3a08e93739)
Co-authored-by: stratakis <cstratak@redhat.com>
gh-150700: Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends (GH-150735)
* Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends
In `inline_comprehension()`, when `__class__` / `__classdict__` /
`__conditional_annotations__` appears as `FREE` in a comprehension's
symbol table because a nested scope captured it (e.g. nested lambdas),
this name is still discarded from `comp_free` unconditionally.
This prevents `drop_class_free()` from seeing it, so the appropriate
`ste_needs_(...)` flag is never set on the enclosing class.
That leads to `codegen_make_closure()` throwing `SystemError` when it
couldn't find `__class__` / `__classdict__` /
`__conditional_annotations__` in the class's cellvars.
From now on we just discard from `comp_free` when no child scope
(e.g. a lambda) still needs the name as `FREE`. When a child scope does
need it, keep it in `comp_free` so `drop_class_free()` can set the
appropriate flag and the class creates the implicit cell.
* Fix tests
* Fix typo
* Fix formatting
* Add test checking validity of `__class__` returned
* Prefer 'used' to 'deferred'
(cherry picked from commit ce916dc506)
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
gh-151112: Fix double free in `assemble_init` when out of memory (GH-151142)
(cherry picked from commit 580499177c)
Co-authored-by: Stan Ulbrych <stan@python.org>
Nonatomic move might be used even if the files are
on the same filesystem in some cases.
(cherry picked from commit 6ecd197c03)
Co-authored-by: Fang Li <fangli@users.noreply.github.com>
gh-150633: Minor improvement of a newly added test (GH-151103)
Minor improvement of a newly added test.
(cherry picked from commit fccf67a354)
Co-authored-by: Barry Warsaw <barry@python.org>
gh-151019: Fix test_os on 32-bit FreeBSD (GH-151087)
Remove references to server.handler_instance. This attribute has been
removed in 2022 by commit 3ae975f1ac.
(cherry picked from commit a9002349cb)
Co-authored-by: Victor Stinner <vstinner@python.org>