summaryrefslogtreecommitdiffstats
path: root/Modules
Commit message (Collapse)AuthorAgeFilesLines
...
* gh-117068: Remove useless code in bytesio.c:resize_buffer() (GH-117069)NGRsoftlab2024-03-221-3/+0
| | | Co-authored-by: i.khabibulin <i.khabibulin@ngrsoftlab.ru>
* gh-105716: Fix _PyInterpreterState_IsRunningMain() For Embedders (gh-117140)Eric Snow2024-03-221-2/+20
| | | | | When I added _PyInterpreterState_IsRunningMain() and friends last year, I tried to accommodate applications that embed Python but don't call _PyInterpreterState_SetRunningMain() (not that they're expected to). That mostly worked fine until my recent changes in gh-117049, where the subtleties with the fallback code led to failures; the change ended up breaking test_tools.test_freeze, which exercises a basic embedding situation. The simplest fix is to drop the fallback code I originally added to _PyInterpreterState_IsRunningMain() (and later to _PyThreadState_IsRunningMain()). I've kept the fallback in the _xxsubinterpreters module though. I've also updated Py_FrozenMain() to call _PyInterpreterState_SetRunningMain().
* gh-116522: Refactor `_PyThreadState_DeleteExcept` (#117131)Sam Gross2024-03-211-0/+8
| | | | | | | | | | | Split `_PyThreadState_DeleteExcept` into two functions: - `_PyThreadState_RemoveExcept` removes all thread states other than one passed as an argument. It returns the removed thread states as a linked list. - `_PyThreadState_DeleteList` deletes those dead thread states. It may call destructors, so we want to "start the world" before calling `_PyThreadState_DeleteList` to avoid potential deadlocks.
* gh-76785: Drop PyInterpreterID_Type (gh-117101)Eric Snow2024-03-215-25/+141
| | | I added it quite a while ago as a strategy for managing interpreter lifetimes relative to the PEP 554 (now 734) implementation. Relatively recently I refactored that implementation to no longer rely on InterpreterID objects. Thus now I'm removing it.
* gh-115754: Add Py_GetConstant() function (#116883)Victor Stinner2024-03-214-1/+85
| | | | | | | | | | | | Add Py_GetConstant() and Py_GetConstantBorrowed() functions. In the limited C API version 3.13, getting Py_None, Py_False, Py_True, Py_Ellipsis and Py_NotImplemented singletons is now implemented as function calls at the stable ABI level to hide implementation details. Getting these constants still return borrowed references. Add _testlimitedcapi/object.c and test_capi/test_object.py to test Py_GetConstant() and Py_GetConstantBorrowed() functions.
* gh-105716: Update interp->threads.main After Fork (gh-117049)Eric Snow2024-03-211-0/+4
| | | | | I missed this in gh-109921. We also update Py_Exit() to call _PyInterpreterState_SetNotRunningMain(), if necessary.
* gh-76785: Clean Up Interpreter ID Conversions (gh-117048)Eric Snow2024-03-213-108/+32
| | | Mostly we unify the two different implementations of the conversion code (from PyObject * to int64_t. We also drop the PyArg_ParseTuple()-style converter function, as well as rename and move PyInterpreterID_LookUp().
* gh-116522: Stop the world before fork() and during shutdown (#116607)Sam Gross2024-03-211-7/+21
| | | | | | | | | | | This changes the free-threaded build to perform a stop-the-world pause before deleting other thread states when forking and during shutdown. This fixes some crashes when using multiprocessing and during shutdown when running with `PYTHON_GIL=0`. This also changes `PyOS_BeforeFork` to acquire the runtime lock (i.e., `HEAD_LOCK(&_PyRuntime)`) before forking to ensure that data protected by the runtime lock (and not just the GIL or stop-the-world) is in a consistent state before forking.
* gh-114314: ctypes: remove stgdict and switch to heap types (GH-116458)Petr Viktorin2024-03-206-1404/+1402
| | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, ctypes classes used a custom dict subclass, `StgDict`, as their `tp_dict`. This acts like a regular dict but also includes extra information about the type. This replaces stgdict by `StgInfo`, a C struct on the type, accessed by `PyObject_GetTypeData()` (PEP-697). All usage of `StgDict` (mainly variables named `stgdict`, `dict`, `edict` etc.) is converted to `StgInfo` (named `stginfo`, `info`, `einfo`, etc.). Where the dict is actually used for class attributes (as a regular PyDict), it's now called `attrdict`. This change -- not overriding `tp_dict` -- is made to make me comfortable with the next part of this PR: moving the initialization logic from `tp_new` to `tp_init`. The `StgInfo` is set up in `__init__` of each class, with a guard that prevents calling `__init__` more than once. Note that abstract classes (like `Array` or `Structure`) are created using `PyType_FromMetaclass` and do not have `__init__` called. Previously, this was done in `__new__`, which also wasn't called for abstract classes. Since `__init__` can be called from Python code or skipped, there is a tested guard to ensure `StgInfo` is initialized exactly once before it's used. Co-authored-by: neonene <53406459+neonene@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-116773: Ensure overlapped objects on Windows are not deallocated too ↵jkriegshauser2024-03-201-0/+18
| | | | early by asyncio (GH-116774)
* gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit ↵Serhiy Storchaka2024-03-203-0/+25
| | | | platforms (GH-117064)
* gh-94808: add tests covering `PyFunction_{Get,Set}Closure` (GH-99429)Nikita Sobolev2024-03-201-0/+29
|
* GH-108362: Incremental Cycle GC (GH-116206)Mark Shannon2024-03-201-15/+10
|
* gh-113964: Don't prevent new threads until all non-daemon threads exit (#116677)Sam Gross2024-03-193-5/+7
| | | | | | | | | | Starting in Python 3.12, we prevented calling fork() and starting new threads during interpreter finalization (shutdown). This has led to a number of regressions and flaky tests. We should not prevent starting new threads (or `fork()`) until all non-daemon threads exit and finalization starts in earnest. This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`, which is set immediately before terminating non-daemon threads.
* gh-116417: Move limited C API complex.c tests to _testlimitedcapi (#117014)Victor Stinner2024-03-195-62/+84
| | | | Split complex.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
* gh-116417: Move limited C API dict.c tests to _testlimitedcapi (#117006)Victor Stinner2024-03-195-279/+297
| | | | Split dict.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
* gh-116417: Move limited C API long.c tests to _testlimitedcapi (#117001)Victor Stinner2024-03-198-895/+936
| | | | | | | * Split long.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. * Move testcapi_long.h from Modules/_testcapi/ to Modules/_testlimitedcapi/. * Add MODULE__TESTLIMITEDCAPI_DEPS to Makefile.pre.in.
* gh-116417: Move limited C API unicode.c tests to _testlimitedcapi (#116993)Victor Stinner2024-03-196-1883/+1961
| | | | | | Split unicode.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. Update test_codecs.
* gh-116417: Move limited C API abstract.c tests to _testlimitedcapi (#116986)Victor Stinner2024-03-197-647/+693
| | | | | | | Split abstract.c and float.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. Update test_bytes and test_class.
* gh-116417: Fix WASI build of _testlimitedcapi (#116974)Victor Stinner2024-03-1810-24/+26
| | | | Use different function names between _testcapi and _testlimitedcapi to not confuse the WASI linker.
* gh-116417: Move limited C API list.c tests to _testlimitedcapi (#116602)Victor Stinner2024-03-187-322/+368
| | | | | Split list.c and set.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi.
* gh-115119: Switch Windows build to mpdecimal external (GH-115182)Zachary Ware2024-03-181-0/+17
| | | | | This includes adding what should be a relatively temporary `Modules/_decimal/windows/mpdecimal.h` shim to choose between `mpdecimal32vc.h` or `mpdecimal64vc.h` based on which of `CONFIG_64` or `CONFIG_32` is defined.
* gh-115874: Don't use module state in teedataobject tp_dealloc (#116204)Erlend E. Aasland2024-03-181-5/+3
| | | Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
* gh-115538: Emit warning when use bool as fd in _io.WindowsConsoleIO (GH-116925)AN Long2024-03-181-0/+7
|
* gh-116915: Make `_thread._ThreadHandle` support GC (#116934)mpage2024-03-181-3/+13
| | | | | | Even though it has no internal references to Python objects it still has a reference to its type by virtue of being a heap type. We need to provide a traverse function that visits the type, but we do not need to provide a clear function.
* gh-85283: Build _statistics extension with the limited C API (#116927)Victor Stinner2024-03-172-35/+17
| | | | | Argument Clinic now inlines _PyArg_CheckPositional() for the limited C API. The generated code should be as fast or even a little bit faster.
* gh-85283: Build termios extension with the limited C API (#116928)Victor Stinner2024-03-172-29/+38
|
* gh-73468: Add math.fma() function (#116667)Victor Stinner2024-03-172-1/+105
| | | | | | Added new math.fma() function, wrapping C99's ``fma()`` operation: fused multiply-add function. Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
* GH-112536: Add more TSan tests (#116911)Antoine Pitrou2024-03-171-2/+2
| | | | These may all exercise some non-trivial aspects of thread synchronization.
* gh-85287: Change codecs to raise precise UnicodeEncodeError and ↵John Sloboda2024-03-171-5/+37
| | | | | UnicodeDecodeError (#113674) Co-authored-by: Inada Naoki <songofacandy@gmail.com>
* gh-114271: Fix race in `Thread.join()` (#114839)mpage2024-03-161-305/+674
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a race between when `Thread._tstate_lock` is released[^1] in `Thread._wait_for_tstate_lock()` and when `Thread._stop()` asserts[^2] that it is unlocked. Consider the following execution involving threads A, B, and C: 1. A starts. 2. B joins A, blocking on its `_tstate_lock`. 3. C joins A, blocking on its `_tstate_lock`. 4. A finishes and releases its `_tstate_lock`. 5. B acquires A's `_tstate_lock` in `_wait_for_tstate_lock()`, releases it, but is swapped out before calling `_stop()`. 6. C is scheduled, acquires A's `_tstate_lock` in `_wait_for_tstate_lock()` but is swapped out before releasing it. 7. B is scheduled, calls `_stop()`, which asserts that A's `_tstate_lock` is not held. However, C holds it, so the assertion fails. The race can be reproduced[^3] by inserting sleeps at the appropriate points in the threading code. To do so, run the `repro_join_race.py` from the linked repo. There are two main parts to this PR: 1. `_tstate_lock` is replaced with an event that is attached to `PyThreadState`. The event is set by the runtime prior to the thread being cleared (in the same place that `_tstate_lock` was released). `Thread.join()` blocks waiting for the event to be set. 2. `_PyInterpreterState_WaitForThreads()` provides the ability to wait for all non-daemon threads to exit. To do so, an `is_daemon` predicate was added to `PyThreadState`. This field is set each time a thread is created. `threading._shutdown()` now calls into `_PyInterpreterState_WaitForThreads()` instead of waiting on `_tstate_lock`s. [^1]: https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1201 [^2]: https://github.com/python/cpython/blob/441affc9e7f419ef0b68f734505fa2f79fe653c7/Lib/threading.py#L1115 [^3]: https://github.com/mpage/cpython/commit/81946532792f938cd6f6ab4c4ff92a4edf61314f --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Antoine Pitrou <antoine@python.org>
* gh-85283: Build pwd extension with the limited C API (#116841)Victor Stinner2024-03-152-5/+10
| | | | Argument Clinic now uses the PEP 737 "%T" format to format type name for the limited C API.
* gh-116195: Implements a fast path for nt.getppid (GH-116205)vxiiduu2024-03-141-2/+84
| | | | | Use the NtQueryInformationProcess system call to efficiently retrieve the parent process ID in a single step, rather than using the process snapshots API which retrieves large amounts of unnecessary information and is more prone to failure (since it makes heap allocations). Includes a fallback to the original win32_getppid implementation in case the unstable API appears to return strange results.
* gh-111696, PEP 737: Add PyType_GetModuleName() function (#116824)Victor Stinner2024-03-143-10/+10
| | | Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-111696, PEP 737: Add PyType_GetFullyQualifiedName() function (#116815)Victor Stinner2024-03-141-68/+17
| | | Rewrite tests on type names in Python, they were written in C.
* gh-116646, AC: Always use PyObject_AsFileDescriptor() in fildes (#116806)Victor Stinner2024-03-143-38/+67
| | | | | | | The fildes converter of Argument Clinic now always call PyObject_AsFileDescriptor(), not only for the limited C API. The _PyLong_FileDescriptor_Converter() converter stays as a fallback when PyObject_AsFileDescriptor() cannot be used.
* gh-116646, AC: Add CConverter.use_converter() method (#116793)Victor Stinner2024-03-141-2/+1
| | | Only add includes when the converter is effectively used.
* gh-85283: Build fcntl extension with the limited C API (#116791)Victor Stinner2024-03-142-24/+44
|
* gh-116646: Add limited C API support to AC fildes converter (#116769)Victor Stinner2024-03-142-1/+52
| | | Add tests on the "fildes" converter to _testclinic_limited.
* gh-116616: Use relaxed atomic ops to access socket module defaulttimeout ↵Erlend E. Aasland2024-03-121-5/+6
| | | | | (#116623) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-116541: Handle errors correctly in `_pystatvfs_fromstructstatvfs` (#116542)Nikita Sobolev2024-03-121-32/+36
|
* gh-85283: Convert grp extension to the limited C API (#116611)Victor Stinner2024-03-123-82/+18
| | | | posixmodule.h: remove check on the limited C API, since these helpers are not part of the public C API.
* gh-108494: Fix Argument Clinic LIMITED_CAPI_REGEX (#116610)Victor Stinner2024-03-1111-31/+21
| | | Accept spaces in "# define Py_LIMITED_API 0x030d0000".
* gh-110850: Fix _PyTime_FromSecondsDouble() API (#116606)Victor Stinner2024-03-112-22/+32
| | | | | | | | Return 0 on success. Set an exception and return -1 on error. Fix os.timerfd_settime(): properly report exceptions on _PyTime_FromSecondsDouble() failure. No longer export _PyTime_FromSecondsDouble().
* gh-116417: Build _testinternalcapi with limited C API version 3.5 (#116598)Victor Stinner2024-03-113-2/+15
|
* gh-116545: Fix error handling in `mkpwent` in `pwdmodule` (#116548)Nikita Sobolev2024-03-111-31/+30
|
* gh-116417: Move 4 limited C API test files to _testlimitedcapi (#116571)Victor Stinner2024-03-1110-24/+57
| | | | | | | | | | | | | | | | Move the following files from Modules/_testcapi/ to Modules/_testlimitedcapi/: * bytearray.c * bytes.c * pyos.c * sys.c Changes: * Replace PyBytes_AS_STRING() with PyBytes_AsString(). * Replace PyBytes_GET_SIZE() with PyBytes_Size(). * Update related test_capi tests. * Copy Modules/_testcapi/util.h to Modules/_testlimitedcapi/util.h.
* gh-116417: Fix make check-c-globals for _testlimitedcapi (#116570)Victor Stinner2024-03-101-4/+0
| | | | | * Remove unused '_testcapimodule' global in Modules/_testcapi/unicode.c. * Update c-analyzer to not use the internal C API in _testlimitedcapi.c.
* gh-116417: Avoid PyFloat_AS_DOUBLE() in AC limited C API (#116568)Victor Stinner2024-03-102-1/+119
| | | | Argument Clinic no longer calls PyFloat_AS_DOUBLE() when the usage of the limited C API is requested.
* gh-116520: Fix error handling in `os_get_terminal_size_impl` in ↵Nikita Sobolev2024-03-091-6/+17
| | | | `posixmodule` (#116521)