summaryrefslogtreecommitdiffstats
path: root/Include/cpython
Commit message (Collapse)AuthorAgeFilesLines
* Revert "gh-133395: add option for extension modules to specialize ↵Irit Katriel2025-05-061-12/+0
| | | | BINARY_OP/SUBSCR, apply to arrays (#133396)" (#133498)
* gh-132775: Unrevert "Add _PyCode_GetVarCounts()" (gh-133265)Eric Snow2025-05-051-0/+5
| | | | | | This reverts commit 811edcf (gh-133232), which itself reverted the original commit 811edcf (gh-133128). We reverted the original change due to failing s390 builds (a big-endian architecture). It ended up that I had not accommodated op caches.
* gh-133140: Add `PyUnstable_Object_IsUniquelyReferenced` for free-threading ↵Peter Bierma2025-05-051-0/+2
| | | | (#133144)
* gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, ↵Irit Katriel2025-05-051-0/+12
| | | | apply to arrays (#133396)
* GH-133231: Changes to executor management to support proposed `sys._jit` ↵Mark Shannon2025-05-041-1/+1
| | | | | | | | module (GH-133287) * Track the current executor, not the previous one, on the thread-state. * Batch executors for deallocation to avoid having to constantly incref executors; this is an ad-hoc form of deferred reference counting.
* gh-128972: Add `_Py_ALIGN_AS` and revert `PyASCIIObject` memory layout. ↵Petr Viktorin2025-05-021-10/+20
| | | | | | | | | | | | | (GH-133085) Add `_Py_ALIGN_AS` as per C API WG vote: https://github.com/capi-workgroup/decisions/issues/61 This patch only adds it to free-threaded builds; the `#ifdef Py_GIL_DISABLED` can be removed in the future. Use this to revert `PyASCIIObject` memory layout for non-free-threaded builds. The long-term plan is to deprecate the entire struct; until that happens it's better to keep it unchanged, as courtesy to people that rely on it despite it not being stable ABI.
* gh-133164: Add `PyUnstable_Object_IsUniqueReferencedTemporary` C API (gh-133170)Sam Gross2025-05-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with `LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references on the interpreter stack when the bytecode compiler can determine that it's safe. This change broke some checks in C API extensions that relied on `Py_REFCNT()` of `1` to determine if it's safe to modify an object in-place. Objects may have a reference count of one, but still be referenced further up the interpreter stack due to borrowing of references. This provides a replacement function for those checks. `PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative: it checks that the object has a reference count of one and that it exists as a unique strong reference in the interpreter's stack of temporary variables in the top most frame. See also: * https://github.com/numpy/numpy/issues/28681 Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: mpage <mpage@cs.stanford.edu> Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626)Irit Katriel2025-05-011-1/+1
|
* PyStats: Make sure that the `failure_kinds` array is big enough. (#133245)Mark Shannon2025-05-011-1/+1
|
* Revert "gh-132775: Add _PyCode_GetVarCounts() (gh-133128)" (gh-133232)Eric Snow2025-05-011-5/+0
| | | | | The change broke the s390 builds, so I'm reverting it while I investigate. This reverts commit 94b4fcd806e7b692955173d309ea3b70a193ad96.
* gh-132775: Add _PyCode_GetVarCounts() (gh-133128)Eric Snow2025-04-301-0/+5
| | | | | | | This helper is useful in a variety of ways, including in demonstrating how the different counts relate to one another. It will be used in a later change to help identify if a function is "stateless", meaning it doesn't have any free vars or globals. Note that a majority of this change is tests.
* GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)Mark Shannon2025-04-301-70/+3
|
* gh-133079: Remove Py_C_RECURSION_LIMIT & PyThreadState.c_recursion_remaining ↵Petr Viktorin2025-04-291-4/+0
| | | | | | | | (GH-133080) Both were added in 3.13, are undocumented, and don't make sense in 3.14 due to changes in the stack overflow detection machinery (gh-112282). PEP 387 exception for skipping a deprecation period: https://github.com/python/steering-council/issues/288
* gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)Eric Snow2025-04-281-2/+0
| | | | | We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API. We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released. This is used by a later change related to pickle and handling __main__.
* gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703)Sergey B Kirpichev2025-04-221-6/+0
|
* gh-132449: Improve syntax error messages for keywords with typos (#132450)Pablo Galindo Salgado2025-04-221-0/+1
| | | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* gh-132639: Adds PyLong_AsNativeBytes, PyLong_FromNativeBytes and ↵Steve Dower2025-04-211-51/+0
| | | | PyLong_FromUnsignedNativeBytes to the limited API (GH-132640)
* gh-131927: Prevent emitting optimizer warnings twice in the REPL (#131993)Tomas R.2025-04-121-0/+6
|
* gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)Neil Schemenauer2025-04-091-0/+2
| | | | | | | | | | | | | | | | | | | | Make `warnings.catch_warnings()` use a context variable for holding the warning filtering state if the `sys.flags.context_aware_warnings` flag is set to true. This makes using the context manager thread-safe in multi-threaded programs. Add the `sys.flags.thread_inherit_context` flag. If true, starting a new thread with `threading.Thread` will use a copy of the context from the caller of `Thread.start()`. Both these flags are set to true by default for the free-threaded build and false for the default build. Move the Python implementation of warnings.py into _py_warnings.py. Make _contextvars a builtin module. Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-100239: more stats for BINARY_OP/SUBSCR specialization (#132230)Irit Katriel2025-04-081-1/+1
|
* gh-100239: more refined specialisation stats for BINARY_OP/SUBSCR (#132068)Irit Katriel2025-04-041-1/+1
|
* gh-131591: Implement PEP 768 (#131937)Pablo Galindo Salgado2025-04-032-0/+9
| | | | Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com> Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
* gh-131525: Cache the result of tuple_hash (#131529)Michael Droettboom2025-03-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gh-131525: Cache the result of tuple_hash * Fix debug builds * Add blurb * Fix formatting * Pre-compute empty tuple singleton * Mostly set the cache within tuple_alloc * Fixes for TSAN * Pre-compute empty tuple singleton * Fix for 32-bit platforms * Assert that op != NULL in _PyTuple_RESET_HASH_CACHE * Use FT_ATOMIC_STORE_SSIZE_RELAXED macro * Update Include/internal/pycore_tuple.h Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> * Fix alignment * atomic load * Update Objects/tupleobject.c Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> --------- Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
* GH-131238: Core header refactor (GH-131250)Mark Shannon2025-03-172-53/+1
| | | | | * Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
* gh-131306: Remove unused code related to `BINARY_SUBSCR` (#131307)Tomas R.2025-03-161-1/+1
|
* gh-130947: Add again PySequence_Fast() to the limited C API (#130948)Victor Stinner2025-03-131-9/+0
| | | | | Add again PySequence_Fast() to the limited C API. Add unit tests.
* gh-131121: Fix `_Py_atomic_store_char_relaxed` memory order (gh-131122)Sam Gross2025-03-121-1/+1
|
* gh-124878: Fix race conditions during interpreter finalization (#130649)Sam Gross2025-03-061-3/+5
| | | | | | | | | | | | | | | | | | | | The PyThreadState field gains a reference count field to avoid issues with PyThreadState being a dangling pointer to freed memory. The refcount starts with a value of two: one reference is owned by the interpreter's linked list of thread states and one reference is owned by the OS thread. The reference count is decremented when the thread state is removed from the interpreter's linked list and before the OS thread calls `PyThread_hang_thread()`. The thread that decrements it to zero frees the `PyThreadState` memory. The `holds_gil` field is moved out of the `_status` bit field, to avoid a data race where on thread calls `PyThreadState_Clear()`, modifying the `_status` bit field while the OS thread reads `holds_gil` when attempting to acquire the GIL. The `PyThreadState.state` field now has `_Py_THREAD_SHUTTING_DOWN` as a possible value. This corresponds to the `_PyThreadState_MustExit()` check. This avoids race conditions in the free threading build when checking `_PyThreadState_MustExit()`.
* gh-130790: Remove references about unicode's readiness from comments (#130801)Sergey Miryanov2025-03-031-5/+4
|
* gh-46236: PyUnicode docs improvements (GH-129966)Petr Viktorin2025-02-281-2/+2
| | | | | | | | | | | | | | | | | | | Move deprecated PyUnicode API docs to new section Move Py_UNICODE to a new "Deprecated API" section. Formally soft-deprecate PyUnicode_READY, and move it Document and soft-deprecate PyUnicode_IS_READY, and move it Document PyUnicode_IS_ASCII, PyUnicode_CHECK_INTERNED PyUnicode_New docs: Clarify requirements for "fresh" strings PyUnicodeWriter_DecodeUTF8Stateful: Link "error-handlers" Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* GH-130396: Increase trashcan overhead (GH-130552)Mark Shannon2025-02-261-2/+2
| | | Double trashcan overhead
* gh-130202: Fix bug in `_PyObject_ResurrectEnd` in free threaded build ↵Sam Gross2025-02-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (gh-130281) This fixes a fairly subtle bug involving finalizers and resurrection in debug free threaded builds: if `_PyObject_ResurrectEnd` returns `1` (i.e., the object was resurrected by a finalizer), it's not safe to access the object because it might still be deallocated. For example: * The finalizer may have exposed the object to another thread. That thread may hold the last reference and concurrently deallocate it any time after `_PyObject_ResurrectEnd()` returns `1`. * `_PyObject_ResurrectEnd()` may call `_Py_brc_queue_object()`, which may internally deallocate the object immediately if the owning thread is dead. Therefore, it's important not to access the object after it's resurrected. We only violate this in two cases, and only in debug builds: * We assert that the object is tracked appropriately. This is now moved up betewen the finalizer and the `_PyObject_ResurrectEnd()` call. * The `--with-trace-refs` builds may need to remember the object if it's resurrected. This is now handled by `_PyObject_ResurrectStart()` and `_PyObject_ResurrectEnd()`. Note that `--with-trace-refs` is currently disabled in `--disable-gil` builds because the refchain hash table isn't thread-safe, but this refactoring avoids an additional thread-safety issue.
* GH-130396: Use computed stack limits on linux (GH-130398)Mark Shannon2025-02-252-37/+8
| | | | | | | | | | | * Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not ↵Petr Viktorin2025-02-242-8/+37
| | | | | | | | | counters. (GH-130007)" for now (GH130413) Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now Unfortunatlely, the change broke some buildbots. This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
* gh-128863: Deprecate the private _PyUnicodeWriter API (#129245)Victor Stinner2025-02-201-32/+28
| | | | | | | | | | | | | | | Deprecate private C API functions: * _PyUnicodeWriter_Init() * _PyUnicodeWriter_Finish() * _PyUnicodeWriter_Dealloc() * _PyUnicodeWriter_WriteChar() * _PyUnicodeWriter_WriteStr() * _PyUnicodeWriter_WriteSubstring() * _PyUnicodeWriter_WriteASCIIString() * _PyUnicodeWriter_WriteLatin1String() These functions are not deprecated in the internal C API (if the Py_BUILD_CORE macro is defined).
* GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)Mark Shannon2025-02-192-37/+8
| | | | | | | | | | | | * Implement C recursion protection with limit pointers * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* gh-129107: make `bytearray` thread safe (#129108)Tomasz Pytel2025-02-151-0/+4
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* GH-129715: Remove _DYNAMIC_EXIT (GH-129716)Brandt Bucher2025-02-071-0/+1
|
* GH-128842: Collect JIT memory stats (GH-128941)Diego Russo2025-02-021-0/+8
|
* gh-91417: Remove PySequence_Fast() from the limited C API (#129398)Victor Stinner2025-02-021-0/+26
| | | | The function never worked with the limited C API. It was added by mistake.
* gh-89188: Implement PyUnicode_KIND() as a function (#129412)Victor Stinner2025-01-301-2/+6
| | | | | Implement PyUnicode_KIND() and PyUnicode_DATA() as function, in addition to the macros with the same names. The macros rely on C bit fields which have compiler-specific layout.
* gh-128911: Add PyImport_ImportModuleAttr() function (#128912)Victor Stinner2025-01-301-0/+7
| | | | | | | | | | | 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.
* gh-127119: Faster check for small ints in long_dealloc (GH-127620)Pieter Eendebak2025-01-291-2/+2
|
* gh-129296: Fix `pyatomic.h` include paths (#129320)Zanie Blue2025-01-292-4/+4
| | | | | | | Use relative includes in Include/cpython/pyatomic.h for pyatomic_gcc.h, pyatomic_std.h and pyatomic_msc.h. Do a similar change in Include/cpython/pythread.h for pthread_stubs.h include.
* gh-128844: Make `_Py_TryIncref` public as an unstable API. (#128926)Sam Gross2025-01-281-0/+6
| | | | | | | | | This exposes `_Py_TryIncref` as `PyUnstable_TryIncref()` and the helper function `_PyObject_SetMaybeWeakref` as `PyUnstable_EnableTryIncRef`. These are helpers for dealing with unowned references in a safe way, particularly in the free threading build. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-128509: Add `PyUnstable_IsImmortal` for finding immortal objects (GH-129182)Peter Bierma2025-01-271-0/+3
| | | | | Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-128863: Deprecate _PyLong_FromDigits() function (#127939)Sergey B Kirpichev2025-01-241-1/+1
|
* gh-128863: Deprecate _PyLong_New() function (#129212)Sergey B Kirpichev2025-01-231-1/+1
|
* gh-128863: Deprecate _PyLong_Sign() function (#129176)Victor Stinner2025-01-231-1/+1
| | | Replace _PyLong_Sign() with PyLong_GetSign().
* gh-128863: Deprecate private C API functions (#128864)Victor Stinner2025-01-226-14/+38
| | | | | | | | | | | | | | | 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.