Commit graph

1372 commits

Author SHA1 Message Date
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
Bénédikt Tran
de13293d26
gh-111178: fix UBSan failures in Modules/posixmodule.c (GH-129788)
Fix UBSan failures for `DirEntry`, `ScandirIterator`
Use better semantic naming
2025-02-24 13:20:49 +01:00
Victor Stinner
df4a2f5bd7
gh-129539: Reorganize posixmodule.c header (#129558)
Add sections: Python includes, system includes, etc.

Add a comment explaining why an include is needed.
2025-02-02 09:16:48 +00:00
Victor Stinner
3447f4a56a
gh-129354: Use PyErr_FormatUnraisable() function (#129514)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
2025-01-31 14:20:35 +01:00
Victor Stinner
3bebe46d34
gh-128911: Add PyImport_ImportModuleAttr() function (#128912)
Add PyImport_ImportModuleAttr() and
PyImport_ImportModuleAttrString() functions.

* Add unit tests.
* Replace _PyImport_GetModuleAttr()
  with PyImport_ImportModuleAttr().
* Replace _PyImport_GetModuleAttrString()
  with PyImport_ImportModuleAttrString().
* Remove "pycore_import.h" includes, no longer needed.
2025-01-30 11:17:29 +00:00
Cody Maloney
1ed4487968
gh-129205: Add os.readinto() API for reading data into a caller provided buffer (#129211)
Add a new OS API which will read data directly into a caller provided
writeable buffer protocol object.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-01-26 14:21:03 +01:00
Victor Stinner
939df0f9f6
gh-58689: Fix os.kill() error handling on Windows (#128932) 2025-01-17 13:30:40 +01:00
Erlend E. Aasland
e08b28235a
gh-127614: Correctly check for ttyname_r() in configure (#128503)
PR #14868 replaced the ttyname() call with ttyname_r(), but the old
check remained.
2025-01-07 22:42:36 +01:00
RUANG (James Roy)
ea578fc6d3
gh-127688: Add SCHED_DEADLINE and SCHED_NORMAL constants to os module (GH-127689) 2024-12-19 14:51:21 +01:00
Hood Chatham
25eee578c8
gh-127627: Add posix._emscripten_debugger function (#127628)
Add a posix._emscripten_debugger function to add an emscripten breakpoint.
2024-12-06 10:47:51 +08:00
Victor Stinner
fcbe6ecdb6
gh-93312: Include <sys/pidfd.h> to get PIDFD_NONBLOCK (#127593) 2024-12-05 10:39:44 +01:00
Malcolm Smith
c5c9286804
gh-118201: Simplify conv_confname (#126089) 2024-11-19 10:42:19 -05:00
Sam Gross
5610860840
gh-126688: Reinit import lock after fork (#126692)
The PyMutex implementation supports unlocking after fork because we
clear the list of waiters in parking_lot.c. This doesn't work as well
for _PyRecursiveMutex because on some systems, such as SerenityOS, the
thread id is not preserved across fork().
2024-11-12 15:53:58 -05:00
Serhiy Storchaka
d3840503b0
gh-126303: Fix pickling and copying of os.sched_param objects (GH-126336) 2024-11-05 08:23:17 +02:00
Bénédikt Tran
f6cc7c8bd0
gh-94512: Fix forced arg format in posixmodule.c clinic code (#122516) 2024-10-26 23:40:31 +02:00
Jelle Zijlstra
cc2938a189
gh-124917: Allow keyword args to os.path.exists/lexists on Windows (#124918) 2024-10-11 12:41:59 -07:00
Malcolm Smith
c58c572a65
gh-123014: Disable pidfd API on older Android versions (#124458) 2024-09-25 16:23:30 +02:00
sobolevn
3e36e5aef1
gh-123797: Check for runtime availability of ptsname_r on macos (#123806) 2024-09-20 09:30:27 +03:00
sobolevn
3b6bfa77aa
gh-102511: Change the os.path.splitroot param name from path back to p (GH-124097) 2024-09-18 15:17:32 +01:00
Wulian
9e108b8719
Fix typos in docs, error messages and comments (#123336)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-08-28 14:41:04 +03:00
Serhiy Storchaka
1a0c7b9ba4
gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
Nikita Sobolev
3df2022931
gh-120586: Fix several "unused function" warnings in posixmodule.c (#120588) 2024-06-17 09:44:13 +03:00
Victor Stinner
7aff2de62b
gh-120057: Add os.environ.refresh() method (#120059) 2024-06-10 16:34:17 +00:00
Sam Gross
e21057b999
gh-117657: Fix TSAN race involving import lock (#118523)
This adds a `_PyRecursiveMutex` type based on `PyMutex` and uses that
for the import lock. This fixes some data races in the free-threaded
build and generally simplifies the import lock code.
2024-06-06 13:40:58 -04:00
Pablo Galindo Salgado
d9095194dd
gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-06-04 20:32:43 +02:00
Serhiy Storchaka
7111d9605f
gh-89928: Fix integer conversion of device numbers (GH-31794)
Fix os.major(), os.minor() and os.makedev().
Support device numbers larger than 2**63-1.
Support non-existent device number (NODEV).
2024-06-04 19:36:37 +03:00
Nice Zombies
96b392df30
gh-118263: Add additional arguments to path_t (Argument Clinic type) in posixmodule (GH-118355) 2024-05-24 19:04:17 +01:00
Nice Zombies
b64182550f
gh-118507 : Refactor nt._path_is* to improve applicability for other cases (GH-118755) 2024-05-21 21:36:36 +01:00
Steve Dower
94591dca51
gh-118486: Simplify test_win32_mkdir_700 to check the exact ACL (GH-119056) 2024-05-15 11:59:41 +01:00
Steve Dower
8af84b503d
gh-118773: Use language-invariant SDDL string instead of aliases for ACLs. (GH-118800) 2024-05-09 17:43:21 +01:00
Brett Simmers
c2627d6eea
gh-116322: Add Py_mod_gil module slot (#116882)
This PR adds the ability to enable the GIL if it was disabled at
interpreter startup, and modifies the multi-phase module initialization
path to enable the GIL when loading a module, unless that module's spec
includes a slot indicating it can run safely without the GIL.

PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went
with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148.

A warning will be issued up to once per interpreter for the first
GIL-using module that is loaded. If `-v` is given, a shorter message
will be printed to stderr every time a GIL-using module is loaded
(including the first one that issues a warning).
2024-05-03 11:30:55 -04:00
Steve Dower
8ed5466795
gh-118486: Switch mkdir(mode=0o700) on Windows to use OWNER RIGHTS instead of CURRENT_USER (GH-118515) 2024-05-02 19:43:54 +01:00
Steve Dower
81939dad77
gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488) 2024-05-02 15:20:43 +01:00
Nice Zombies
9a75d56d5d
gh-118379: Use PyTuple_Pack instead of Py_BuildValue if possible (GH-118381) 2024-04-30 17:55:15 +03:00
Nice Zombies
10bb90ed49
gh-102511: Speed up os.path.splitroot() with native helpers (GH-118089) 2024-04-25 10:07:38 +01:00
Steve Dower
985917dc8d
gh-117267: Ensure DirEntry.stat().st_ctime still contains creation time during deprecation period (GH-117354) 2024-04-03 23:14:55 +01:00