Sam Gross [Wed, 12 Feb 2025 23:09:15 +0000 (18:09 -0500)]
gh-130030: Fix crash on 32-bit Linux with free threading (gh-130043)
The `gc_get_refs` assertion needs to be after we check the alive and
unreachable bits. Otherwise, `ob_tid` may store the actual thread id
instead of the computed `gc_refs`, which may trigger the assertion if
the `ob_tid` looks like a negative value.
donBarbos [Wed, 12 Feb 2025 14:54:22 +0000 (18:54 +0400)]
gh-109798: Normalize `_datetime` and `datetime` error messages (#127345)
Updates error messages in datetime and makes them consistent between Python and C.
---------
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Sam Gross [Wed, 12 Feb 2025 14:34:40 +0000 (09:34 -0500)]
gh-128759: Fix accesses to `tp_version_tag`. (GH-129750)
We should use a relaxed atomic load in the free threading build in
`PyType_Modified()` because that's called without the type lock held.
It's not necessary to use atomics in `type_modified_unlocked()`.
We should also use `FT_ATOMIC_STORE_UINT_RELAXED()` instead of the
`UINT32` variant because `tp_version_tag` is declared as `unsigned int`.
Sam Gross [Tue, 11 Feb 2025 22:29:27 +0000 (17:29 -0500)]
gh-129967: Fix race condition in `repr(set)` (gh-129978)
The call to `PySequence_List()` could temporarily unlock and relock the
set, allowing the items to be cleared and return the incorrect
notation `{}` for a empty set (it should be `set()`).
Sam Gross [Tue, 11 Feb 2025 21:53:08 +0000 (16:53 -0500)]
gh-117657: Enable test_opcache under TSAN (GH-129831)
Fix a few thread-safety bugs to enable test_opcache when run with TSAN:
* Use relaxed atomics when clearing `ht->_spec_cache.getitem`
(gh-115999)
* Add temporary suppression for type slot modifications (gh-127266)
* Use atomic load when reading `*dictptr`
Add a helper for raising DB-API compatible exceptions based on the
result code of SQLite C APIs. Some APIs do not store the error indicator
on the database pointer, so we need to be able to deduce the DB-API
compatible exception directly from the error code.
- rename _pysqlite_seterror() as set_error_from_db()
- introduce set_error_from_code()
s-hamann [Mon, 10 Feb 2025 12:34:27 +0000 (12:34 +0000)]
gh-127712: Fix `secure` argument of `logging.handlers.SMTPHandler` (GH-127726)
GH-127712: Fix `secure` argument of `logging.handlers.SMTPHandler`
Python 3.12 removed support for the `keyfile` and `certfile` parameters
in `smtplib.SMTP.starttls()`, requiring a `ssl.SSLContext` instead.
`SMTPHandler` now creates a context from the `secure` tuple and passes
that to `starttls`.
Bénédikt Tran [Mon, 10 Feb 2025 10:02:47 +0000 (11:02 +0100)]
gh-111178: fix UBSan failures in `Modules/_dbmmodule.c` (#129775)
This fixes UBSan failures for `dbmobject`.
In addition, we perform some minor cleanup changes such as renaming
some `args` parameter to `dummy` in some `METH_NOARGS` methods and
suppressing an unused return value in `_dbm_module_free`.
Move pathlib's private `CopyReader`, `LocalCopyReader`, `CopyWriter` and
`LocalCopyWriter` classes into `pathlib._os`, where they can live alongside
the low-level copying functions (`copyfileobj()` etc) and high-level path
querying interface (`PathInfo`).
This sets the stage for merging `LocalCopyReader` into `PathInfo`.
No change of behaviour; just moving some code around.
Stan Ulbrych [Sun, 9 Feb 2025 08:17:35 +0000 (08:17 +0000)]
gh-129873: IDLE: Improve help.py's method of parsing HTML (#129859)
In `help.copy_strip`, only copy the text `<section>`. In `help.HelpParser.handle_starttag` and elsewhere, remove code to skip the no longer present html. Add a reminder at the top of idle.rst to run copy_strip after changes.
---------
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Stan Ulbrych [Sat, 8 Feb 2025 19:26:07 +0000 (19:26 +0000)]
gh-129699: Add description to IDLE doc title (#129727)
Also extend the 'idlelib' section header. These additions affect both the displayed idle.html file and the contents.html file displayed by clicking the Complete table of contents link on the main docs.python.org page. (The module index entries are generated from the module name and synopsis within module files.)
---------
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Brian Ward [Sat, 8 Feb 2025 13:02:36 +0000 (08:02 -0500)]
gh-119349: Add ctypes.util.dllist -- list loaded shared libraries (GH-122946)
Add function to list the currently loaded libraries to ctypes.util
The dllist() function calls platform-specific APIs in order to
list the runtime libraries loaded by Python and any imported modules.
On unsupported platforms the function may be missing.
Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Barney Gale [Sat, 8 Feb 2025 06:47:09 +0000 (06:47 +0000)]
GH-129835: Yield path with trailing slash from `ReadablePath.glob('')` (#129836)
In the private pathlib ABCs, make `ReadablePath.glob('')` yield a path with
a trailing slash (if it yields anything at all). As a result, `glob()`
works similarly to `joinpath()` when given a non-magic pattern.
In the globbing implementation, we preemptively add trailing slashes to
intermediate paths if there are pattern parts remaining; this removes the
need to check for existing trailing slashes (in the removed `add_slash()`
method) at subsequent steps.
Add `pathlib.Path.info` attribute, which stores an object implementing the `pathlib.types.PathInfo` protocol (also new). The object supports querying the file type and internally caching `os.stat()` results. Path objects generated by `Path.iterdir()` are initialised with status information from `os.DirEntry` objects, which is gleaned from scanning the parent directory.
The `PathInfo` protocol has four methods: `exists()`, `is_dir()`, `is_file()` and `is_symlink()`.
Cody Maloney [Fri, 7 Feb 2025 11:06:11 +0000 (03:06 -0800)]
gh-129005: Align FileIO.readall between _pyio and _io (#129705)
Utilize `bytearray.resize()` and `os.readinto()` to reduce copies
and match behavior of `_io.FileIO.readall()`.
There is still an extra copy which means twice the memory required
compared to FileIO because there isn't a zero-copy path from
`bytearray` -> `bytes` currently.
On my system reading a 2 GB file:
`./python -m test -M8g -uall test_largefile -m test.test_largefile.PyLargeFileTest.test_large_read -v`
Goes from ~2.7 seconds -> ~2.2 seconds
Co-authored-by: Victor Stinner <vstinner@python.org>