Commit graph

15393 commits

Author SHA1 Message Date
Serhiy Storchaka
610377056b
gh-140615: Update docstrings in the fcntl module (GH-140619)
* Refer to bytes objects or bytes-like objects instead of strings.
* Remove backticks -- they do not have effect on formatting.
* Re-wrap lines to ensure the pydoc output fits in 80 coluimns.
* Remove references to the 1024 bytes limit.
2025-11-08 12:17:59 +02:00
Victor Stinner
986bb0a1a2
gh-83714: Fix stat_nanosecond_timestamp() for 32-bit time_t (#141069) 2025-11-05 21:16:37 +01:00
Victor Stinner
f458ac01ba
Fix compiler warnings in remote debugging (#141060)
Example of fixed warnings on 32-bit Windows:

    Python\remote_debugging.c(24,53): warning C4244: 'function':
    conversion from 'uint64_t' to 'uintptr_t', possible loss of data

    Modules\_remote_debugging_module.c(789,44): warning C4244:
    'function': conversion from 'uint64_t' to 'size_t', possible loss
    of data
2025-11-05 20:18:45 +01:00
Sachin Shah
1d25b751c5
gh-140650: Fix write(), flush() and close() methods of io.BufferedWriter (GH-140653)
They could raise SystemError or crash when getting the "closed" attribute
or converting it to boolean raises an exception.
2025-11-05 21:15:27 +02:00
Victor Stinner
4ac16dd109
Fix a compiler warning in _randommodule.c (#141058)
The test just before the cast ensures that the cast cannot overflow.

Fix the warning on 32-bit Windows:

    Modules\_randommodule.c(525,28): warning C4244: '=': conversion
    from 'uint64_t' to 'Py_ssize_t', possible loss of data
2025-11-05 18:00:32 +00:00
Victor Stinner
8d55faf2d6
Remove internal _PyTime_AsLong() function (#141053)
* Replace _PyTime_AsLong() with PyLong_FromInt64()
* Replace _PyTime_FromLong() with PyLong_AsInt64().
2025-11-05 18:37:06 +01:00
Victor Stinner
30ab627aab
gh-83714: Fix a compiler warning in stat_nanosecond_timestamp() (#141043)
Disable the fast path on systems with 32-bit long.
2025-11-05 18:31:35 +01:00
Petr Viktorin
589a03a8ce
gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-05 12:31:42 +01:00
Serhiy Storchaka
1326d2a808
gh-140979: Fix off-by-one error in the RE code validator (GH-140984)
It was too lenient and allowed MARK opcodes with too large value.
2025-11-04 17:49:44 +02:00
Neil Schemenauer
c98c5b3449
gh-131253: free-threaded build support for pystats (gh-137189)
Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
2025-11-03 11:36:37 -08:00
Sergey Miryanov
da65f38a94
gh-134786: raise error if Py_TPFLAGS_MANAGED_WEAKREF or Py_TPFLAGS_MANAGED_DICT is used without Py_TPFLAGS_HAVE_GC set (#135863) 2025-11-02 16:34:49 +05:30
Serhiy Storchaka
dcf3cc5796
gh-81313: Add the math.integer module (PEP-791) (GH-133909) 2025-10-31 16:13:43 +02:00
Stan Ulbrych
a3ce2f77f0
gh-55531: Implement normalize_encoding in C (#136643)
Closes gh-55531
2025-10-30 15:31:47 +01:00
Donghee Na
c45e6e1bb3
gh-137821: Improve Argument Clinic definitions in the `_json` module (#140780) 2025-10-30 10:32:08 +00:00
Stan Ulbrych
dbe3950a76
gh-129117: Add unicodedata.isxidstart() function (#140269)
Expose `_PyUnicode_IsXidContinue/Start` in `unicodedata`:
add isxidstart() and isxidcontinue() functions.

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-30 10:18:12 +00:00
Yoonho Hann
25bd72d683
gh-137821: Convert _json module to use Argument Clinic (gh-140778) 2025-10-30 09:42:09 +00:00
Sergey Miryanov
d26686a7f8
GH-140590: Fix setstate for functools.partial C-module (GH-140671)
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
2025-10-28 10:28:32 +01:00
Serhiy Storchaka
364ae607d8
gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH-140667) 2025-10-27 21:42:32 +02:00
Cody Maloney
0f0a362768
gh-140607: Validate returned byte count in RawIOBase.read (#140611)
While `RawIOBase.readinto` should return a count of bytes between 0 and
the length of the given buffer, it is not required to. Add validation
inside RawIOBase.read() that the returned byte count is valid.

Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-27 18:06:46 +00:00
Alper
9479a62a51
gh-116738: Use PyMutex for bz2 module (gh-140555)
The methods are already wrapped with a lock, which makes them thread-safe in
free-threaded build. This replaces `PyThread_acquire_lock` with `PyMutex` and
removes some macros and allocation handling code.

Also add a test for free-threading to ensure we aren't getting data races and
that the locking is working.
2025-10-27 09:52:30 -04:00
Petr Viktorin
18e4a89e42
gh-134160: Add more comments for the xxlimited module (GH-140214) 2025-10-27 11:39:42 +01:00
Sebastian Pipping
e34a5e3304
gh-140593: Fix a memory leak in function my_ElementDeclHandler of pyexpat (#140602)
Ensure that the memory allocated for the content model
passed to `my_ElementDeclHandler` is freed in all error
paths.
2025-10-26 13:45:32 +00:00
Stan Ulbrych
00026d19c2
gh-76007: Deprecate __version__ attribute in decimal (#140302)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-10-26 12:01:04 +01:00
Shamil
2a1c9bd616
Remove unreachable break statements in _ctypes_test.c (#140585) 2025-10-25 14:59:12 +00:00
Kumar Aditya
95e5d59630
gh-140414: add fastpath for current running loop in asyncio.all_tasks (#140542)
Optimize `asyncio.all_tasks()` for the common case where the event loop is running in the current thread by avoiding stop-the-world pauses and locking.

This optimization is already present for `asyncio.current_task()` so we do the same for `asyncio.all_tasks()`.
2025-10-24 20:02:17 +05:30
Victor Stinner
5d2edf72d2
gh-83714: Set os.statx().stx_mode to None if missing from stx_mask (#140484)
* Set stx_mode to None if STATX_TYPE|STATX_MODE is missing from
  stx_mask.
* Enhance os.statx() tests.
* statx_result structure: remove atime_sec, btime_sec, ctime_sec and
  mtime_sec members. Compute them on demand when stx_atime,
  stx_btime, stx_ctime and stx_mtime are read.
* Doc: fix statx members sorting.
2025-10-23 22:35:17 +02:00
Abhishek Tiwari
f0291c3f2d
gh-140443: Use fma in loghelper to improve accuracy of log for very large integers (#140469)
* gh-140443:use fma in loghelper to improve accuracy of log for very large integers

Use fused multiply-add in log_helper() for huge ints.

Saving a rounding here is remarkably effective. Across some millions
of randomized test cases with ints up to a billion bits, on Windows
and using log10, the ULP error distribution was dramatically
flattened, and its range was nearly cut in half. In fact, the largest
error Tim saw was under 0.6 ULP.

---------

Co-authored-by: abhi210 <27881020+Abhi210@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-10-23 12:05:12 -05:00
Stan Ulbrych
aa9d0a61d5
gh-140474: Fix memory leak in array.array (GH-140478) 2025-10-23 05:49:27 -04:00
Alper
d51be28876
gh-116738: Add critical section to dbm/gdbm context manager (gh-140391) 2025-10-22 11:16:28 -04:00
Petr Viktorin
e53e9eb2f1
gh-83714: Only use STATX_MNT_ID & STATX_SUBVOL if they're defined (GH-140446) 2025-10-22 12:42:51 +02:00
Victor Stinner
7339cf7899
gh-83714: Use "stx_" prefix for all os.statx_result members (#140432)
Rename stx_birthtime to stx_btime, and rename stx_birthtime_ns to
stx_btime_ns.
2025-10-22 11:48:37 +02:00
Alper
b3a38438d8
gh-116738: Make _suggestions module thread-safe (gh-140321) 2025-10-22 09:14:48 +09:00
Stan Ulbrych
02c1abfc54
gh-69528: Distinguish between file modes "wb+" and "rb+" (GH-137834)
Co-authored-by: Xiang Zhang <angwerzx@126.com>
2025-10-21 20:33:30 +03:00
Jeffrey Bosboom
60df1d7e0c
gh-83714: Check for struct statx members in configure (#140402)
Some systems have the definitions of the mask bits without having the
corresponding members in struct statx.  Add configure checks for members
added after Linux 4.11 (when statx itself was added).
2025-10-21 18:13:14 +02:00
Shamil
e8e0f411ba
gh-140398: fix memory leaks in readline module when PySys_Audit fails (#140400) 2025-10-21 13:24:34 +05:30
Victor Stinner
3222ea0f14
gh-83714: Set os.statx() members to None if missing from stx_mask (#140216) 2025-10-20 17:59:12 +02:00
Sam Gross
f11ec6e643
gh-140263: Fix data race in test_lock_two_threads (gh-140264)
Clang-20 detects a data race between the unlock and the non-atomic
read of the lock state. Use a relaxed load for the assertion to avoid
the race.
2025-10-20 09:58:05 -04:00
mdehoon
baf45159e5
fix typo in comments PyOS_CallInputHook -> PyOS_InputHook (#140237) 2025-10-20 14:25:57 +05:30
Shamil
f9323213c9
gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) 2025-10-19 22:24:28 +03:00
Shamil
f937468e7c
gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) 2025-10-18 09:27:58 +00:00
Jeffrey Bosboom
5a31024da4
gh-83714: Check for struct statx.stx_atomic_write_unit_max_opt in configure (#140185)
stx_atomic_write_unit_max_opt was added in Linux 6.16, but is controlled
by the STATX_WRITE_ATOMIC mask bit added in Linux 6.11.  That's safe at
runtime because all kernels clear the reserved space in struct statx and
zero is a valid value for stx_atomic_write_unit_max_opt, and it avoids
allocating another mask bit, which are a limited resource.  But it also
means the kernel headers don't provide a way to check whether
stx_atomic_write_unit_max_opt exists, so add a configure check.
2025-10-16 13:40:47 +02:00
Victor Stinner
4641925bf2
Set type names earlier in posixmodule.c (#140168) 2025-10-16 12:54:57 +02:00
Serhiy Storchaka
2a2bc82cef
gh-130567: Remove optimistic allocation in locale.strxfrm() (GH-137143)
On modern systems, the result of wcsxfrm() is much larger the size of
the input string (from 4+2*n on Windows to 4+5*n on Linux for simple
ASCII strings), so optimistic allocation of the buffer of the same size
never works.

The exception is if the locale is "C" (or unset), but in that case the `wcsxfrm`
call should be fast (and calling `locale.strxfrm()` doesn't make too much
sense in the first place).
2025-10-16 09:54:41 +02:00
Jonathan Protzenko
3a81313019
gh-140120: Refresh HACL* to fix an hmac memory leak (GH-140188)
This pulls an updated version of HACL* that fixes the memory leak reported in #140120, via an upstream fix.
2025-10-16 05:25:51 +00:00
Victor Stinner
5213f1b684
gh-83714: Disable os.statx_result.stx_atomic_write_unit_max_opt (#140162)
Fix building on Centos 9 x86-64 buildbot.
2025-10-15 17:38:34 +02:00
Maurycy Pawłowski-Wieroński
d301587369
gh-140135: Use PyBytesWriter in io.RawIOBase.readall(); 4x faster (#140139) 2025-10-15 14:04:17 +00:00
yihong
a05aece543
gh-140080: Clear atexit callbacks when memory allocation fails during finalization (GH-140103)
This fixes a regression introduced by GH-136004, in which finalization would hang while executing atexit handlers if the system was out of memory.

---------

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-15 09:49:55 -04:00
Sergey Miryanov
32c264982e
gh-140061: Use _PyObject_IsUniquelyReferenced() to check if objects are uniquely referenced (gh-140062)
The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
2025-10-15 09:48:21 -04:00
Jeffrey Bosboom
fe9ac7fc8c
gh-83714: Implement os.statx() function (#139178)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-15 13:44:08 +00:00
Bénédikt Tran
27acaf1cb7
gh-139327: consolidate sqlite3_finalize and sqlite3_reset usages (GH-139329) 2025-10-15 15:18:07 +02:00