Commit Graph

9596 Commits

Author SHA1 Message Date
Mark Shannon 54f74b80ae
GH-128563: Move some labels, to simplify implementing tailcalling interpreter. (GH-129525) 2025-01-31 17:13:20 +00:00
Peter Bierma 9ba281d871
gh-128509: Add `sys._is_immortal` for identifying immortal objects (#128510)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-01-31 15:27:08 +00:00
Valery Fedorenko fad36bf382
gh-126108: Fix potential null pointer dereference in `PySys_AddWarnOptionUnicode` (#126118) 2025-01-31 20:06:30 +05:30
Victor Stinner 3447f4a56a
gh-129354: Use PyErr_FormatUnraisable() function (#129514)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
2025-01-31 14:20:35 +01:00
Mark Shannon c3ae5c9e4a
GH-128563: Simplify recursion check in `_PyEval_EvalFrameDefault` (GH-129481)
Simplify recursion check in _PyEval_EvalFrameDefault
2025-01-31 12:12:24 +00:00
Victor Stinner 95504f429e
gh-129354: Fix grammar in PyErr_FormatUnraisable() (#129475)
Replace "on verb+ing" with "while verb+ing".
2025-01-31 09:45:35 +01:00
Victor Stinner 4e47e05045
gh-129354: Use PyErr_FormatUnraisable() function (#129435)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
2025-01-30 16:09:38 +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
Sam Gross 5ff2fbc026
gh-129236: Use `stackpointer` in free threaded GC (#129240)
The stack pointers in interpreter frames are nearly always valid now, so
use them when visiting each thread's frame. For now, don't collect
objects with deferred references in the rare case that we see a frame
with a NULL stack pointer.
2025-01-29 10:40:51 -05:00
Irit Katriel 4815131910
gh-100239: specialize bitwise logical binary ops on ints (#128927) 2025-01-29 09:28:21 +00:00
Brandt Bucher 828b27680f
GH-126599: Remove the PyOptimizer API (GH-129194) 2025-01-28 16:10:51 -08:00
T. Wouters 5c930a26fb
gh-115999: Enable free-threaded specialization of LOAD_CONST (#129365)
Enable free-threaded specialization of LOAD_CONST.
2025-01-29 01:07:56 +01:00
Mark Shannon 75b4962157
GH-128914: Remove all but one conditional stack effects (GH-129226)
* Remove all 'if (0)' and 'if (1)' conditional stack effects

* Use array instead of conditional for BUILD_SLICE args

* Refactor LOAD_GLOBAL to use a common conditional uop

* Remove conditional stack effects from LOAD_ATTR specializations

* Replace conditional stack effects in LOAD_ATTR with a 0 or 1 sized array.

* Remove conditional stack effects from CALL_FUNCTION_EX
2025-01-27 16:24:48 +00:00
Bénédikt Tran ced296d2c0
gh-111178: fix UBSan failures in `Python/traceback.c` (GH-128259) 2025-01-27 15:07:39 +01:00
Ken Jin 87fb8b198c
gh-128563: Move labels in ceval.c to bytecodes.c (GH-129112) 2025-01-27 18:30:20 +08:00
Irit Katriel c39ae8922b
gh-128799: Add frame of except* to traceback when wrapping a naked exception (#128971) 2025-01-25 13:00:23 +00:00
Michael Droettboom 9e52e553f4
gh-129244: Remove workaround for MSVC compiler crash (#129263)
* Remove compiler workaround

* Remote _Py_USING_PGO
2025-01-25 07:56:13 -05:00
Chris Eibl 8fecb9fa0b
Remove unused DPRINTF in ceval.c (GH-129282)
remove unused DPRINTF in ceval.c
2025-01-25 18:33:26 +08:00
Victor Stinner fc6bc1e4e3
gh-129185: Simplify PyTraceMalloc_Track() (#129256)
Since tracemalloc uses PyMutex, it becomes safe to use TABLES_LOCK()
even after _PyTraceMalloc_Fini(): remove the "pre-check" in
PyTraceMalloc_Track() and PyTraceMalloc_Untrack().

PyTraceMalloc_Untrack() no longer needs to acquire the GIL.

_PyTraceMalloc_Fini() can be called earlier during Python
finalization.
2025-01-24 14:29:36 +01:00
Victor Stinner c005ea4951
gh-129185: Use PyMutex in tracemalloc (#129246) 2025-01-24 11:25:24 +01:00
Bénédikt Tran 36bb229933
gh-129173: Use `_PyUnicodeError_GetParams` in `PyCodec_IgnoreErrors` (#129174)
We also cleanup `PyCodec_StrictErrors` and the error message rendered
when an object of incorrect type is passed to codec error handlers.
2025-01-24 11:25:03 +01:00
Bénédikt Tran 25a614a502
gh-126004: Fix positions handling in `codecs.backslashreplace_errors` (#127676)
This fixes how `PyCodec_BackslashReplaceErrors` handles the `start` and `end`
attributes of `UnicodeError` objects via the `_PyUnicodeError_GetParams` helper.
2025-01-23 14:28:33 +01:00
Victor Stinner e579cdb21e
gh-129185: Remove internal TRACE_RAW_MALLOC macro (#129218)
Always build tracemalloc with PyMem_RawMalloc() hooks.
2025-01-23 13:49:35 +01:00
Victor Stinner 46c7e13c05
gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191)
Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack()
during late Python finalization.

* Call _PyTraceMalloc_Fini() later in Python finalization.
* Test also PyTraceMalloc_Untrack() without the GIL
* PyTraceMalloc_Untrack() now gets the GIL.
* Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race().
2025-01-23 12:07:34 +01:00
Bénédikt Tran 225296cd5b
gh-126004: Fix positions handling in `codecs.replace_errors` (#127674)
This fixes how `PyCodec_ReplaceErrors` handles the `start` and `end` attributes
of `UnicodeError` objects via the `_PyUnicodeError_GetParams` helper.
2025-01-23 11:44:18 +01:00
Bénédikt Tran 70dcc847df
gh-126004: Fix positions handling in `codecs.xmlcharrefreplace_errors` (#127675)
This fixes how `PyCodec_XMLCharRefReplaceErrors` handles the `start` and `end`
attributes of `UnicodeError` objects via the `_PyUnicodeError_GetParams` helper.
2025-01-23 11:42:38 +01:00
Sam Gross a10f99375e
Revert "GH-128914: Remove conditional stack effects from `bytecodes.c` and the code generators (GH-128918)" (GH-129202)
The commit introduced a ~2.5-3% regression in the free threading build.

This reverts commit ab61d3f430.
2025-01-23 09:26:25 +00:00
Sergey B Kirpichev d7d066c3ab
gh-127936, PEP 757: Convert marshal module to use import/export API for ints (#128530)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-01-23 02:54:23 +00:00
Victor Stinner 0093a31273
gh-119182: Use public PyUnicodeWriter in Python-ast.c (#129209)
Replace the private _PyUnicodeWriter API with the public
PyUnicodeWriter API.

Use PyUnicodeWriter_WriteRepr() in ast_repr_list().
2025-01-23 00:57:37 +00:00
Victor Stinner 8eb9e76b5b
gh-119182: Use public PyUnicodeWriter in ast_unparse.c (#129208)
Replace the private _PyUnicodeWriter API with the public
PyUnicodeWriter API.

* Add append_char() function.
* Add APPEND_CHAR() and APPEND_CHAR_FINISH() macros.
* Replace APPEND_STR() and APPEND_STR_FINISH() of single character
  with APPEND_CHAR() and APPEND_CHAR_FINISH().
2025-01-23 01:44:43 +01:00
Hood Chatham 960936fe90
gh-128627: Emscripten: Fix address calculation for wasm-gc trampoline (#128782)
Modifies the memory calculation to divide the entire memory address by 4, not just the base address.
2025-01-23 08:02:04 +08:00
Yury Selivanov 188598851d
GH-91048: Add utils for capturing async call stack for asyncio programs and enable profiling (#124640)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
Co-authored-by: Jacob Coffee <jacob@z7x.org>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-01-22 17:25:29 +01:00
Victor Stinner 9012fa741d
gh-128863: Deprecate private C API functions (#128864)
Deprecate private C API functions:

* _PyBytes_Join()
* _PyDict_GetItemStringWithError()
* _PyDict_Pop()
* _PyThreadState_UncheckedGet()
* _PyUnicode_AsString()
* _Py_HashPointer()
* _Py_fopen_obj()

Replace _Py_HashPointer() with Py_HashPointer().

Remove references to deprecated functions.
2025-01-22 11:04:19 +00:00
Mark Shannon 470a0a68eb
GH-128682: Change a couple of functions to only steal references on success. (GH-129132)
Change PyTuple_FromStackRefSteal and PyList_FromStackRefSteal to only steal on success to avoid escaping
2025-01-22 10:51:37 +00:00
Ken Jin 86c1a60d5a
gh-128563: Move GO_TO_INSTRUCTION and PREDICT to cases generator (GH-129115) 2025-01-22 09:22:25 +08:00
Ken Jin 5809b25909
gh-128563: Move lltrace into the frame struct (GH-129113) 2025-01-21 22:17:15 +08:00
Victor Stinner 31f149d5b3
gh-128679: Use _PyThreadState_GET() in tracemalloc.c (#129126)
Replace uncommon PyGILState_GetThisThreadState() with common
_PyThreadState_GET().
2025-01-21 14:43:31 +01:00
Victor Stinner 01de4af3e1
gh-126925: Make PyConfig.use_system_logger read-only (#129124)
The variable is only used once during early Python initialization, it
doesn't make sense to modify it at runtime.
2025-01-21 12:02:38 +01:00
Mark Shannon f5b6356a11
GH-128563: Add new frame owner type for interpreter entry frames (GH-129078)
Add new frame owner type for interpreter entry frames
2025-01-21 10:15:02 +00:00
Mark Shannon 7239da7559
GH-127953: Make line number lookup O(1) regardless of the size of the code object (GH-128350) 2025-01-21 09:33:23 +00:00
Mark Shannon ab61d3f430
GH-128914: Remove conditional stack effects from `bytecodes.c` and the code generators (GH-128918) 2025-01-20 17:09:23 +00:00
Mark Shannon f0f7b978be
GH-128939: Refactor JIT optimize structs (GH-128940) 2025-01-20 15:49:15 +00:00
Victor Stinner 8ceb6cb117
gh-129033: Remove _PyInterpreterState_SetConfig() function (#129048)
Remove _PyInterpreterState_GetConfigCopy() and
_PyInterpreterState_SetConfig() private functions. PEP 741 "Python
Configuration C API" added a better public C API: PyConfig_Get() and
PyConfig_Set().
2025-01-20 16:31:33 +01:00
Erlend E. Aasland 537296cdcd
gh-111178: Generate correct signature for most self converters (#128447) 2025-01-20 12:40:18 +01:00
Peter Bierma 4d0a6595a0
gh-128360: Add `_Py_AssertHoldsTstate` as assertion for holding a thread state (#128361)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-01-20 17:04:35 +05:30
Victor Stinner 07c3518ffb
gh-129033: Remove _Py_InitializeMain() function (#129034)
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
2025-01-20 10:03:22 +00:00
Kirill Podoprigora 6c52ada551
gh-100239: Handle NaN and zero division in guards for `BINARY_OP_EXTEND` (#128963)
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2025-01-19 11:02:49 +00:00
mpage 13c4def692
gh-128955: Fix goto if tlbc creation fails when throwing into a generator (#128957)
We don't have the correct copy of the bytecode and can't update next_instr
appropriately, so just unwind.
2025-01-17 12:53:29 -08:00
Sam Gross d66c08aa75
gh-128923: Use zero to indicate unassigned unique id (#128925)
In the free threading build, the per thread reference counting uses a
unique id for some objects to index into the local reference count
table. Use 0 instead of -1 to indicate that the id is not assigned. This
avoids bugs where zero-initialized heap type objects look like they have
a unique id assigned.
2025-01-17 16:42:27 +01:00
Xuanteng Huang b44ff6d0df
GH-126599: Remove the "counter" optimizer/executor (GH-126853) 2025-01-16 15:57:04 -08:00
Irit Katriel 3893a92d95
gh-100239: specialize long tail of binary operations (#128722) 2025-01-16 15:22:13 +00:00
Victor Stinner 3193cb5ef8
gh-128679: Fix tracemalloc.stop() race conditions (#128893)
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(),
_PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check
'tracemalloc_config.tracing' after calling TABLES_LOCK().

_PyTraceMalloc_TraceRef() now always returns 0.
2025-01-16 13:53:18 +01:00
Victor Stinner 36c5e3bcc2
gh-128679: Redesign tracemalloc locking (#128888)
* Use TABLES_LOCK() to protect 'tracemalloc_config.tracing'.
* Hold TABLES_LOCK() longer while accessing tables.
* tracemalloc_realloc() and tracemalloc_free() no longer
  remove the trace on reentrant call.
* _PyTraceMalloc_Stop() unregisters _PyTraceMalloc_TraceRef().
* _PyTraceMalloc_GetTraces() sets the reentrant flag.
* tracemalloc_clear_traces_unlocked() sets the reentrant flag.
2025-01-15 20:22:44 +00:00
Neil Schemenauer 080f444a58
gh-128807: Add marking phase for free-threaded cyclic GC (gh-128808) 2025-01-15 11:27:28 -08:00
mpage b5ee0258bf
gh-115999: Specialize `LOAD_ATTR` for instance and class receivers in free-threaded builds (#128164)
Finish specialization for LOAD_ATTR in the free-threaded build by adding support for class and instance receivers.
2025-01-14 11:56:11 -08:00
Neil Schemenauer 1c13c56a34
gh-128384: Add locking to warnings.py. (gh-128386)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-01-14 11:43:42 -08:00
Mark Shannon f49a1df6f3
GH-128682: Convert explicit loops closing arrays into `DECREF_INPUTS`. (GH-128822)
* Mark Py_DECREF and Py_XDECREF as escaping

* Remove explicit loops for clearing array inputs
2025-01-14 15:08:56 +00:00
Peter Bierma bf64a582f0
gh-128400: Only show the current thread in `Py_FatalError` on the free-threaded build (#128758) 2025-01-13 20:06:54 +05:30
Mark Shannon 517dc65ffc
GH-128682: Stronger checking of `PyStackRef_CLOSE` and `DEAD`. (GH-128683) 2025-01-13 12:37:48 +00:00
Mark Shannon ddd959987c
GH-128685: Specialize (rather than quicken) LOAD_CONST into LOAD_CONST_[IM]MORTAL (GH-128708) 2025-01-13 10:30:28 +00:00
Hood Chatham d0ecbdd838
gh-128627: Emscripten: Use wasm-gc based call adaptor if available (#128628)
Replaces the trampoline mechanism in Emscripten with an implementation that uses a
recently added feature of wasm-gc instead of JS type reflection, when that feature is
available.
2025-01-13 07:09:39 +08:00
Peter Bierma f6c61bf2d7
gh-128717: Stop-the-world when setting the recursion limit (#128741) 2025-01-12 18:34:30 +05:30
9cel 3a570c6d58
Make the Python CLI error message style more consistent (GH-128129) 2025-01-11 11:17:35 +02:00
Bénédikt Tran 28ffdc5702
gh-111178: fix UBSan failures in `Python/bltinmodule.c` (GH-128235)
* fix UBSan failures for `filterobject`
* fix UBSan failures for `mapobject`
* fix UBSan failures for `zipobject`
2025-01-10 11:51:24 +01:00
Petr Viktorin 1439b81928
gh-128629: Add Py_PACK_VERSION and Py_PACK_FULL_VERSION (GH-128630) 2025-01-09 11:10:28 +01:00
Brandt Bucher 004f9fd1f2
Remove unnecessary LIST_TO_TUPLE conversions (GH-126558) 2025-01-08 09:00:11 -08:00
Bénédikt Tran 1da0901894
gh-111178: fix UBSan failures in `Python/context.c` (GH-128242)
* fix UBSan failures for `PyContext`
* fix UBSan failures for `PyContextVar`
* fix UBSan failures for `PyContextToken`
* fix UBSan failures for `_PyContextTokenMissing`
2025-01-08 14:52:27 +01:00
Bénédikt Tran c22302ecea
gh-111178: fix UBSan failures in `Python/hamt.c` (GH-128247)
* fix UBSan failures for `PyHamtObject`
* fix UBSan failures for `PyHamtNode_Array`
* fix UBSan failures for `PyHamtNode_Collision`
* fix UBSan failures for `PyHamtNode_Bitmap`
2025-01-08 14:50:40 +01:00
Brandt Bucher 65ae3d5a73
GH-127809: Fix the JIT's understanding of ** (GH-127844) 2025-01-07 17:25:48 -08:00
T. Wouters 8f93dd8a8f
gh-115999: Add free-threaded specialization for COMPARE_OP (#126410)
Add free-threaded specialization for COMPARE_OP, and tests for COMPARE_OP specialization in general.

Co-authored-by: Donghee Na <donghee.na92@gmail.com>
2025-01-07 06:41:01 -08:00
Russell Keith-Magee e837a1f71e
gh-128146: Exclude os/log.h import on older macOS versions. (#128165)
Reworks the handling of Apple system log handling to account for older macOS 
versions that don't provide os-log.
2025-01-07 13:12:58 +08:00
Mark Shannon 2434fd2d50
GH-128533: Add `NOT_TAKEN` instruction after bytecode optimization. (GH-128554) 2025-01-06 22:01:07 +00:00
Mark Shannon f826beca0c
GH-128375: Better instrument for `FOR_ITER` (GH-128445) 2025-01-06 17:54:47 +00:00
Victor Stinner f89e5e20cb
gh-127350: Add Py_fopen() and Py_fclose() functions (#127821) 2025-01-06 12:43:09 +00:00
Anders Kaseorg a626f9a67b
Remove asserts that confuse `enum _framestate` with `enum _frameowner` (GH-124148)
The `owner` field of `_PyInterpreterFrame` is supposed to be a member of
`enum _frameowner`, but `FRAME_CLEARED` is a member of `enum _framestate`.

At present, it happens that `FRAME_CLEARED` is not numerically equal to any
member of `enum _frameowner`, but that could change in the future. The code
that incorrectly assigned `owner = FRAME_CLEARED` was deleted in commit
a53cc3f494 (GH-116687). Remove the incorrect
checks for `owner != FRAME_CLEARED` as well.
2025-01-02 16:55:33 +00:00
Kumar Aditya e389d6c650
gh-128277: make globals variables thread safe in socket module (#128286) 2024-12-31 19:10:06 +05:30
Ken Jin 7ef4907412
gh-128262: Allow specialization of calls to classes with __slots__ (GH-128263) 2024-12-31 12:24:17 +08:00
Yan Yanchii fe4dd07a84
gh-119786: Mention `InternalDocs/interpreter.md` instead of non-existing `adaptive.md` (#128329)
`Python/specialize.c`: Mention `InternalDocs/interpreter.md` instead of non-existing `adaptive.md`


Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-12-30 18:38:09 +00:00
Jelle Zijlstra 3480124321
gh-119180: Set the name of the param to __annotate__ to "format" (#124730) 2024-12-30 08:19:38 -08:00
Yan Yanchii 30efede33c
gh-128195: Add `_REPLACE_WITH_TRUE` to the tier2 optimizer (GH-128203)
Add `_REPLACE_WITH_TRUE` to the tier2 optimizer
2024-12-24 05:17:47 +08:00
T. Wouters 180d417e9f
gh-114203: Optimise simple recursive critical sections (#128126)
Add a fast path to (single-mutex) critical section locking _iff_ the mutex
is already held by the currently active, top-most critical section of this
thread. This can matter a lot for indirectly recursive critical sections
without intervening critical sections.
2024-12-23 13:31:33 +01:00
Nico-Posada 3879ca0100
gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (#128079) 2024-12-20 19:20:31 +00:00
Mark Shannon 128cc47fbd
GH-127705: Add debug mode for `_PyStackRef`s inspired by HPy debug mode (GH-128121) 2024-12-20 16:52:20 +00:00
Shantanu 45e6dd63b8
gh-128030: Avoid error from PyModule_GetFilenameObject for non-module (#128047)
I missed the extra `PyModule_Check` in #127660 because I was looking at
3.12 as the base implementation for import from. This meant that I
missed the `PyModuleCheck` introduced in #112661.
2024-12-20 00:22:26 -08:00
mpage 255762c09f
gh-127274: Defer nested methods (#128012)
Methods (functions defined in class scope) are likely to be cleaned
up by the GC anyway.

Add a new code flag, `CO_METHOD`, that is set for functions defined
in a class scope. Use that when deciding to defer functions.
2024-12-19 13:03:14 -08:00
Neil Schemenauer 1b15c89a17
gh-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)
* Add `_PyDictKeys_StringLookupSplit` which does locking on dict keys and
  use in place of `_PyDictKeys_StringLookup`.

* Change `_PyObject_TryGetInstanceAttribute` to use that function
  in the case of split keys.

* Add `unicodekeys_lookup_split` helper which allows code sharing
  between `_Py_dict_lookup` and `_PyDictKeys_StringLookupSplit`.

* Fix locking for `STORE_ATTR_INSTANCE_VALUE`.  Create
  `_GUARD_TYPE_VERSION_AND_LOCK` uop so that object stays locked and
  `tp_version_tag` cannot change.

* Pass `tp_version_tag` to `specialize_dict_access()`, ensuring
  the version we store on the cache is the correct one (in case of
  it changing during the specalize analysis).

* Split `analyze_descriptor` into `analyze_descriptor_load` and
  `analyze_descriptor_store` since those don't share much logic.
  Add `descriptor_is_class` helper function.

* In `specialize_dict_access`, double check `_PyObject_GetManagedDict()`
  in case we race and dict was materialized before the lock.

* Avoid borrowed references in `_Py_Specialize_StoreAttr()`.

* Use `specialize()` and `unspecialize()` helpers.

* Add unit tests to ensure specializing happens as expected in FT builds.

* Add unit tests to attempt to trigger data races (useful for running under TSAN).

* Add `has_split_table` function to `_testinternalcapi`.
2024-12-19 10:21:17 -08:00
Mark Shannon d2f1d917e8
GH-122548: Implement branch taken and not taken events for sys.monitoring (GH-122564) 2024-12-19 16:59:51 +00:00
Donghee Na 48c70b8f7d
gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (gh-127737) 2024-12-19 11:08:17 +09:00
Kumar Aditya 91c55085a9
gh-128033: change `PyMutex_LockFast` to take `PyMutex` as argument (#128054)
Change `PyMutex_LockFast` to take `PyMutex` as argument.
2024-12-18 20:49:00 +05:30
Bénédikt Tran 7303f06846
gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746)
- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-17 12:12:45 +01:00
Berker Peksag cfeaa992ba
Free arena on _PyCompile_AstOptimize failure in Py_CompileStringObject (GH-127910)
After commit 10a91d7e9 introduced arena cleanup, commit 2dfbd4f36
removed the free call when _PyCompile_AstOptimize fails.
2024-12-16 22:59:36 +02:00
Tomas R. 081673801e
gh-127864: Fix compiler warning (-Wstringop-truncation) (GH-127878) 2024-12-16 11:57:18 -05:00
mpage 2de048ce79
gh-115999: Specialize loading attributes from modules in free-threaded builds (#127711)
We use the same approach that was used for specialization of LOAD_GLOBAL in free-threaded builds:

_CHECK_ATTR_MODULE is renamed to _CHECK_ATTR_MODULE_PUSH_KEYS; it pushes the keys object for the following _LOAD_ATTR_MODULE_FROM_KEYS (nee _LOAD_ATTR_MODULE). This arrangement avoids having to recheck the keys version.

_LOAD_ATTR_MODULE is renamed to _LOAD_ATTR_MODULE_FROM_KEYS; it loads the value from the keys object pushed by the preceding _CHECK_ATTR_MODULE_PUSH_KEYS at the cached index.
2024-12-13 10:17:16 -08:00
Mark Shannon e62e1ca455
GH-126833: Dumps graphviz representation of executor graph. (GH-126880) 2024-12-13 11:00:00 +00:00
Pieter Eendebak 5fc6bb2754
gh-126868: Add freelist for compact int objects (GH-126865) 2024-12-13 10:06:26 +00:00
velemas f823910bbd
gh-127865: Fix build failure for systems without thread local support (GH-127866)
This PR fixes the build issue introduced by the commit 628f6eb from
GH-112207 on systems without thread local support.
2024-12-12 13:07:55 -05:00
mpage c84928ed6d
gh-115999: Specialize `CALL_KW` in free-threaded builds (#127713)
* Enable specialization of CALL_KW

* Fix bug pushing frame in _PY_FRAME_KW

`_PY_FRAME_KW` pushes a pointer to the new frame onto the stack for
consumption by the next uop. When pushing the frame fails, we do not
want to push the result, `NULL`, to the stack because it is not
a valid stackref. This works in the default build because `PyStackRef_NULL`
 and `NULL` are the same value, so the `PyStackRef_XCLOSE()` in the error
handler ignores it. In the free-threaded build the values are not the same;
`PyStackRef_XCLOSE()` will attempt to decref a null pointer.
2024-12-11 15:18:22 -08:00
Petr Viktorin 690fe077f6
gh-126491: Revert "GH-126491: Lower heap size limit with faster marking (GH-127519)" (GH-127770)
Revert "GH-126491: Lower heap size limit with faster marking (GH-127519)"

This reverts commit 023b7d2141, which introduced
a refleak.
2024-12-10 11:53:56 +01:00
Shantanu 3983527c3a
gh-127651: Use __file__ in diagnostics if origin is missing (#127660)
See the left hand side in https://github.com/python/cpython/pull/123929/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59deL2840-L2849

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-12-09 20:55:20 -08:00
Russell Keith-Magee 2041a95e68
gh-126925: Modify how iOS test results are gathered (#127592)
Adds a `use_system_log` config item to enable stdout/stderr redirection for
Apple platforms. This log streaming is then used by a new iOS test runner
script, allowing the display of test suite output at runtime. The iOS test
runner script can be used by any Python project, not just the CPython test
suite.
2024-12-09 13:28:57 +08:00
Sam Gross a353455fca
gh-125610: Fix `STORE_ATTR_INSTANCE_VALUE` specialization check (GH-125612)
The `STORE_ATTR_INSTANCE_VALUE` opcode doesn't support objects with
non-NULL managed dictionaries, so don't specialize to that op in that case.
2024-12-06 10:48:24 -05:00
Mark Shannon 023b7d2141
GH-126491: Lower heap size limit with faster marking (GH-127519)
* Faster marking of reachable objects

* Changes calculation of work to do and work done.

* Merges transitive closure calculations
2024-12-06 10:46:59 +00:00
mpage dabcecfd6d
gh-115999: Enable specialization of `CALL` instructions in free-threaded builds (#127123)
The CALL family of instructions were mostly thread-safe already and only required a small number of changes, which are documented below.

A few changes were needed to make CALL_ALLOC_AND_ENTER_INIT thread-safe:

Added _PyType_LookupRefAndVersion, which returns the type version corresponding to the returned ref.

Added _PyType_CacheInitForSpecialization, which takes an init method and the corresponding type version and only populates the specialization cache if the current type version matches the supplied version. This prevents potentially caching a stale value in free-threaded builds if we race with an update to __init__.

Only cache __init__ functions that are deferred in free-threaded builds. This ensures that the reference to __init__ that is stored in the specialization cache is valid if the type version guard in _CHECK_AND_ALLOCATE_OBJECT passes.
Fix a bug in _CREATE_INIT_FRAME where the frame is pushed to the stack on failure.

A few other miscellaneous changes were also needed:

Use {LOCK,UNLOCK}_OBJECT in LIST_APPEND. This ensures that the list's per-object lock is held while we are appending to it.

Add missing co_tlbc for _Py_InitCleanup.

Stop/start the world around setting the eval frame hook. This allows us to read interp->eval_frame non-atomically and preserves the behavior of _CHECK_PEP_523 documented below.
2024-12-03 11:20:20 -08:00
Neil Schemenauer fc5a0dc224
gh-127271: Replace use of PyCell_GET/SET (gh-127272)
* Replace uses of `PyCell_GET` and `PyCell_SET`.  These macros are not
  safe to use in the free-threaded build.  Use `PyCell_GetRef()` and
  `PyCell_SetTakeRef()` instead. 

* Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some
  code restructuring was required, e.g. `frame_get_var()` returns a strong
  ref now.

* Add critical sections to `PyCell_GET` and `PyCell_SET`.

* Move critical_section.h earlier in the Python.h file.

* Add `PyCell_GET` to the free-threading howto table of APIs that return
  borrowed refs.

* Add additional unit tests for free-threading.
2024-12-03 10:33:06 -08:00
Neil Schemenauer 276cd66ccb
gh-115999: Add free-threaded specialization for `SEND` (gh-127426)
No additional thread safety changes are required.  Note that sending to
a generator that is shared between threads is currently not safe in the
free-threaded build.
2024-12-03 10:25:12 -08:00
Neil Schemenauer 0cb5222079
gh-115999: Specialize `LOAD_SUPER_ATTR` in free-threaded builds (gh-127128)
Use existing helpers to atomically modify the bytecode.  Add unit tests
to ensure specializing is happening as expected.  Add test_specialize.py
that can be used with ThreadSanitizer to detect data races.  
Fix thread safety issue with cell_set_contents().
2024-12-03 09:32:26 -08:00
Daniele Parmeggiani 979bf2489d
gh-117657: TSAN Fix races in `PyMember_Get` and `PyMember_Set` for C extensions (GH-123211) 2024-12-03 09:41:53 -05:00
Michael Droettboom edefb8678a
gh-127518: Fix pystats build after #127169 (#127526)
gh-127518: Fix pystats build after #127619
2024-12-02 20:17:08 +00:00
Donghee Na 7c2bd9b226
gh-115999: Use light-weight lock for UNPACK_SEQUENCE_LIST (gh-127514) 2024-12-03 00:14:40 +09:00
Mark Shannon a8dd821d5b
GH-126491: GC: Mark objects reachable from roots before doing cycle collection (GH-127110)
* Mark almost all reachable objects before doing collection phase

* Add stats for objects marked

* Visit new frames before each increment

* Update docs

* Clearer calculation of work to do.
2024-12-02 10:12:17 +00:00
Donghee Na e2713409cf
gh-115999: Add partial free-thread specialization for BINARY_SUBSCR (gh-127227) 2024-12-02 10:38:17 +09:00
Peter Bierma 46bfd26fb2
gh-127165: Disallow embedded NULL characters in `_interpreters` (#127199) 2024-12-01 06:33:23 +00:00
Victor Stinner b14fdadc6c
gh-127208: Reject null character in _imp.create_dynamic() (#127400)
_imp.create_dynamic() now rejects embedded null characters in the
path and in the module name.
2024-11-29 16:20:38 +01:00
Kumar Aditya 762c603a86
gh-126881: fix finalization of dtoa state (#126904) 2024-11-29 15:17:16 +05:30
Victor Stinner 58e334e143
gh-123967: Fix faulthandler for trampoline frames (#127329)
If the top-most frame is a trampoline frame, skip it.
2024-11-27 16:14:49 +01:00
Sam Gross 71ede1142d
gh-115999: Add free-threaded specialization for `STORE_SUBSCR` (#127169)
The specialization only depends on the type, so no special thread-safety
considerations there.

STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.

`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
2024-11-26 16:46:06 -05:00
Sergey B Kirpichev 987311d42e
gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)
"Generally, mixed-mode arithmetic combining real and complex variables should
be performed directly, not by first coercing the real to complex, lest the sign
of zero be rendered uninformative; the same goes for combinations of pure
imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for
complex elementary functions.

This patch implements mixed-mode arithmetic rules, combining real and
complex variables as specified by C standards since C99 (in particular,
there is no special version for the true division with real lhs
operand).  Most C compilers implementing C99+ Annex G have only these
special rules (without support for imaginary type, which is going to be
deprecated in C2y).
2024-11-26 17:57:39 +02:00
Jelle Zijlstra dcf629213b
gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415) 2024-11-26 15:40:13 +00:00
Marc Mueller 4fd9eb2aca
Fix typo: Use AsyncFor element access in codegen (#127278)
Use AsyncFor element access in codegen
2024-11-26 01:00:46 +00:00
mpage 193890c1cc
gh-126612: Include stack effects of uops when computing maximum stack depth (#126894) 2024-11-26 00:53:49 +00:00
Sam Gross d3da04bfc9
gh-127022: Remove `_PyEvalFramePushAndInit_UnTagged` (gh-127168)
The interpreter now handles `_PyStackRef`s pointing to immortal objects
without the deferred bit set, so `_PyEvalFramePushAndInit_UnTagged` is
no longer necessary.
2024-11-25 12:24:37 -05:00
Sergey B Kirpichev c595eae84c
gh-127238: adjust error message for sys.set_int_max_str_digits() (#127241)
Now it's correct and closer to Python/initconfig.c
2024-11-25 00:29:55 -05:00
mpage d24a22e9b6
gh-115999: Record success in `specialize` (#127167)
Record success in `specialize`

This matches the existing behavior where we increment the success
stat for the generic opcode each time we successfully specialize
an instruction.
2024-11-22 12:07:05 -08:00
Radislav Chugunov ca3ea9ad05
gh-109746: Make _thread.start_new_thread delete state of new thread on its startup failure (GH-109761)
If Python fails to start newly created thread
due to failure of underlying PyThread_start_new_thread() call,
its state should be removed from interpreter' thread states list
to avoid its double cleanup.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-11-22 21:20:07 +02:00
Filipe Laíns 🇵🇸 a264637654
GH-89435: os.path should not be a frozen module (#126924) 2024-11-22 18:50:30 +00:00
Sam Gross 4759ba6eec
gh-127022: Simplify `PyStackRef_FromPyObjectSteal` (#127024)
This gets rid of the immortal check in `PyStackRef_FromPyObjectSteal()`.
Overall, this improves performance about 2% in the free threading
build.

This also renames `PyStackRef_Is()` to `PyStackRef_IsExactly()` because
the macro requires that the tag bits of the arguments match, which is
only true in certain special cases.
2024-11-22 12:55:33 -05:00
Kirill Podoprigora 27486c3365
gh-115999: Add free-threaded specialization for `UNPACK_SEQUENCE` (#126600)
Add free-threaded specialization for `UNPACK_SEQUENCE` opcode.
`UNPACK_SEQUENCE_TUPLE/UNPACK_SEQUENCE_TWO_TUPLE` are already thread safe since tuples are immutable.
`UNPACK_SEQUENCE_LIST` is not thread safe because of nature of lists (there is nothing preventing another thread from adding items to or removing them the list while the instruction is executing). To achieve thread safety we add a critical section to the implementation of `UNPACK_SEQUENCE_LIST`, especially around the parts where we check the size of the list and push items onto the stack.


---------

Co-authored-by: Matt Page <mpage@meta.com>
Co-authored-by: mpage <mpage@cs.stanford.edu>
2024-11-22 19:00:35 +02:00
Donghee Na 78a530a578
gh-115999: Add free-threaded specialization for ``TO_BOOL`` (gh-126616) 2024-11-22 07:52:16 +09:00
mpage 09c240f20c
gh-115999: Specialize `LOAD_GLOBAL` in free-threaded builds (#126607)
Enable specialization of LOAD_GLOBAL in free-threaded builds.

Thread-safety of specialization in free-threaded builds is provided by the following:

A critical section is held on both the globals and builtins objects during specialization. This ensures we get an atomic view of both builtins and globals during specialization.
Generation of new keys versions is made atomic in free-threaded builds.
Existing helpers are used to atomically modify the opcode.
Thread-safety of specialized instructions in free-threaded builds is provided by the following:

Relaxed atomics are used when loading and storing dict keys versions. This avoids potential data races as the dict keys versions are read without holding the dictionary's per-object lock in version guards.
Dicts keys objects are passed from keys version guards to the downstream uops. This ensures that we are loading from the correct offset in the keys object. Once a unicode key has been stored in a keys object for a combined dictionary in free-threaded builds, the offset that it is stored in will never be reused for a different key. Once the version guard passes, we know that we are reading from the correct offset.
The dictionary read fast-path is used to read values from the dictionary once we know the correct offset.
2024-11-21 11:22:21 -08:00
Eric Snow 9dabace39d
gh-114940: Add _Py_FOR_EACH_TSTATE_UNLOCKED(), and Friends (gh-127077)
This is a precursor to the actual fix for gh-114940, where we will change these macros to use the new lock.  This change is almost entirely mechanical; the exceptions are the loops in codeobject.c and ceval.c, which now hold the "head" lock.  Note that almost all of the uses of _Py_FOR_EACH_TSTATE_UNLOCKED() here will change to _Py_FOR_EACH_TSTATE_BEGIN() once we add the new per-interpreter lock.
2024-11-21 11:08:38 -07:00
Dino Viehland bf542f8bb9
gh-124470: Fix crash when reading from object instance dictionary while replacing it (#122489)
Delay free a dictionary when replacing it
2024-11-21 10:41:19 -06:00
Nice Zombies 60ec854bc2
gh-126780: Fix `ntpath.normpath()` for drive-relative paths (GH-126801) 2024-11-21 14:43:36 +00:00
mpage 32428cf9ea
gh-115999: Don't take a reason in unspecialize (#127030)
Don't take a reason in unspecialize

We only want to compute the reason if stats are enabled. Optimizing
compilers should optimize this away for us (gcc and clang do), but
it's better to be safe than sorry.
2024-11-20 14:54:48 -08:00
Peter Bierma 6c1a4fb6d4
gh-121058: Warn if `PyThreadState_Clear` is called with an exception set (gh-121343) 2024-11-20 10:27:19 -07:00
Mark Shannon aea0c586d1
GH-127010: Don't lazily track and untrack dicts (GH-127027) 2024-11-20 16:41:20 +00:00
Brandt Bucher 48c50ff1a2
GH-126892: Reset warmup counters when JIT compiling code (GH-126893) 2024-11-20 08:11:25 -08:00
Eric Snow 1c0a104eca
gh-126914: Store the Preallocated Thread State's Pointer in a PyInterpreterState Field (gh-126989)
This approach eliminates the originally reported race. It also gets rid of the deadlock reported in gh-96071, so we can remove the workaround added then.
2024-11-19 12:59:19 -07:00
Mark Shannon a99dd23c1f
GH-124567: Replace quadratic assert with linear one (GH-127009) 2024-11-19 13:38:59 +00:00
Pablo Galindo Salgado 30aeb00d36
gh-126076: Account for relocated objects in tracemalloc (#126077) 2024-11-19 10:35:17 +00:00
Hugo van Kemenade 899fdb213d
Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle collection (GH-126502)" (#126983) 2024-11-19 11:25:09 +02:00
Eric Snow d6b3e78504
gh-126986: Drop _PyInterpreterState_FailIfNotRunning() (gh-126988)
We replace it with _PyErr_SetInterpreterAlreadyRunning().
2024-11-19 00:11:12 +00:00
Mark Shannon b0fcc2c47a
GH-126491: GC: Mark objects reachable from roots before doing cycle collection (GH-126502)
* Mark almost all reachable objects before doing collection phase

* Add stats for objects marked

* Visit new frames before each increment

* Remove lazy dict tracking

* Update docs

* Clearer calculation of work to do.
2024-11-18 14:31:26 +00:00
Petr Viktorin d00f7b1b9d
gh-125063: marshal: Add version 5, improve documentation (GH-126829)
* Document that slices can be marshalled
* Deduplicate and organize the list of supported types
  in docs
* Organize the type code list in marshal.c, to make
  it more obvious that this is a versioned format
* Back-fill some historical info

Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-11-15 13:48:57 +01:00
Peter Bierma d4c72fed8c
gh-126312: Don't traverse frozen objects on the free-threaded build (#126338)
Also, _PyGC_Freeze() no longer freezes unreachable objects.

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-11-15 11:21:30 +01:00
Mark Shannon c0f045f7fd
GH-124567: Reduce overhead of debug build for GC. Should help CI performance (GH-126777) 2024-11-15 08:59:01 +00:00
Sergey B Kirpichev d9e251223e
gh-103951: enable optimization for fast attribute access on module subclasses (GH-126264)
Co-authored-by: Nicolas Tessore <n.tessore@ucl.ac.uk>
2024-11-15 16:03:38 +08:00
Yuxuan Zhang 8cc6e5c875
gh-126757: fix minor typo (GH-126758) 2024-11-12 13:23:40 -08: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
Eric Snow 73cf069099
gh-76785: Improved Subinterpreters Compatibility with 3.12 (2/2) (gh-126707)
These changes makes it easier to backport the _interpreters, _interpqueues, and _interpchannels modules to Python 3.12.

This involves the following:

* add the _PyXI_GET_STATE() and _PyXI_GET_GLOBAL_STATE() macros
* add _PyXIData_lookup_context_t and _PyXIData_GetLookupContext()
* add _Py_xi_state_init() and _Py_xi_state_fini()
2024-11-12 10:41:51 -07:00
Hugo van Kemenade 91f4908798
gh-126133: Only use start year in PSF copyright, remove end years (#126236) 2024-11-12 15:59:19 +02:00
Daehee Kim 0ef84b0e2b
gh-126209: Fix inconsistency of `skip_file_prefixes` in `warnings.warn`'s C and Python implementations (GH-126329)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-11-12 13:01:56 +01:00
Diego Russo c45be8aa71
GH-126195: Use M1 JIT memory protection APIs (GH-126196) 2024-11-11 17:20:10 -08:00
Eric Snow a6d48e8f83
gh-76785: Improved Subinterpreters Compatibility with 3.12 (1/2) (gh-126704)
These changes makes it easier to backport the _interpreters, _interpqueues, and _interpchannels modules to Python 3.12.

This involves the following:

* rename several structs and typedefs
* add several typedefs
* stop using the PyThreadState.state field directly in parking_lot.c
2024-11-11 15:58:46 -07:00
Eric Snow b697d8c48e
gh-76785: Minor Cleanup of Exception-related Cross-interpreter State (gh-126602)
This change makes it easier to backport the _interpreters, _interpqueues, and _interpchannels modules to Python 3.12.
2024-11-11 14:49:41 -07:00
Ken Jin 6293d00e72
gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2024-11-09 11:35:33 +08:00
Xuanteng Huang 6ec886531f
gh-126072: Set docstring attribute for module and class (#126231) 2024-11-08 15:13:18 +00:00
Serhiy Storchaka a93fc0969e
gh-126579: Adapt sys.audit() to Argument Clinic (GH-126580) 2024-11-08 13:11:44 +00:00
Serhiy Storchaka 061e50f196
gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords (GH-126564)
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
2024-11-08 14:23:50 +02:00
Valery Fedorenko 9ecd8f7f40
gh-126171: fix possible null dereference in _imp_find_frozen_impl (#126566) 2024-11-08 15:49:15 +05:30
Serhiy Storchaka 06a8b0bb5e
gh-122943: Remove the object converter for var-positional parameter (GH-126560) 2024-11-08 05:41:54 +00:00
Bénédikt Tran c222441fa7
gh-120017: use 'do-while(0)' in some `{codegen,compile}.c` multi-line macros (#120018) 2024-11-07 23:03:11 +00:00
Serhiy Storchaka 1f777396f5
gh-122943: Rework support of var-positional parameter in Argument Clinic (GH-122945)
Move creation of a tuple for var-positional parameter out of
_PyArg_UnpackKeywordsWithVararg().
Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords().
Add a new parameter in _PyArg_UnpackKeywords().

The "parameters" and "converters" attributes of ParseArgsCodeGen no
longer contain the var-positional parameter. It is now available as the
"varpos" attribute. Optimize code generation for var-positional
parameter and reuse the same generating code for functions with and without
keyword parameters.

Add special converters for var-positional parameter. "tuple" represents it as
a Python tuple and "array" represents it as a continuous array of PyObject*.
"object" is a temporary alias of "tuple".
2024-11-07 23:40:03 +02:00
Eric Snow 9357fdcaf0
gh-76785: Minor Cleanup of "Cross-interpreter" Code (gh-126457)
The primary objective here is to allow some later changes to be cleaner. Mostly this involves renaming things and moving a few things around.

* CrossInterpreterData -> XIData
* crossinterpdatafunc -> xidatafunc
* split out pycore_crossinterp_data_registry.h
* add _PyXIData_lookup_t
2024-11-07 09:32:42 -07:00
Aditya Borikar 3d9f9ae5a7
Chore: Fix typo in `pyarena.c` (#126527) 2024-11-07 16:37:41 +01:00
Kirill Podoprigora 6e03ff2419
gh-126513: Use helpers for `_Py_Specialize_ConstainsOp` (#126517)
* Use helpers for _Py_Specialize_ConstainsOp

* Remove unnecessary variable
2024-11-06 13:52:15 -08:00
mpage 9ce4fa0719
gh-115999: Introduce helpers for (un)specializing instructions (#126414)
Introduce helpers for (un)specializing instructions

Consolidate the code to specialize/unspecialize instructions into
two helper functions and use them in `_Py_Specialize_BinaryOp`.
The resulting code is more concise and keeps all of the logic at
the point where we decide to specialize/unspecialize an instruction.
2024-11-06 12:04:04 -08:00
Donghee Na 4ea214ea98
gh-115999: Add free-threaded specialization for CONTAINS_OP (gh-126450)
- The specialization logic determines the appropriate specialization using only the operand's type, which is safe to read non-atomically (changing it requires stopping the world). We are guaranteed that the type will not change in between when it is checked and when we specialize the bytecode because the types involved are immutable (you cannot assign to `__class__` for exact instances of `dict`, `set`, or `frozenset`). The bytecode is mutated atomically using helpers.
- The specialized instructions rely on the operand type not changing in between the `DEOPT_IF` checks and the calls to the appropriate type-specific helpers (e.g. `_PySet_Contains`). This is a correctness requirement in the default builds and there are no changes to the opcodes in the free-threaded builds that would invalidate this.
2024-11-06 03:35:10 +00:00
Savannah Ostrowski c3a12ae13e
GH-125911: Rename big trampoline to "shim" (GH-126339) 2024-11-05 15:26:46 -08:00
Valery Fedorenko 8525c9375f
gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (#126239)
* Replace Py_DECREF by Py_XDECREF

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-11-05 20:34:33 +03:00
Peter Bierma 1371295e67
gh-126366: Fix crash if `__iter__` raises an exception during `yield from` (#126369) 2024-11-05 15:26:36 +05:30
Kirill Podoprigora 78015818c2
gh-126415: Fix conversion warning in `Python/bytecodes.c` (#126416)
Fix conversion warning in bytecodes

Co-authored-by: mpage <mpage@cs.stanford.edu>
2024-11-05 04:12:31 +02:00
mpage 2e95c5ba3b
gh-115999: Implement thread-local bytecode and enable specialization for `BINARY_OP` (#123926)
Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads.

Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization.

Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.
2024-11-04 11:13:32 -08:00
Nice Zombies 3032fcd90e
gh-119793: Add optional length-checking to `map()` (GH-120471)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
2024-11-04 15:00:19 +01:00
Donghee Na 8161afe51c
gh-125832: Reformat comments for inlined comprehensions (gh-126346) 2024-11-03 04:15:07 +00:00
rimchoi 868bfcc02e
gh-125832: Clarify comment for inlined comprehensions as per PEP-709 (#126322)
* Fix comprehensions comment to inlined by pep 709

* Update spacing

Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>

* Add reference to PEP 709

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: RUANG (James Roy) <longjinyii@outlook.com>
2024-11-02 17:04:53 +00:00
mpage f0c6fccd08
gh-126255: Ignore warning about JIT being deactivated when perf support is active in `test_embed.InitConfigTests.test_initconfig_api` (#126302)
Temporarily ignore warnings about JIT deactivation when perf support is active. 
This will be reverted as soon as a way is found to determine at run time whether the interpreter was built with JIT. Currently, this is not possible on Windows.


Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-11-01 23:10:58 +00:00
Sergey B Kirpichev 8477951a1c
gh-120026: soft deprecate Py_HUGE_VAL macro (#120027)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-11-01 22:04:31 +00:00
Xuanteng Huang 35df4eb959
gh-126072: do not add `None` to `co_consts` if there is no docstring (GH-126101) 2024-10-30 09:01:09 +00:00
Pablo Galindo Salgado 2d37c719ed
gh-124855: Don't allow the JIT and perf support to be active at the same time (#124856) 2024-10-30 00:12:45 +00:00
Brian Schubert 224c370a36
gh-126139: Improve error message location for future statement with unknown feature (#126140) 2024-10-29 23:57:59 +00:00
Tomas R. aab58a93ef
gh-118423: Add `INSTRUCTION_SIZE` macro to code generator (GH-125467) 2024-10-29 17:25:05 +00:00
sobolevn b2eaa75b17
gh-126105: Fix crash in `ast` module, when `._fields` is deleted (#126115)
Previously, if the `ast.AST._fields` attribute was deleted, attempts to create a new `as`t node would crash due to the assumption that `_fields` always had a non-NULL value. Now it has been fixed by adding an extra check to ensure that `_fields` does not have a NULL value (this can happen when you manually remove `_fields` attribute).
2024-10-29 17:42:48 +02:00
Mark Shannon faa3272fb8
GH-125837: Split `LOAD_CONST` into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
2024-10-29 11:15:42 +00:00
Brandt Bucher b5b06349eb
GH-125912: Teach the JIT's optimizer about _BINARY_OP_INPLACE_ADD_UNICODE (GH-125935) 2024-10-28 14:37:16 -07:00
Mark Shannon 25441592db
GH-125515: Reduce number of compiler warnings in generated code (GH-125697) 2024-10-28 10:30:31 +00:00
devdanzin 80eec52fc8
gh-126018: Avoid aborting due to unnecessary assert in `sys.audit` (#126020)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-27 07:41:42 -07:00
Nadeshiko Manju 7f6e884f3a
GH-125911: Call combine_symbol_mask on the initial trampoline of a trace (GH-125973) 2024-10-25 15:43:02 +00:00
Sam Gross 332356b880
gh-125900: Clean-up logic around immortalization in free-threading (#125901)
* Remove `@suppress_immortalization` decorator
* Make suppression flag per-thread instead of per-interpreter
* Suppress immortalization in `eval()` to avoid refleaks in three tests
  (test_datetime.test_roundtrip, test_logging.test_config8_ok, and
   test_random.test_after_fork).
* frozenset() is constant, but not a singleton. When run multiple times,
  the test could fail due to constant interning.
2024-10-24 18:09:59 -04:00
Shantanu 500f5338a8
gh-123930: Better error for "from imports" when script shadows module (#123929) 2024-10-24 12:11:12 -07:00
Sam Gross 3c4a7fa617
gh-124218: Avoid refcount contention on builtins module (GH-125847)
This replaces `_PyEval_BuiltinsFromGlobals` with
`_PyDict_LoadBuiltinsFromGlobals`, which returns a new reference
instead of a borrowed reference. Internally, the new function uses
per-thread reference counting when possible to avoid contention on the
refcount fields on the builtins module.
2024-10-24 12:44:38 -04:00
Sam Gross ad6110a93f
gh-125842: Fix `sys.exit(0xffff_ffff)` on Windows (#125896)
On Windows, `long` is a signed 32-bit integer so it can't represent
`0xffff_ffff` without overflow. Windows exit codes are unsigned 32-bit
integers, so if a child process exits with `-1`, it will be represented
as `0xffff_ffff`.

Also fix a number of other possible cases where `_Py_HandleSystemExit`
could return with an exception set, leading to a `SystemError` (or
fatal error in debug builds) later on during shutdown.
2024-10-24 12:03:50 -04:00
Sam Gross e545ead66c
gh-125859: Fix crash when `gc.get_objects` is called during GC (#125882)
This fixes a crash when `gc.get_objects()` or `gc.get_referrers()` is
called during a GC in the free threading build.

Switch to `_PyObjectStack` to avoid corrupting the `struct worklist`
linked list maintained by the GC. Also, don't return objects that are frozen
(`gc.freeze()`) or in the process of being collected to more closely match
the behavior of the default build.
2024-10-24 09:33:11 -04:00
Mark Shannon b61fece852
GH-125868: Fix STORE_ATTR_WITH_HINT specialization (GH-125876) 2024-10-24 11:57:02 +01:00
Eric Snow 6f26d496d3
gh-125286: Share the Main Refchain With Legacy Interpreters (gh-125709)
They used to be shared, before 3.12.  Returning to sharing them resolves a failure on Py_TRACE_REFS builds.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-10-23 10:10:06 -06:00
Mikhail Efimov 079875e395
gh-125038: Fix crash after genexpr.gi_frame.f_locals manipulations (#125178) 2024-10-22 09:00:25 -07:00
Mark Shannon 57e3c59bb6
GH-125521: Remove `if (true)` from generated output to reduce C compiler warnings (GH-125700) 2024-10-22 10:11:29 +01:00
mpage de5a6c7c7d
gh-121459: Fix a couple of uses of `PyStackRef_FromPyObjectSteal` (#125711)
* Fix usage of PyStackRef_FromPyObjectSteal in CALL_TUPLE_1

This was missed in gh-124894

* Fix usage of PyStackRef_FromPyObjectSteal in _CALL_STR_1

This was missed in gh-124894

* Regenerate code
2024-10-21 11:08:13 -07:00
Sam Gross 9b0bfba2a2
gh-124218: Use per-thread reference counting for globals and builtins (#125713)
Use per-thread refcounting for the reference from function objects to
the globals and builtins dictionaries.
2024-10-21 12:51:29 -04:00
Pablo Galindo Salgado 3d1df3d84e
gh-125703: Correctly honour tracemalloc hooks on more PyDECREF specialized paths (#125712) 2024-10-21 15:39:05 +01:00
Michael Droettboom c8fd4b12e3
gh-125207: Fix MSVC 1935 build with JIT (#125209)
* gh-125207: Use {0} array initializers

* Simplify, as suggested in PR

* Revert change to explicitly specify length
2024-10-18 15:51:29 -04:00
Eric Snow 6d93690954
gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)
This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed.

We do the following:

* add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there
* inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState
* move struct _reftracer_runtime_state to the existing pycore_object_state.h
* add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks
* add audit.h and cpython/audit.h and move the existing audit-related API there
*move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
2024-10-18 09:26:08 -06:00
Sam Gross d8c8648161
gh-125541: Make Ctrl-C interrupt `threading.Lock.acquire()` on Windows (#125546) 2024-10-17 20:10:55 +02:00
Michael Droettboom 37986e830b
gh-123153: Fix PGO builds with free-threading on Windows (#125607)
* gh-123153: Fix PGO builds with free-threading

* Redo how the #define works
2024-10-17 08:20:30 -04:00
Michael Droettboom 51410d8bdc
gh-125217: Turn off optimization around_PyEval_EvalFrameDefault to avoid MSVC crash (#125477) 2024-10-16 12:51:15 +00:00
Kirill Podoprigora bee112a94d
gh-124872: Replace enter/exit events with "switched" (#125532)
Users want to know when the current context switches to a different
context object.  Right now this happens when and only when a context
is entered or exited, so the enter and exit events are synonymous with
"switched".  However, if the changes proposed for gh-99633 are
implemented, the current context will also switch for reasons other
than context enter or exit.  Since users actually care about context
switches and not enter or exit, replace the enter and exit events with
a single switched event.

The former exit event was emitted just before exiting the context.
The new switched event is emitted after the context is exited to match
the semantics users expect of an event with a past-tense name.  If
users need the ability to clean up before the switch takes effect,
another event type can be added in the future.  It is not added here
because YAGNI.

I skipped 0 in the enum as a matter of practice.  Skipping 0 makes it
easier to troubleshoot when code forgets to set zeroed memory, and it
aligns with best practices for other tools (e.g.,
https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).

Co-authored-by: Richard Hansen <rhansen@rhansen.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-16 13:53:21 +02:00
Sam Gross 3ea488aac4
gh-124218: Use per-thread refcounts for code objects (#125216)
Use per-thread refcounting for the reference from function objects to
their corresponding code object. This can be a source of contention when
frequently creating nested functions. Deferred refcounting alone isn't a
great fit here because these references are on the heap and may be
modified by other libraries.
2024-10-15 15:06:41 -04:00
Sam Gross 54c6fcbefd
gh-124375: Avoid calling `_PyMem_ProcessDelayed` on other thread states (#124459)
This fixes a crash when running the PyO3 test suite on the free-threaded
build. The `qsbr` field is initialized after the `PyThreadState` is
added to the interpreter's linked list -- it might still be NULL.

Instead, we "steal" the queue of to-be-freed memory blocks. This is
always initialized (possibly empty) and protected by the stop the world
pause.
2024-10-15 16:09:35 +00:00
Kirill Podoprigora d3c82b9cce
gh-125512: Revert "gh-124872: Replace enter/exit events with "switched" (#124776)" (#125513) 2024-10-15 17:42:16 +03:00
Victor Stinner aa18fd55d5
gh-125196: Use PyUnicodeWriter in HAMT (#125458) 2024-10-15 09:47:36 +00:00
RUANG (Roy James) 546dddca43
gh-125234: Make PyInitConfig_Free(NULL) a no-op (#125266) 2024-10-15 09:21:16 +00:00
sobolevn 0c8c665581
gh-125470: Fix warning in `Python/generated_cases.c.h` (#125471)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-10-14 23:46:17 +03:00
Richard Hansen 843d28f59d
gh-124872: Replace enter/exit events with "switched" (#124776)
Users want to know when the current context switches to a different
context object.  Right now this happens when and only when a context
is entered or exited, so the enter and exit events are synonymous with
"switched".  However, if the changes proposed for gh-99633 are
implemented, the current context will also switch for reasons other
than context enter or exit.  Since users actually care about context
switches and not enter or exit, replace the enter and exit events with
a single switched event.

The former exit event was emitted just before exiting the context.
The new switched event is emitted after the context is exited to match
the semantics users expect of an event with a past-tense name.  If
users need the ability to clean up before the switch takes effect,
another event type can be added in the future.  It is not added here
because YAGNI.

I skipped 0 in the enum as a matter of practice.  Skipping 0 makes it
easier to troubleshoot when code forgets to set zeroed memory, and it
aligns with best practices for other tools (e.g.,
https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum).
2024-10-14 12:28:41 -07:00
Mark Shannon 06ca33020e
GH-125323: Convert DECREF_INPUTS_AND_REUSE_FLOAT into a function that takes PyStackRefs. (GH-125439) 2024-10-14 14:18:57 +01:00
Kumar Aditya 67f6e08147
gh-125139: use `_PyRecursiveMutex` in `_thread.RLock` (#125144) 2024-10-14 14:06:31 +05:30
Ken Jin 4b358ee647
gh-125323: Remove some unsafe Py_DECREFs in bytecodes.c, replacing them with PyStackRef_CLOSEs (GH-125324) 2024-10-14 09:17:51 +01:00
Kumar Aditya 08489325d1
gh-125161: return non zero value in pthread_self on wasi (#125303) 2024-10-13 20:59:41 +05:30
Richard Hansen 330c527299
gh-124872: Change PyContext_WatchCallback to take PyObject (#124737)
The PyContext struct is not intended to be public, and users of the
API don't need anything more specific than PyObject.  Also see
gh-78943.
2024-10-12 13:57:27 -07:00
Richard Hansen 62d5a53a0b
gh-124872: Move PyThreadState to first argument for consistency (#124774) 2024-10-12 12:33:00 -07:00
Kumar Aditya 5d8739e956
gh-111924: use atomics for interp id refcounting (#125321) 2024-10-12 12:40:34 +05:30
Sam Gross 427dcf24de
gh-125268: Use static string for "1e309" in AST (#125272)
When formatting the AST as a string, infinite values are replaced by
1e309, which evaluates to infinity. The initialization of this string
replacement was not thread-safe in the free threading build.
2024-10-10 16:21:29 -04:00
Mark Shannon c9014374c5
GH-125174: Make immortal objects more robust, following design from PEP 683 (GH-125251) 2024-10-10 18:19:08 +01:00
Victor Stinner 942916378a
gh-125196: Use PyUnicodeWriter for repr(contextvars.Token) (#125220)
Replace the private _PyUnicodeWriter with the public PyUnicodeWriter.
2024-10-09 23:37:14 +00:00
Victor Stinner 9bda7750c2
gh-125196: Use PyUnicodeWriter in symtable.c (#125199) 2024-10-09 17:54:54 +02:00
mpage f978fb4f8d
gh-115999: Refactor `LOAD_GLOBAL` specializations to avoid reloading {globals, builtins} keys (gh-124953)
Each of the `LOAD_GLOBAL` specializations is implemented roughly as:

1. Load keys version.
2. Load cached keys version.
3. Deopt if (1) and (2) don't match.
4. Load keys.
5. Load cached index into keys.
6. Load object from (4) at offset from (5).

This is not thread-safe in free-threaded builds; the keys object may be replaced
in between steps (3) and (4).

This change refactors the specializations to avoid reloading the keys object and
instead pass the keys object from guards to be consumed by downstream uops.
2024-10-09 15:18:25 +00:00
Victor Stinner b9a8ca0a6a
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194)
Replace PyUnicode_New(0, 0), PyUnicode_FromString("")
and PyUnicode_FromStringAndSize("", 0)
with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
2024-10-09 17:15:23 +02:00
Tomas R. 6b533a659b
gh-125039: Make `this_instr`/`prev_instr` const in cases generator (GH-125071) 2024-10-09 13:54:39 +01:00
Victor Stinner e0c87c64b1
gh-124502: Remove _PyUnicode_EQ() function (#125114)
* Replace unicode_compare_eq() with unicode_eq().
* Use unicode_eq() in setobject.c.
* Replace _PyUnicode_EQ() with _PyUnicode_Equal().
* Remove unicode_compare_eq() and _PyUnicode_EQ().
2024-10-09 10:15:17 +02:00
Michael Droettboom c6127af868
gh-125063: Emit slices as constants in the bytecode compiler (#125064)
* Make slices marshallable

* Emit slices as constants

* Update Python/marshal.c

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

* Refactor codegen_slice into two functions so it
always has the same net effect

* Fix for free-threaded builds

* Simplify marshal loading of slices

* Only return SUCCESS/ERROR from codegen_slice

---------

Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-10-08 13:18:39 -04:00
mpage e99f159be4
gh-115999: Stop the world when invalidating function versions (#124997)
Stop the world when invalidating function versions

The tier1 interpreter specializes `CALL` instructions based on the values
of certain function attributes (e.g. `__code__`, `__defaults__`). The tier1
interpreter uses function versions to verify that the attributes of a function
during execution of a specialization match those seen during specialization.
A function's version is initialized in `MAKE_FUNCTION` and is invalidated when
any of the critical function attributes are changed. The tier1 interpreter stores
the function version in the inline cache during specialization. A guard is used by
the specialized instruction to verify that the version of the function on the operand
stack matches the cached version (and therefore has all of the expected attributes).
It is assumed that once the guard passes, all attributes will remain unchanged
while executing the rest of the specialized instruction.

Stopping the world when invalidating function versions ensures that all critical
function attributes will remain unchanged after the function version guard passes
in free-threaded builds. It's important to note that this is only true if the remainder
of the specialized instruction does not enter and exit a stop-the-world point.

We will stop the world the first time any of the following function attributes
are mutated:

- defaults
- vectorcall
- kwdefaults
- closure
- code

This should happen rarely and only happens once per function, so the performance
impact on majority of code should be minimal.

Additionally, refactor the API for manipulating function versions to more clearly
match the stated semantics.
2024-10-08 10:04:35 -04:00
Mikhail Efimov 9a35d05338
gh-121404: typo fix in compile.c: MATADATA -> METADATA (#125101) 2024-10-08 12:18:28 +00:00
Mark Shannon d1453f60c2
GH-121459: Streamline PyObject* to PyStackRef conversions by disallowing NULL pointers. (GH-124894) 2024-10-07 18:13:04 +01:00
Mark Shannon da071fa3e8
GH-119866: Spill the stack around escaping calls. (GH-124392)
* Spill the evaluation around escaping calls in the generated interpreter and JIT. 

* The code generator tracks live, cached values so they can be saved to memory when needed.

* Spills the stack pointer around escaping calls, so that the exact stack is visible to the cycle GC.
2024-10-07 14:56:39 +01:00
Mark Shannon f55273b3b7
GH-116968: Remove branch from advance_backoff_counter (GH-124469) 2024-10-07 11:46:33 +01:00
Tomas R. a1be83dae3
gh-125010: Fix `use-after-free` in AST `repr()` (#125015) 2024-10-06 12:46:03 -07:00
Donghee Na a5fc50994a
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)
* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
2024-10-05 11:27:32 +09:00
Irit Katriel f474391b26
gh-124871: fix 'visited' tracking in compiler's reachability analysis (#124952) 2024-10-04 17:37:38 +01:00
Victor Stinner 6c7d5c6415
gh-111178: Fix function signatures in Python-ast.c (#124942) 2024-10-04 11:59:08 +02:00
Brandt Bucher 6810928927
GH-118093: Don't lose confidence when tracing through 100% biased branches (GH-124813) 2024-10-02 19:24:37 +00:00
Diego Russo b85923a0fe
GH-119726: Deduplicate AArch64 trampolines within a trace (GH-123872) 2024-10-02 12:07:20 -07:00
Ken Jin b84a763dca
gh-120619: Optimize through `_Py_FRAME_GENERAL` (GH-124518)
* Optimize through _Py_FRAME_GENERAL

* refactor
2024-10-03 01:10:51 +08:00
Jeremy Maitin-Shepard 8cc5aa47ee
gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805)
Instead of surprise crashes and memory corruption, we now hang threads that attempt to re-enter the Python interpreter after Python runtime finalization has started. These are typically daemon threads (our long standing mis-feature) but could also be threads spawned by extension modules that then try to call into Python. This marks the `PyThread_exit_thread` public C API as deprecated as there is no plausible safe way to accomplish that on any supported platform in the face of things like C++ code with finalizers anywhere on a thread's stack. Doing this was the least bad option.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-10-02 09:17:49 -07:00
Tian Gao 5e0abb4788
gh-116750: Add clear_tool_id function to unregister events and callbacks (#124568) 2024-10-01 13:32:55 -04:00
Sam Gross b482538523
gh-124218: Refactor per-thread reference counting (#124844)
Currently, we only use per-thread reference counting for heap type objects and
the naming reflects that. We will extend it to a few additional types in an
upcoming change to avoid scaling bottlenecks when creating nested functions.

Rename some of the files and functions in preparation for this change.
2024-10-01 17:05:42 +00:00
Sam Gross 5aa91c56bf
gh-124296: Remove private dictionary version tag (PEP 699) (#124472) 2024-10-01 12:39:56 -04:00
Serhiy Storchaka d08c788822
gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)
Instead of be limited just by the size of addressable memory (2**63
bytes), Python integers are now also limited by the number of bits, so
the number of bit now always fit in a 64-bit integer.

Both limits are much larger than what might be available in practice,
so it doesn't affect users.

_PyLong_NumBits() and _PyLong_Frexp() are now always successful.
2024-09-29 10:40:20 +03:00
Bénédikt Tran c00964ecd5
gh-124665: Add `_PyCodec_UnregisterError` and `_codecs._unregister_error` (#124677) 2024-09-29 02:25:23 +02:00
Kira 04c837d9d8
gh-124442: make `__static_attributes__` deterministic by sorting (#124492)
Signed-off-by: kp2pml30 <kp2pml30@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-09-28 15:15:43 -07:00
Pablo Galindo Salgado 02b49c5150
gh-107954: Fix configuration type for the perf profiler (#124636) 2024-09-28 01:50:16 +02:00
Jelle Zijlstra 365dffbaad
gh-119180: No longer set `__annotations__` in `__main__` (#124634) 2024-09-27 05:49:43 -07:00
Neil Schemenauer 6f9525dd3f
gh-116510: Fix crash during sub-interpreter shutdown (gh-124645)
Fix a bug that can cause a crash when sub-interpreters use "basic"
single-phase extension modules.  Shared objects could refer to PyGC_Head
nodes that had been freed as part of interpreter shutdown.
2024-09-26 19:33:07 -07:00