Commit Graph

14322 Commits

Author SHA1 Message Date
Victor Stinner bf8b374639
gh-111495: Add more tests on PyEval C APIs (#122789)
* Add Lib/test/test_capi/test_eval.py
* Add Modules/_testlimitedcapi/eval.c
2024-08-08 14:16:20 +02:00
Erlend E. Aasland e006c7371d
gh-105201: Add PyIter_NextItem() (#122331)
Return -1 and set an exception on error; return 0 if the iterator is
exhausted, and return 1 if the next item was fetched successfully.

Prefer this API to PyIter_Next(), which requires the caller to use
PyErr_Occurred() to differentiate between iterator exhaustion and errors.

Co-authered-by: Irit Katriel <iritkatriel@yahoo.com>
2024-08-08 00:47:15 +02:00
Serhiy Storchaka 540fcc62f5
gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
2024-08-07 23:30:10 +03:00
Lucas Esposito 0bd93755f3
gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation (GH-122047) 2024-08-07 16:07:26 +01:00
Victor Stinner 4767a6e31c
gh-122728: Fix SystemError in PyEval_GetLocals() (#122735)
Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.

Add an unit test on PyEval_GetLocals().
2024-08-06 23:01:44 +02:00
Sergey B Kirpichev 0b433aa9df
gh-122681: merge m_atan2() and c_atan2() helper functions (#122682) 2024-08-06 14:43:13 +02:00
Kirill Podoprigora 94a4bd79a7
gh-122704: Fix reference leak in Modules/_pickle.c (GH-122705) 2024-08-06 08:57:36 +03:00
Serhiy Storchaka 1bb955a2fe
gh-122459: Optimize pickling by name objects without __module__ (GH-122460) 2024-08-05 16:21:32 +03:00
Sergey B Kirpichev e6fad7a0e3
gh-122637: fix tanh(±0+infj) and tanh(±0+nanj) to return ±0+nanj (#122638)
As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
2024-08-04 10:05:30 +01:00
Sergey B Kirpichev 3462a80d2c
gh-121889: cmath.acosh(0+nanj) returns nan+pi/2j (#121892)
As per C11 DR#471 (adjusted resolution accepted for C17), cacosh (0 +
iNaN) should return NaN ± i pi/2, not NaN + iNaN.  This patch
fixes cmath's code to do same.
2024-08-04 09:53:17 +01:00
Sam Gross b5e6fb39a2
gh-120974: Make asyncio `swap_current_task` safe in free-threaded build (#122317)
* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
2024-08-02 19:02:08 +05:30
Victor Stinner addbb73927
Update PyObject_Del() documentation (#122597)
Replace PyMem_Del() with PyMem_Free().
2024-08-02 12:13:33 +02:00
Victor Stinner fda6bd842a
Replace PyObject_Del with PyObject_Free (#122453)
PyObject_Del() is just a alias to PyObject_Free() kept for backward
compatibility. Use directly PyObject_Free() instead.
2024-08-01 14:12:33 +02:00
Malcolm Smith 06656e259b
gh-116622: Don't expose `FICLONE` ioctl on Android (#122522)
Don't expose `FICLONE` ioctl on Android

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2024-08-01 00:23:10 +00:00
Cody Maloney a9344cdffa
gh-121381 Remove subprocess._USE_VFORK escape hatch (#121383)
This flag was added as an escape hatch in gh-91401 and backported to
Python 3.10. The flag broke at some point between its addition and now.
As there is currently no publicly known environments that require this,
remove it rather than work on fixing it.

This leaves the flag in the subprocess module to not break code which
may have used / checked the flag itself.

discussion: https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/2
2024-07-30 18:39:54 -07:00
Serhiy Storchaka 68840e91ac
gh-122311: Fix a refleak in pickle (GH-122411) 2024-07-29 21:52:48 +03:00
Serhiy Storchaka 3b034d26eb
gh-122311: Fix some error messages in pickle (GH-122386) 2024-07-29 11:49:13 +03:00
Peter Bierma c08696286f
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (#122338) 2024-07-27 11:57:48 +05:30
Marc Mueller aef95eb107
gh-121489: Export private _PyBytes_Join() again (#122267) 2024-07-25 17:31:30 +02:00
Serhiy Storchaka dc07f65a53
gh-82951: Fix serializing by name in pickle protocols < 4 (GH-122149)
Serializing objects with complex __qualname__ (such as unbound methods and
nested classes) by name no longer involves serializing parent objects by value
in pickle protocols < 4.
2024-07-25 08:45:19 +00:00
Mikołaj Kuranowski a3327dbfd4
gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) 2024-07-25 10:04:47 +03:00
Mark Shannon e55b05f29e
GH-121832: Assert that the version number of static builtin types is not changed by PyType_Modified. (GH-122182)
Update datetime module and test_type_cache.py to not call PyType_Modified.
2024-07-24 10:22:51 +01:00
Sam Gross a15feded71
gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (#122139)
* gh-120974: Make _asyncio._leave_task atomic in the free-threaded build

Update `_PyDict_DelItemIf` to allow for an argument to be passed to the
predicate.
2024-07-23 17:06:03 +00:00
Serhiy Storchaka e6b25e9a09
gh-122163: Add notes for JSON serialization errors (GH-122165)
This allows to identify the source of the error.
2024-07-23 20:02:54 +03:00
Sam Gross c908d1f87d
gh-120974: Use common freelist code in asyncio (#122132)
This refactors asyncio to use the common freelist helper functions and
macros. As a side effect, the freelist for _asyncio.Future is now
re-enabled in the free-threaded build.
2024-07-23 21:54:24 +05:30
Sam Gross 47847aa8ef
gh-120974: Make _asyncio._enter_task atomic in the free-threaded build (#122138)
Use `PyDict_SetDefaultRef` to set the current task in a single operation
under the dictionary's lock.
2024-07-23 14:17:14 +05:30
Łukasz Langa dc93d1125f
gh-121957: Emit audit events for `python -i` and `python -m asyncio` (GH-121958)
Relatedly, emit the `cpython.run_startup` event from the Python version of
`PYTHONSTARTUP` handling.
2024-07-22 13:04:08 +02:00
Sam Gross 97248204a1
gh-121621: Disable asyncio freelist in free-threaded build (#122046)
The futureobj freelist isn't thread-safe. We intend to re-enable the
freelist in a thread-safe way for 3.14 (but not 3.13).
2024-07-19 15:26:29 -04:00
mpage e059aa6b01
gh-120973: Fix thread-safety issues with `threading.local` (#121655)
This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.

This should also fix gh-118490.
2024-07-19 13:22:02 -04:00
Rodrigo Oliveira d66b06107b
gh-118830: Bump pickle.DEFAULT_PROTOCOL to 5 (GH-119340) 2024-07-19 16:47:10 +02:00
Serhiy Storchaka 1a0c7b9ba4
gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
Tian Gao eaf094c09b
gh-120289: Add external timer in traverse of _lsprof.Profiler (#121998) 2024-07-18 20:46:24 -07:00
Tian Gao 1ab1778283
gh-120289: Disallow disable() and clear() in external timer to prevent use-after-free (#120297) 2024-07-18 12:47:22 -07:00
Sam Gross 81fd625b5c
gh-121621: Move asyncio_running_loop to private struct (#121939)
This avoids changing the ABI and keeps the field in the private struct.
2024-07-17 15:21:24 -07:00
sobolevn f4bc84d261
gh-121925: Fix uninitialized variables in `main.c` (#121926) 2024-07-17 16:13:37 +00:00
Alex Waygood ac07451116
gh-120678: pyrepl: Include globals from modules passed with `-i` (GH-120904)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-17 16:18:42 +02:00
Ken Jin 69c68de43a
gh-121621: Move asyncio running loop to thread state (GH-121695) 2024-07-17 01:09:58 +08:00
Petr Viktorin b4aedb23ae
gh-113993: Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (#121364)
* Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs

* Document immortality in some functions that take `const char *`

This is PyUnicode_InternFromString;
PyDict_SetItemString, PyObject_SetAttrString;
PyObject_DelAttrString; PyUnicode_InternFromString;
and the PyModule_Add convenience functions.

Always point out a non-immortalizing alternative.

* Don't immortalize user-provided attr names in _ctypes
2024-07-16 15:36:21 +02:00
sobolevn 8b6d475581
gh-121791: Check for `NULL` in `MethodDescriptor2_new` in `_testcapi` (#121792) 2024-07-16 11:29:33 +03:00
Eric Snow 8b209fd4f8
gh-76785: Expand How Interpreter Channels Handle Interpreter Finalization (gh-121805)
See 6b98b274b6 for an explanation of the problem and solution.  Here I've applied the solution to channels.
2024-07-15 19:43:59 +00:00
Eric Snow 6b98b274b6
gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-116431)
Any cross-interpreter mechanism for passing objects between interpreters must be very careful to respect isolation, even when the object is effectively immutable (e.g. int, str).  Here this especially relates to when an interpreter sends one of its objects, and then is destroyed while the inter-interpreter machinery (e.g. queue) still holds a reference to the object.

When I added interpreters.Queue, I dealt with that case (using an atexit hook) by silently removing all items from the queue that were added by the finalizing interpreter.

Later, while working on concurrent.futures.InterpreterPoolExecutor (gh-116430), I noticed it was somewhat surprising when items were silently removed from the queue when the originating interpreter was destroyed.  (See my comment on that PR.) 
 It took me a little while to realize what was going on.  I expect that users, which much less context than I have, would experience the same pain.

My approach, here, to improving the situation is to give users three options:

1. return a singleton (interpreters.queues.UNBOUND) from Queue.get() in place of each removed item
2. raise an exception (interpreters.queues.ItemInterpreterDestroyed) from Queue.get() in place of each removed item
3. existing behavior: silently remove each item (i.e. Queue.get() skips each one)

The default will now be (1), but users can still explicitly opt in any of them, including to the silent removal behavior.

The behavior for each item may be set with the corresponding Queue.put() call. and a queue-wide default may be set when the queue is created.  (This is the same as I did for "synconly".)
2024-07-15 12:49:23 -06:00
Kumar Aditya 48042c52a6
fix outdated comments in asyncio (#121783) 2024-07-15 05:59:19 +00:00
Ken Jin 5d6861ad06
gh-121621: Use PyMutex for writes to asyncio state (#121622)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-07-14 12:22:56 +00:00
Savannah Ostrowski 65fededf9c
Update retroactive comments from GH-117741 (segfault in `FutureIter_dealloc`) (GH-121638)
Address comments
2024-07-12 10:34:30 +02:00
Sam Gross e8c91d90ba
gh-121103: Put free-threaded libraries in `lib/python3.14t` (#121293)
On POSIX systems, excluding macOS framework installs, the lib directory
for the free-threaded build now includes a "t" suffix to avoid conflicts
with a co-located default build installation.
2024-07-11 16:21:37 -04:00
Sam Gross 44937d11a6
gh-121592: Make select.poll() and related objects thread-safe (#121594)
This makes select.poll() and kqueue() objects thread-safe in the
free-threaded build. Note that calling close() concurrently with other
functions is still not thread-safe due to races on file descriptors
(gh-121544).
2024-07-11 10:21:09 -04:00
Irit Katriel 6557af6698
gh-121554: remove unnecessary internal functions in compile.c (#121555)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
2024-07-10 23:48:37 +01:00
Eric Snow 35a67e36aa
gh-121596: Fix Sharing Interpreter Channels (gh-121597)
This fixes a mistake in gh-113012 and adds a test that verifies the fix.
2024-07-10 21:31:09 +00:00
Sam Gross 1d3cf79a50
gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388)
The `_PySeqLock_EndRead` function needs an acquire fence to ensure that
the load of the sequence happens after any loads within the read side
critical section. The missing fence can trigger bugs on macOS arm64.

Additionally, we need a release fence in `_PySeqLock_LockWrite` to
ensure that the sequence update is visible before any modifications to
the cache entry.
2024-07-08 14:52:07 -04:00
Max Muoto 5289550b33
gh-121374: Correct docstrings in `_interpchannels` (gh-121418) 2024-07-08 10:32:17 -06:00