Commit Graph

14256 Commits

Author SHA1 Message Date
Miss Islington (bot) d8701e2f7e
[3.13] gh-122311: Fix a refleak in pickle (GH-122411) (GH-122415)
(cherry picked from commit 68840e91ac)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-07-29 19:16:15 +00:00
Serhiy Storchaka 9f6f8790ef
Revert "[3.13] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121144)" (GH-122408)
This reverts commit 009618f112.
2024-07-29 21:55:28 +03:00
Miss Islington (bot) c26dd270f7
[3.13] gh-122311: Fix some error messages in pickle (GH-122386) (GH-122387)
(cherry picked from commit 3b034d26eb)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-07-29 12:27:14 +03:00
Miss Islington (bot) 6b9a5af72f
[3.13] gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338) (#122344)
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338)
(cherry picked from commit c08696286f)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-07-27 12:36:50 +05:30
Miss Islington (bot) aca41cfe99
[3.13] GH-121832: Assert that the version number of static builtin types is not changed by PyType_Modified (gh-122290)
Update datetime module and test_type_cache.py to not call PyType_Modified.

(cherry picked from commit e55b05f29e, AKA gh--122182)

Co-authored-by: Mark Shannon <mark@hotpy.org>
2024-07-25 17:34:01 +00:00
Miss Islington (bot) dd270f610c
[3.13] gh-121489: Export private _PyBytes_Join() again (GH-122267) (#122287)
gh-121489: Export private _PyBytes_Join() again (GH-122267)
(cherry picked from commit aef95eb107)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-07-25 16:06:31 +00:00
Miss Islington (bot) 984f8aaa2f
[3.13] gh-82951: Fix serializing by name in pickle protocols < 4 (GH-122149) (GH-122264)
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.
(cherry picked from commit dc07f65a53)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-07-25 13:44:55 +03:00
Miss Islington (bot) 6933c4ace9
[3.13] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122258)
(cherry picked from commit a3327dbfd4)

Co-authored-by: Mikołaj Kuranowski <mkuranowski@gmail.com>
2024-07-25 07:29:36 +00:00
Miss Islington (bot) 77ab53a5f3
[3.13] gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (GH-122139) (#122186)
gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (GH-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.
(cherry picked from commit a15feded71)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-23 17:30:58 +00:00
Miss Islington (bot) 48154e7053
[3.13] gh-120974: Make _asyncio._enter_task atomic in the free-threaded build (GH-122138) (#122152)
gh-120974: Make _asyncio._enter_task atomic in the free-threaded build (GH-122138)

Use `PyDict_SetDefaultRef` to set the current task in a single operation
under the dictionary's lock.
(cherry picked from commit 47847aa8ef)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-23 09:17:52 +00:00
Miss Islington (bot) 148beb6de9
[3.13] gh-121957: Emit audit events for `python -i` and `python -m asyncio` (GH-121958) (GH-122115)
Relatedly, emit the `cpython.run_startup` event from the Python version of
`PYTHONSTARTUP` handling.
(cherry picked from commit dc93d1125f)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-22 13:36:57 +02:00
Sam Gross f3c79cb400
[3.13] gh-121621: Disable asyncio freelist in free-threaded build (GH-122046) (#122048)
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).
(cherry picked from commit 97248204a1)
2024-07-19 19:55:15 +00:00
Miss Islington (bot) bf7f4f357b
[3.13] gh-120973: Fix thread-safety issues with `threading.local` (GH-121655) (#122042)
This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.

This should also fix gh-118490.
(cherry picked from commit e059aa6b01)

Co-authored-by: mpage <mpage@meta.com>
2024-07-19 17:49:34 +00:00
Serhiy Storchaka a45d9051ed
[3.13] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122012)
(cherry picked from commit 1a0c7b9ba4)
2024-07-19 09:13:08 +00:00
Miss Islington (bot) e992cc3922
[3.13] gh-120289: Add external timer in traverse of _lsprof.Profiler (GH-121998) (#122000)
gh-120289: Add external timer in traverse of _lsprof.Profiler (GH-121998)
(cherry picked from commit eaf094c09b)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-07-19 04:10:11 +00:00
Miss Islington (bot) 721a7dde11
[3.13] gh-120289: Disallow disable() and clear() in external timer to prevent use-after-free (GH-120297) (#121984)
gh-120289: Disallow disable() and clear() in external timer to prevent use-after-free (GH-120297)
(cherry picked from commit 1ab1778283)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
2024-07-18 13:26:47 -07:00
Miss Islington (bot) afa5321c6c
[3.13] gh-121621: Move asyncio_running_loop to private struct (GH-121939) (#121943)
gh-121621: Move asyncio_running_loop to private struct (GH-121939)

This avoids changing the ABI and keeps the field in the private struct.
(cherry picked from commit 81fd625b5c)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-18 01:52:39 -07:00
Miss Islington (bot) 449529a8c2
[3.13] gh-121925: Fix uninitialized variables in `main.c` (GH-121926) (#121931)
gh-121925: Fix uninitialized variables in `main.c` (GH-121926)
(cherry picked from commit f4bc84d261)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-07-17 17:00:42 +00:00
Miss Islington (bot) 3d9692dbf8
[3.13] gh-120678: pyrepl: Include globals from modules passed with `-i` (GH-120904) (#121916)
(cherry picked from commit ac07451116)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-17 16:52:46 +02:00
Petr Viktorin 4395d68c70
[3.13] gh-113993: Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (GH-121364) (GH-121854)
* 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
(cherry picked from commit b4aedb23ae)
2024-07-17 14:51:42 +02:00
Miss Islington (bot) 06d76c4b94
[3.13] gh-121621: Move asyncio running loop to thread state (GH-121695) (GH-121864)
gh-121621: Move asyncio running loop to thread state (GH-121695)
(cherry picked from commit 69c68de43a)

Co-authored-by: Ken Jin <kenjin@python.org>
2024-07-17 01:57:37 +08:00
Miss Islington (bot) 93ee63ae20
[3.13] gh-121791: Check for `NULL` in `MethodDescriptor2_new` in `_testcapi` (GH-121792) (#121839)
gh-121791: Check for `NULL` in `MethodDescriptor2_new` in `_testcapi` (GH-121792)
(cherry picked from commit 8b6d475581)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-07-16 08:55:37 +00:00
Miss Islington (bot) 835f4add60
[3.13] gh-76785: Expand How Interpreter Channels Handle Interpreter Finalization (gh-121811)
See 6b98b274b6 for an explanation of the problem and solution.  Here I've applied the solution to channels.

(cherry picked from commit 8b209fd4f8, AKA gh-121805)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-15 20:15:47 +00:00
Miss Islington (bot) f19ccfdae0
[3.13] gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-121807)
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".)

(cherry picked from commit 6b98b274b6, AKA gh-116431)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-15 19:13:51 +00:00
Sam Gross a2a4f5ebc5
[3.13] gh-121621: Use PyMutex for writes to asyncio state (GH-121622) (#121774)
(cherry picked from commit 5d6861ad06)

Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-07-15 10:44:35 +05:30
Miss Islington (bot) 15c875a57c
[3.13] Update retroactive comments from GH-117741 (segfault in `FutureIter_dealloc`) (GH-121638) (GH-121642)
Update retroactive comments from GH-117741 (segfault in `FutureIter_dealloc`) (GH-121638)

Address comments
(cherry picked from commit 65fededf9c)

Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
2024-07-12 09:00:09 +00:00
Miss Islington (bot) 35f7155bc3
[3.13] gh-121103: Put free-threaded libraries in `lib/python3.14t` (GH-121293) (#121631)
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.
(cherry picked from commit e8c91d90ba)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-11 21:00:28 +00:00
Miss Islington (bot) 3b5f8d256c
[3.13] gh-121592: Make select.poll() and related objects thread-safe (GH-121594) (#121623)
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).
(cherry picked from commit 44937d11a6)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-11 14:44:54 +00:00
Miss Islington (bot) 5bb117586e
[3.13] gh-121596: Fix Sharing Interpreter Channels (gh-121600)
This fixes a mistake in gh-113012 and adds a test that verifies the fix.

(cherry picked from commit 35a67e36aa, AKA gh-121597)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-10 21:54:47 +00:00
Miss Islington (bot) c128718f30
[3.13] gh-121368: Fix seq lock memory ordering in _PyType_Lookup (GH-121388) (#121505)
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.
(cherry picked from commit 1d3cf79a50)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-08 19:15:58 +00:00
Miss Islington (bot) bccfd8a53f
[3.13] gh-121374: Correct docstrings in `_interpchannels` (gh-121501)
(cherry picked from commit 5289550b33, AKA gh-121418)

Co-authored-by: Max Muoto <maxmuoto@gmail.com>
2024-07-08 16:57:10 +00:00
neonene 2c3aa527fd
[3.13] gh-120782: Update internal type cache when reloading datetime (GH-120829) (#120855)
* [3.13] gh-120782: Update internal type cache when reloading datetime

When reloading _datetime module, the single-phase version did not invoke the PyInit__datetime function, whereas the current multi-phase version updates the static types through the module init. The outdated static type cache in the interpreter state needs to be invalidated at the end of reloading the multi-phase module.
2024-07-03 13:52:51 +05:30
Miss Islington (bot) 85971492b7
[3.13] gh-116181: Remove Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE in rotatingtree.c (GH-121260) (#121307)
gh-116181: Remove Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE in rotatingtree.c (GH-121260)
(cherry picked from commit 705a123898)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-07-03 07:59:26 +00:00
Miss Islington (bot) 06fd745dd9
[3.13] gh-117657: Fix data races reported by TSAN in some set methods (GH-120914) (#121240)
Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed
atomic loads in the free-threaded build.

After this change, the TSAN doesn't report data races for this method.
(cherry picked from commit 294e724964)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-07-01 19:40:28 +00:00
Miss Islington (bot) 82777cd024
[3.13] gh-113565: Improve and harden detection of curses dependencies (GH-119816) (#121202)
1. Use pkg-config to check for ncursesw/panelw. If that fails, use
   pkg-config to check for ncurses/panel.
2. Regardless of pkg-config output, search for curses/panel headers, so
   we're sure we have all defines in pyconfig.h.
3. Regardless of pkg-config output, check if libncurses or libncursesw
   contains the 'initscr' symbol; if it does _and_ pkg-config failed
   earlier, add the resulting -llib linker option to CURSES_LIBS.
   Ditto for 'update_panels' and PANEL_LIBS.
4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're
   using updated LIBS and CPPFLAGS for those.

Add the PY_CHECK_CURSES convenience macro.
(cherry picked from commit f80376b129)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
2024-07-01 08:35:38 +00:00
Miss Islington (bot) 009618f112
[3.13] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121144)
(cherry picked from commit 6d34938dc8)

Co-authored-by: blhsing <blhsing@gmail.com>
2024-06-29 06:57:33 +00:00
Miss Islington (bot) 50ea6408b8
[3.13] gh-121137: Add missing Py_DECREF calls for ADDITEMS opcode of _pickle.c (GH-121136) (#121139)
gh-121137: Add missing Py_DECREF calls for ADDITEMS opcode of _pickle.c (GH-121136)

PyObject_GetAttr returns a new reference, but this reference is never decremented using Py_DECREF, so Py_DECREF calls to this referece are added
(cherry picked from commit 92893fd8dc)

Co-authored-by: Justin Applegate <70449145+Legoclones@users.noreply.github.com>
2024-06-28 16:17:34 -07:00
Miss Islington (bot) 49e5740135
[3.13] gh-121027: Add a future warning in functools.partial.__get__ (GH-121086) (#121092)
gh-121027: Add a future warning in functools.partial.__get__ (GH-121086)
(cherry picked from commit db96edd6d1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-27 12:13:01 +00:00
Miss Islington (bot) c052b192aa
[3.13] gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121013)
We also add _PyThreadState_NewBound() and drop _PyThreadState_SetWhence().

This change only affects internal API.

(cherry picked from commit a905721b9c, AKA gh-121010)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-26 15:32:00 -06:00
Victor Stinner e26e0985d9
[3.13] gh-120642: Move private PyCode APIs to the internal C API (#120643) (#121043)
gh-120642: Move private PyCode APIs to the internal C API (#120643)

* Move _Py_CODEUNIT and related functions to pycore_code.h.
* Move _Py_BackoffCounter to pycore_backoff.h.
* Move Include/cpython/optimizer.h content to pycore_optimizer.h.
* Remove Include/cpython/optimizer.h.
* Remove PyUnstable_Replace_Executor().

Rename functions:

* PyUnstable_GetExecutor() => _Py_GetExecutor()
* PyUnstable_GetOptimizer() => _Py_GetOptimizer()
* PyUnstable_SetOptimizer() => _Py_SetTier2Optimizer()
* PyUnstable_Optimizer_NewCounter() => _PyOptimizer_NewCounter()
* PyUnstable_Optimizer_NewUOpOptimizer() => _PyOptimizer_NewUOpOptimizer()

(cherry picked from commit 9e4a81f00f)
2024-06-26 15:35:19 +02:00
Petr Viktorin 9769b7ae06
[3.13] gh-113993: Allow interned strings to be mortal, and fix related issues (GH-120520) (GH-120945)
* Add an InternalDocs file describing how interning should work and how to use it.

* Add internal functions to *explicitly* request what kind of interning is done:
  - `_PyUnicode_InternMortal`
  - `_PyUnicode_InternImmortal`
  - `_PyUnicode_InternStatic`

* Switch uses of `PyUnicode_InternInPlace` to those.

* Disallow using `_Py_SetImmortal` on strings directly.
  You should use `_PyUnicode_InternImmortal` instead:
  - Strings should be interned before immortalization, otherwise you're possibly
    interning a immortalizing copy.
  - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
    `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
    backports, as they are now part of public API and version-specific ABI.

* Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

* Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
  - `_Py_ID`
  - `_Py_STR` (including the empty string)
  - one-character latin-1 singletons

  Now, when you intern a singleton, that exact singleton will be interned.

* Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

* Intern `_Py_STR` singletons at startup.

* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.

* Beef up the tests. Cover internal details (marked with `@cpython_only`).

* Add lots of assertions

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-24 20:24:19 +02:00
Miss Islington (bot) 732c00550f
[3.13] gh-119614: Fix truncation of strings with embedded null characters in Tkinter (GH-120909) (GH-120938)
Now the null character is always represented as \xc0\x80 for
Tcl_NewStringObj().
(cherry picked from commit c38e2f64d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-24 09:45:45 +00:00
Miss Islington (bot) 99f18ea689
[3.13] gh-101830: Fix Tcl_Obj to string conversion (GH-120884) (GH-120905)
Accessing the Tkinter object's string representation no longer converts
the underlying Tcl object to a string on Windows.
(cherry picked from commit f4ddaa3967)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-23 18:33:19 +03:00
Sam Gross 4dc27bc0b7
[3.13] gh-119344: Make critical section API public (GH-119353) (#120856)
This makes the following macros public as part of the non-limited C-API for
locking a single object or two objects at once.

* `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()`
* `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()`

The supporting functions and structs used by the macros are also exposed for
cases where C macros are not available.
(cherry picked from commit 8f17d69b7b)
2024-06-21 20:20:41 +00:00
Sam Gross 3cb6c4cd60
[3.13] gh-117511: Make PyMutex public in the non-limited API (GH-117731) (#120800)
(cherry picked from commit 3af7263037)
2024-06-20 16:00:25 +00:00
Mark Shannon b8fd80f91b
[3.13] GH-119462: Enforce invariants of type versioning. Backport of GH-120731. (#120748)
* Remove uses of Py_TPFLAGS_VALID_VERSION_TAG
2024-06-20 15:09:32 +01:00
Miss Islington (bot) 9be94f9ce6
[3.13] gh-119506: fix `_io.TextIOWrapper.write()` write during flush (GH-119507) (#119964)
gh-119506: fix `_io.TextIOWrapper.write()` write during flush (GH-119507)
(cherry picked from commit 52586f930f)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2024-06-19 10:11:07 +00:00
Miss Islington (bot) 1ce5984961
[3.13] gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (GH-118807) (#120695)
This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.

Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use `_PyWeakref_ClearRef` on each weakref, but
that's not thread-safe in the free-threaded build.

(cherry picked from commit e8752d7b80)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-06-18 14:54:51 +00:00
Jelle Zijlstra 7c47f93dff
[3.13] gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (GH-119976) (#120641)
(cherry picked from commit 4bf17c381f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-06-17 08:01:49 -07:00
Miss Islington (bot) 03b89e3a3d
[3.13] gh-120586: Fix several "unused function" warnings in `posixmodule.c` (GH-120588) (#120616)
gh-120586: Fix several "unused function" warnings in `posixmodule.c` (GH-120588)
(cherry picked from commit 3df2022931)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-17 07:09:11 +00:00