Commit graph

1407 commits

Author SHA1 Message Date
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
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
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
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
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
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
mdehoon
baf45159e5
fix typo in comments PyOS_CallInputHook -> PyOS_InputHook (#140237) 2025-10-20 14:25:57 +05:30
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
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
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
Victor Stinner
35e9d41a9c
gh-139482: Add posix._clearenv() function (#139965) 2025-10-11 22:58:43 +02:00
Kumar Aditya
b881df47ff
gh-139894: fix incorrect sharing of current task while forking in asyncio (#139897)
Fix incorrect sharing of current task with the forked child process by clearing thread state's current task and current loop in `PyOS_AfterFork_Child`.
2025-10-10 21:58:23 +05:30
Nadeshiko Manju
7cafd76a7f
gh-139184: Set O_CLOEXEC for master_fd when calling os.forkpty() (#139408)
Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-10 10:56:10 +02:00
Bénédikt Tran
b04a57deef
gh-139748: fix leaks in AC error paths when using unicode FS-based converters (#139765) 2025-10-08 20:52:44 +05:30
Victor Stinner
4e7e2dd043
gh-139322: Reenable test_os.test_getlogin() (#139498)
Fix also getlogin() errno.
2025-10-02 20:51:57 +00:00
Serhiy Storchaka
1a2e00c97a
gh-67795: Accept any real numbers as timestamp and timeout (GH-139224)
Functions that take timestamp or timeout arguments now accept any
real numbers (such as Decimal and Fraction), not only integers or floats,
although this does not improve precision.
2025-09-23 21:31:42 +03:00
Benjamin Peterson
e163fbdeda
fixes gh-139090: add os.RWF_DONTCACHE (#139091) 2025-09-18 08:13:23 -07:00
Serhiy Storchaka
a003112821
gh-138712: Add os.NODEV (GH-138728) 2025-09-15 14:36:32 +00:00
Serhiy Storchaka
43013f72f0
gh-138779: Use the dev_t converter for st_rdev (GH-138780)
This allows to support device numbers larger than 2**63-1.
2025-09-15 17:07:34 +03:00
Victor Stinner
af386fd361
gh-129813, PEP 782: Use PyBytesWriter in posix extension (#138829)
Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize()
with the new public PyBytesWriter API.
2025-09-13 18:57:46 +02:00
Bénédikt Tran
4978bfca10
gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to several internal types (#138582)
The following types are now immutable:

* `_curses_panel.panel`,
* `[posix,nt].ScandirIterator`, `[posix,nt].DirEntry` (exposed in `os.py`),
* `_remote_debugging.RemoteUnwinder`,
* `_tkinter.Tcl_Obj`, `_tkinter.tkapp`, `_tkinter.tktimertoken`,
* `zlib.Compress`, and `zlib.Decompress`.
2025-09-11 09:56:20 +02:00
Victor Stinner
6b7b9d00a9
gh-138535: Pass directly state to posix fill_time() (#138693)
Pass directly the module state instead of passing the module to avoid
a call to get_posix_state().
2025-09-09 16:31:13 +02:00
Jeffrey Bosboom
d4825ac27c
gh-138535: Optimize fill_time for typical timestamps (#138537)
While file timestamps can be anything the file system can store, most
lie between the recent past and the near future.  Optimize fill_time()
for typical timestamps in three ways:

- When possible, convert to nanoseconds with C arithmetic.
- When using C arithmetic and the seconds member is not required (for
  st_birthtime), avoid creating a long object.
- When using C arithmetic, reorder the code to avoid the null checks
  implied in Py_XDECREF().

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-09-09 11:05:54 +02:00
Christoph Walcher
ed53c63769
gh-138401: Check arg count>=0 in os.sendfile() (#138403)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-09-05 09:16:55 +00:00
Adam Turner
98b4cd6fe9
GH-135763: AC: Use `Py_ssize_t(allow_negative=False)` (#138394) 2025-09-02 21:29:05 +01:00
Victor Stinner
aec006be97
gh-135755: Make Py_MAX_SCRIPT_PATH_SIZE private (#138350) 2025-09-01 20:01:01 +01:00
Jakub Kulík
bbcb75c986
bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374) 2025-08-27 20:41:14 +03:00
Rani Pinchuk
fd8f42d3d1
gh-135427: Fix DeprecationWarning for os.fork when run in threads with -Werror (GH-136796)
Don't ignore errors raised by `PyErr_WarnFormat` in `warn_about_fork_with_threads`
Instead, ignore the warnings in all test code that forks. (That's a lot of functions.)

In `test_support`, make `ignore_warnings` a context manager (as well as decorator),
and add a `message` argument to it.
Also add a `ignore_fork_in_thread_deprecation_warnings` helper for the deadlock-in-fork
warning.
2025-08-26 15:33:21 +02:00
Adam Turner
918e3ba6c0
GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
Adam Turner
6baf552484
GH-137623: Begin enforcing docstring length in Argument Clinic (#137624) 2025-08-12 20:17:35 +00:00
sobolevn
99cdf1deb6
gh-136437: Make several functions in os.path pos-only (#136949) 2025-07-23 14:56:02 +03:00
Hood Chatham
c933a6bb32
gh-124621: Emscripten: Support pyrepl in browser (GH-136931)
Basic support for pyrepl in Emscripten. Limitations:
* requires JSPI
* no signal handling implemented

As followup work, it would be nice to implement a webworker variant
for when JSPI is not available and proper signal handling.

Because it requires JSPI, it doesn't work in Safari. Firefox requires
setting an experimental flag. All the Chromiums have full support since
May. Until we make it work without JSPI, let's keep the original web_example
around.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Éric <merwok@netwok.org>
2025-07-22 12:13:38 +02:00
Harmen Stoppels
bde808ad6b
gh-136710: Fix bad indentation in os.chdir docstring (GH-136709) 2025-07-16 15:30:10 +00:00
Petr Viktorin
a1da208eec
gh-131591: Add Py_ prefix to MAX_SCRIPT_PATH_SIZE; remove unprefixed struct tag (GH-135924)
Names/macros defined in public headers should have `Py`/`_Py` prefixes.
2025-06-26 09:25:41 +02:00
Furkan Onder
5b3865418c
gh-135108: Fix utmp.h inclusion in posixmodule.c on NetBSD (GH-135109) 2025-06-04 08:51:18 -04:00
Duane Griffin
1ffe913c20
gh-127081: use getlogin_r if available (gh-132751)
The `getlogin` function is not thread-safe: replace with `getlogin_r` where
available.
2025-06-03 13:28:58 -04:00
Max Bachmann
74c4e35ff1
Let PyUnicode_FromWideChar calculate the input length (GH-134045) 2025-05-15 11:56:50 +00:00
Max Bachmann
e528aef7e2
gh-133562: Skip security descriptors on unsupported Windows API partitions (GH-133563) 2025-05-14 11:34:41 +00:00
Max Bachmann
1460ccefd0
gh-133537: Avoid using console I/O in WinAPI partitions that don't support it (GH-133538) 2025-05-07 20:47:05 +01:00
Max Bachmann
427f8c366d
gh-133517: Remove os.listdrive, os.listvolumes and os.listmounts in non-desktop Windows builds (GH-133518) 2025-05-07 20:45:42 +01:00
Wulian233
b6c2ef0c7a
gh-131296: Avoid posixmodule.c warning (GH-133142)
Clang-cl detects that on 32-bit builds the variable is always smaller than the value. But since the same code is used for other architectures, we can't just _fix_ it. This cast avoids the tautological-constant-out-of-range-compare warning.
2025-05-05 17:45:15 +01:00
Serhiy Storchaka
5a57248b22
gh-81793: Always call linkat() from os.link(), if available (GH-132517)
This fixes os.link() on platforms (like Linux and OpenIndiana) where the
system link() function does not follow symlinks.

* On Linux, it now follows symlinks by default and if
  follow_symlinks=True is specified.
* On Windows, it now raises error if follow_symlinks=True is passed.
* On macOS, it now raises error if follow_symlinks=False is passed and
  the system linkat() function is not available at runtime.
* On other platforms, it now raises error if follow_symlinks is passed
  with a value that does not match the system link() function behavior
  if if the behavior is not known.

Co-authored-by: Joachim Henke <37883863+jo-he@users.noreply.github.com>
Co-authored-by: Thomas Kluyver <takowl@gmail.com>
2025-05-04 17:24:10 +03:00
Serhiy Storchaka
07edc0d2b2
gh-132987: Support __index__() in the posix module (GH-133096)
Support it for the dev_t values in mknod(), major(), minor() and makedev(),
CPU numbers in sched_setaffinity(), group numbers in setgroups(),
configuration name in fpathconf(), pathconf(), confstr(), and sysconf().
2025-04-29 16:14:47 +03:00
Nadeshiko Manju
3a39e33ee4
gh-131591: Reset RemoteDebuggerSuupport state after fork (#132793)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2025-04-25 01:40:01 +01:00
Chris Eibl
7cbcb6efd9
GH-131296: Fix parenthesis warnings on Windows-specific code (GH-131905) 2025-03-31 15:54:30 +01:00
Victor Stinner
486d537065
Fix Windows build warnings (#131487)
Fix the following warnings:

* Modules\_io\fileio.c(1296,13): unused variable 'self'
* Modules\_io\winconsoleio.c(334,9): unused variable 'fd_is_own'
* Modules\faulthandler.c(409,11): unused variable 'flags'
* Modules\posixmodule.c(5699,9): unused variable 'pathError'
* PC\winreg.c(2077,5): suggest braces around initialization of
  subobject
* PC\winreg.c(34,13): unused variable 'errNotAHandle'
* Python\fileutils.c(132,12): result of comparison of constant
  1114111 with expression of type 'wchar_t' (aka 'unsigned short') is
  always false
* Python\fileutils.c(58,21): unused variable 'INCOMPLETE_CHARACTER'
* Python\sysmodule.c(2534,21): unused variable 'perf_map_state'
2025-03-20 12:03:20 +01:00
Victor Stinner
20c5f969dd
gh-131238: Remove more includes from pycore_interp.h (#131480) 2025-03-19 23:01:32 +01:00
Sam Gross
052cb717f5
gh-124878: Fix race conditions during interpreter finalization (#130649)
The PyThreadState field gains a reference count field to avoid
issues with PyThreadState being a dangling pointer to freed memory.
The refcount starts with a value of two: one reference is owned by the
interpreter's linked list of thread states and one reference is owned by
the OS thread. The reference count is decremented when the thread state
is removed from the interpreter's linked list and before the OS thread
calls `PyThread_hang_thread()`. The thread that decrements it to zero
frees the `PyThreadState` memory.

The `holds_gil` field is moved out of the `_status` bit field, to avoid
a data race where on thread calls `PyThreadState_Clear()`, modifying the
`_status` bit field while the OS thread reads `holds_gil` when
attempting to acquire the GIL.

The `PyThreadState.state` field now has `_Py_THREAD_SHUTTING_DOWN` as a
possible value. This corresponds to the `_PyThreadState_MustExit()`
check. This avoids race conditions in the free threading build when
checking `_PyThreadState_MustExit()`.
2025-03-06 10:38:34 -05:00