summaryrefslogtreecommitdiffstats
path: root/Include/cpython
Commit message (Collapse)AuthorAgeFilesLines
* gh-124218: Use per-thread refcounts for code objects (#125216)Sam Gross2024-10-152-1/+2
| | | | | | | 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.
* gh-125512: Revert "gh-124872: Replace enter/exit events with "switched" ↵Kirill Podoprigora2024-10-151-4/+13
| | | | (#124776)" (#125513)
* gh-124872: Replace enter/exit events with "switched" (#124776)Richard Hansen2024-10-141-13/+4
| | | | | | | | | | | | | | | | | | | | | | 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).
* gh-124872: Change PyContext_WatchCallback to take PyObject (#124737)Richard Hansen2024-10-121-1/+1
| | | | | 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.
* gh-124872: Refine contextvars documentation (#124773)Richard Hansen2024-10-091-6/+17
| | | | | | | | | | | | | * Add definitions for "context", "current context", and "context management protocol". * Update related definitions to be consistent with the new definitions. * Restructure the documentation for the `contextvars.Context` class to prepare for adding context manager support, and for consistency with the definitions. * Use `testcode` and `testoutput` to test the `Context.run` example. * Expand the documentation for the `Py_CONTEXT_EVENT_ENTER` and `Py_CONTEXT_EVENT_EXIT` events to clarify and to prepare for planned changes.
* gh-111178: Fix function signatures in longobject.c (#124895)Victor Stinner2024-10-021-0/+3
| | | | | | | | | | | | | | * Add _PyLong_CAST() macro. * Move forward declarations to the top of longobject.c. * Change long_add(), long_sub(), long_mul(), long_neg(), long_lshift(), long_abs() to take PyLongObject* and return PyLongObject*. Avoid CHECK_BINOP() test. * Add long_add_method(), long_sub_method(), long_mul_method(), long_neg_method(), long_lshift_method(), and long_abs_method() which take PyObject* and return PyObject*. Implement CHECK_BINOP() test. * Add long_lshift_int64() function. * _PyLong_DivmodNear() calls long_lshift_int64(obj, 1) instead of long_lshift_obj(obj, one).
* gh-111178: Fix function signatures in weakrefobject.c (#124903)Victor Stinner2024-10-021-5/+5
|
* gh-116750: Add clear_tool_id function to unregister events and callbacks ↵Tian Gao2024-10-011-0/+4
| | | | (#124568)
* gh-124296: Remove private dictionary version tag (PEP 699) (#124472)Sam Gross2024-10-011-9/+4
|
* gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)Serhiy Storchaka2024-09-291-3/+2
| | | | | | | | | | | 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.
* gh-119333: get interp from tstate for PyContext watchers(#124444)Jason Fried2024-09-261-3/+2
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-119333: Add C api to have contextvar enter/exit callbacks (#119335)Jason Fried2024-09-241-0/+32
| | | Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* GH-124284: Add stats for refcount operations on immortal objects (GH-124288)Mark Shannon2024-09-231-0/+8
|
* GH-113655: Lower the C recursion limit for HPPA, PPC64 and SPARC (#124264)Sam James2024-09-231-0/+6
| | | | | | | | | Lower the C recursion limit for HPPA, PPC64 and SPARC, as they use relatively large stack frames that cause e.g. `test_descr` to hit a stack overflow. According to quick testing, it seems that values around 8000 are max for HPPA and PPC64 (ELFv1 ABI) and 7000 for SPARC64. To keep things safe, let's use 5000 for PPC64 and 4000 for SPARC. Co-authored-by: Michał Górny <mgorny@gentoo.org>
* gh-124153: Implement `PyType_GetBaseByToken()` and `Py_tp_token` slot ↵neonene2024-09-181-0/+1
| | | | (GH-124163)
* gh-107954, PEP 741: Add PyInitConfig_AddModule() function (#123668)Victor Stinner2024-09-041-0/+4
|
* gh-107954, PEP 741: Add PyInitConfig C API (#123502)Victor Stinner2024-09-031-0/+41
| | | Add Doc/c-api/config.rst documentation.
* gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)Victor Stinner2024-09-021-0/+8
| | | | | | | | | | | Add PyConfig_Get(), PyConfig_GetInt(), PyConfig_Set() and PyConfig_Names() functions to get and set the current runtime Python configuration. Add visibility and "sys spec" to config and preconfig specifications. _PyConfig_AsDict() now converts PyConfig.xoptions as a dictionary. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-122854: Add Py_HashBuffer() function (#122855)Victor Stinner2024-08-301-0/+2
|
* gh-121645: Add PyBytes_Join() function (#121646)Victor Stinner2024-08-301-3/+4
| | | | * Replace _PyBytes_Join() with PyBytes_Join(). * Keep _PyBytes_Join() as an alias to PyBytes_Join().
* gh-121485: Always use 64-bit integers for integers bits count (GH-121486)Serhiy Storchaka2024-08-301-2/+2
| | | | | Use 64-bit integers instead of platform specific size_t or Py_ssize_t to represent the number of bits in Python integer.
* gh-122417: Implement per-thread heap type refcounts (#122418)Sam Gross2024-08-061-0/+3
| | | | | | | The free-threaded build partially stores heap type reference counts in distributed manner in per-thread arrays. This avoids reference count contention when creating or destroying instances. Co-authored-by: Ken Jin <kenjin@python.org>
* gh-120593: Make _PyLong_CompactValue() parameter const again (#122367)Victor Stinner2024-07-281-4/+4
| | | | | Change _PyLong_IsCompact() and _PyLong_CompactValue() parameter type from 'PyObject*' to 'const PyObject*'. Avoid the Py_TYPE() macro which does not support const parameter.
* gh-121489: Export private _PyBytes_Join() again (#122267)Marc Mueller2024-07-251-0/+4
|
* gh-120973: Fix thread-safety issues with `threading.local` (#121655)mpage2024-07-191-0/+8
| | | | | | This is a small refactoring to the current design that allows us to avoid manually iterating over threads. This should also fix gh-118490.
* gh-121621: Move asyncio_running_loop to private struct (#121939)Sam Gross2024-07-171-2/+0
| | | | This avoids changing the ABI and keeps the field in the private struct.
* GH-121583: Remove dependency from pystats.h to internal header file (GH-121587)Michael Droettboom2024-07-161-5/+5
| | | Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* gh-121621: Move asyncio running loop to thread state (GH-121695)Ken Jin2024-07-161-0/+2
|
* gh-120642: Move _PyCode_CODE() to the internal C API (#121644)Victor Stinner2024-07-131-3/+0
| | | | Move _PyCode_CODE() and _PyCode_NBYTES() macros to the internal C API since they use _Py_CODEUNIT which is only part of the internal C API.
* gh-89364: Export PySignal_SetWakeupFd() function (#121537)Victor Stinner2024-07-101-1/+1
| | | | Export the PySignal_SetWakeupFd() function. Previously, the function was documented but it couldn't be used in 3rd party code.
* gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388)Sam Gross2024-07-084-0/+26
| | | | | | | | | 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.
* gh-112136: Restore removed _PyArg_Parser (#121262)Victor Stinner2024-07-031-0/+26
| | | | | | | Restore the private _PyArg_Parser structure and the private _PyArg_ParseTupleAndKeywordsFast() function, previously removed in Python 3.13 alpha 1. Recreate Include/cpython/modsupport.h header file.
* gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118)Steve Dower2024-06-281-2/+5
|
* gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053)Victor Stinner2024-06-261-2/+2
| | | | | | | | | | | | | | | | | | Remove the const qualifier of the argument of functions: * _PyLong_IsCompact() * _PyLong_CompactValue() Py_TYPE() argument is not const. Fix the compiler warning: Include/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’: Include/pyport.h:19:31: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual] (...) Include/cpython/longintrepr.h:133:30: note: in expansion of macro ‘Py_TYPE’ assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
* gh-120593: Fix const qualifier in pyatomic.h (#121055)Victor Stinner2024-06-261-4/+4
|
* gh-120642: Move private PyCode APIs to the internal C API (#120643)Victor Stinner2024-06-262-187/+0
| | | | | | | | | | | | | | | * 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()
* gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121010)Eric Snow2024-06-251-4/+5
| | | | | We also add _PyThreadState_NewBound() and drop _PyThreadState_SetWhence(). This change only affects internal API.
* gh-119182: Add PyUnicodeWriter_WriteUCS4() function (#120849)Victor Stinner2024-06-241-0/+4
|
* gh-120834: fix type of *_iframe field in _PyGenObject_HEAD declaration (#120835)Irit Katriel2024-06-241-30/+3
|
* gh-119344: Make critical section API public (#119353)Sam Gross2024-06-211-0/+134
| | | | | | | | | | 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.
* gh-119182: Add PyUnicodeWriter_DecodeUTF8Stateful() (#120639)Victor Stinner2024-06-211-0/+10
| | | | | | Add PyUnicodeWriter_WriteWideChar() and PyUnicodeWriter_DecodeUTF8Stateful() functions. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-117511: Make PyMutex public in the non-limited API (#117731)Sam Gross2024-06-202-1/+64
|
* gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)Sam Gross2024-06-181-0/+2
| | | | | | | | | | | | 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. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-119182: Add PyUnicodeWriter C API (#119184)Victor Stinner2024-06-171-2/+35
|
* gh-83754: Use the Py_TYPE() macro (#120599)Victor Stinner2024-06-171-2/+2
| | | | Don't access directly PyObject.ob_type, but use the Py_TYPE() macro instead.
* Fix typos in comments (#120188)Xie Yanbo2024-06-072-2/+2
|
* gh-116560: Add PyLong_GetSign() public function (#116561)Sergey B Kirpichev2024-06-031-3/+7
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-112026: Deprecate _PyDict_GetItemStringWithError() function (#119855)Victor Stinner2024-06-031-1/+2
|
* gh-119336: Restore removed _PyLong_NumBits() function (#119418)Ethan Smith2024-05-301-0/+9
| | | It is used by the pywin32 project.
* gh-118727: Don't drop the GIL in `drop_gil()` unless the current thread ↵Brett Simmers2024-05-231-1/+3
| | | | | | | | | | | | | | | | | holds it (#118745) `drop_gil()` assumes that its caller is attached, which means that the current thread holds the GIL if and only if the GIL is enabled, and the enabled-state of the GIL won't change. This isn't true, though, because `detach_thread()` calls `_PyEval_ReleaseLock()` after detaching and `_PyThreadState_DeleteCurrent()` calls it after removing the current thread from consideration for stop-the-world requests (effectively detaching it). Fix this by remembering whether or not a thread acquired the GIL when it last attached, in `PyThreadState._status.holds_gil`, and check this in `drop_gil()` instead of `gil->enabled`. This fixes a crash in `test_multiprocessing_pool_circular_import()`, so I've reenabled it.