summaryrefslogtreecommitdiffstats
path: root/Include/cpython
Commit message (Collapse)AuthorAgeFilesLines
* gh-127787: Move _PyUnicodeError_GetParams() to the internal C API (#128803)Victor Stinner2025-01-141-6/+0
|
* gh-127773: Disable attribute cache on incompatible MRO entries (GH-127924)Petr Viktorin2025-01-131-1/+11
|
* gh-127350: Add Py_fopen() and Py_fclose() functions (#127821)Victor Stinner2025-01-061-2/+8
|
* gh-128137: Update PyASCIIObject to handle interned field with the atomic ↵Donghee Na2025-01-051-7/+13
| | | | operation (gh-128196)
* gh-127787: refactor helpers for `PyUnicodeErrorObject` internal interface ↵Bénédikt Tran2025-01-031-0/+6
| | | | | | | | | | | | | | | | | | | | | | (GH-127789) - Unify `get_unicode` and `get_string` in a single function. - Allow to retrieve the underlying `object` attribute, its size, and the adjusted 'start' and 'end', all at once. Add a new `_PyUnicodeError_GetParams` internal function for this. (In `exceptions.c`, it's somewhat common to not need all the attributes, but the compiler has opportunity to inline the function and optimize unneeded work away. Outside that file, we'll usually need all or most of them at once.) - Use a common implementation for the following functions: - `PyUnicode{Decode,Encode}Error_GetEncoding` - `PyUnicode{Decode,Encode,Translate}Error_GetObject` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}Reason` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}{Start,End}`
* gh-127274: Defer nested methods (#128012)mpage2024-12-191-0/+3
| | | | | | | 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.
* GH-122548: Implement branch taken and not taken events for sys.monitoring ↵Mark Shannon2024-12-192-15/+34
| | | | (GH-122564)
* gh-128008: Add `PyWeakref_IsDead()` (GH-128009)Sam Gross2024-12-191-0/+3
| | | | | | | | | The `PyWeakref_IsDead()` function tests if a weak reference is dead without any side effects. Although you can also detect if a weak reference is dead using `PyWeakref_GetRef()`, that function returns a strong reference that must be `Py_DECREF()`'d, which can introduce side effects if the last reference is concurrently dropped (at least in the free threading build).
* gh-127599: Fix _Py_RefcntAdd missing calls to ↵Ed Nutting2024-12-151-0/+6
| | | | | | | | _Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC (#127717) Previously, `_Py_RefcntAdd` hasn't called `_Py_INCREF_STAT_INC/_Py_INCREF_IMMORTAL_STAT_INC` which is incorrect. Now it has been fixed.
* gh-102471, PEP 757: Add PyLong import and export API (#121339)Victor Stinner2024-12-131-0/+38
| | | | | Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Steve Dower <steve.dower@microsoft.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* Add `extern "C"` around `PyTraceMalloc_` functions. (#127772)Peter Hawkins2024-12-111-0/+6
| | | | Pretty much everything else exported by Python.h has an extern "C" annotation, yet this header appears to be missing one.
* gh-126925: Modify how iOS test results are gathered (#127592)Russell Keith-Magee2024-12-091-0/+3
| | | | | | | 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.
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-031-1/+7
| | | | | | | | | | | | | | | | | | * 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.
* gh-117657: TSAN Fix races in `PyMember_Get` and `PyMember_Set` for C ↵Daniele Parmeggiani2024-12-034-0/+347
| | | | extensions (GH-123211)
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-12-021-0/+2
| | | | | | | | | | | | | 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.
* gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)Sergey B Kirpichev2024-11-261-0/+6
| | | | | | | | | | | | | | | "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).
* Improve comment for co_nlocalsplus (#126993)Jacob Bower2024-11-211-1/+2
|
* Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Hugo van Kemenade2024-11-191-2/+0
| | | | collection (GH-126502)" (#126983)
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-11-181-0/+2
| | | | | | | | | | | | | | | | 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.
* gh-123619: Add an unstable C API function for enabling deferred reference ↵Peter Bierma2024-11-131-0/+7
| | | | | | counting (GH-123635) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-126061: Add PyLong_IsPositive/Zero/Negative() functions (#126065)RUANG (James Roy)2024-11-121-0/+18
| | | | | Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-042-0/+20
| | | | | | | | | `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.
* gh-126072: do not add `None` to `co_consts` if there is no docstring (GH-126101)Xuanteng Huang2024-10-301-0/+5
|
* gh-124218: Use per-thread reference counting for globals and builtins (#125713)Sam Gross2024-10-211-1/+3
| | | | Use per-thread refcounting for the reference from function objects to the globals and builtins dictionaries.
* gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)Eric Snow2024-10-183-22/+26
| | | | | | | | | | | | 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
* gh-124872: Replace enter/exit events with "switched" (#125532)Kirill Podoprigora2024-10-161-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). Co-authored-by: Richard Hansen <rhansen@rhansen.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* 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
|