summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* gh-142737: Handle lost `io.open` in `_Py_FindSourceFile` (GH-142747)Bartosz Sławecki2025-12-151-0/+1
|
* gh-134584: Remove custom float decref ops (GH-142576)Ken Jin2025-12-151-7/+0
|
* gh-142472: Clean-up _PyStackRef functions (gh-142479)Sam Gross2025-12-151-1/+1
| | | | | | | | This combines most _PyStackRef functions and macros between the free threaded and default builds. - Remove Py_TAG_DEFERRED (same as Py_TAG_REFCNT) - Remove PyStackRef_IsDeferred (same as !PyStackRef_RefcountOnObject)
* gh-139871: Optimize bytearray construction with encoding (#142243)Cody Maloney2025-12-151-1/+16
| | | | | | | | | | | | | | | | | | | When a `str` is encoded in `bytearray.__init__` the encoder tends to create a new unique bytes object. Rather than allocate new memory and copy the bytes use the already created bytes object as bytearray backing. The bigger the `str` the bigger the saving. Mean +- std dev: [main_encoding] 497 us +- 9 us -> [encoding] 14.2 us +- 0.3 us: 34.97x faster ```python import pyperf runner = pyperf.Runner() runner.timeit( name="encode", setup="a = 'a' * 1_000_000", stmt="bytearray(a, encoding='utf8')") ```
* gh-132657: Use stronger memory ordering for so->mask. (gh-142735)Neil Schemenauer2025-12-151-5/+5
| | | | | We need to use release/acquire ordering for the 'mask' member of the set structure. Without this, `set_lookkey_threadsafe()` could be looking at the old value of `table` but the new value of `mask`.
* gh-142554: avoid `divmod` crashes due to bad `_pylong.int_divmod` (#142673)Bénédikt Tran2025-12-141-2/+2
|
* gh-132657: Add lock-free set contains implementation (#132290)Neil Schemenauer2025-12-132-116/+317
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This roughly follows what was done for dictobject to make a lock-free lookup operation. With this change, the set contains operation scales much better when used from multiple-threads. The frozenset contains performance seems unchanged (as already lock-free). Summary of changes: * refactor set_lookkey() into set_do_lookup() which now takes a function pointer that does the entry comparison. This is similar to dictobject and do_lookup(). In an optimized build, the comparison function is inlined and there should be no performance cost to this. * change set_do_lookup() to return a status separately from the entry value * add set_compare_frozenset() and use if the object is a frozenset. For the free-threaded build, this avoids some overhead (locking, atomic operations, incref/decref on key) * use FT_ATOMIC_* macros as needed for atomic loads and stores * use a deferred free on the set table array, if shared (only on free-threaded build, normal build always does an immediate free) * for free-threaded build, use explicit for loop to zero the table, rather than memcpy() * when mutating the set, assign so->table to NULL while the change is a happening. Assign the real table array after the change is done.
* gh-142217: Deprecate the private _Py_Identifier C API (#142221)Victor Stinner2025-12-122-0/+6
| | | | | | | Deprecate functions: * _PyObject_CallMethodId() * _PyObject_GetAttrId() * _PyUnicode_FromId()
* gh-142534: Avoid TSan warnings in dictobject.c (gh-142544)Sam Gross2025-12-111-6/+6
| | | | | | There are places we use "relaxed" loads where C11 requires "consume" or stronger. Unfortunately, compilers don't really implement "consume" so fake it for our use in a way that avoids upsetting TSan.
* gh-142589: Fix PyUnstable_Object_IsUniqueReferencedTemporary (gh-142593)Sam Gross2025-12-111-2/+6
| | | | PyUnstable_Object_IsUniqueReferencedTemporary wasn't handling tagged ints on the evaluation stack properly.
* gh-123241: Don't modify ref count during visitation (GH-142232)Dino Viehland2025-12-111-13/+29
|
* gh-142433: Move deref to below the error when checking for laststring (#142402)AZero132025-12-101-1/+2
| | | | Move deref of laststring to below the error checking so the deref is applied after the object in strings is replaced.
* gh-141770: Annotate anonymous mmap usage if "-X dev" is used (gh-142079)Donghee Na2025-12-081-0/+2
|
* gh-141732: Fix `ExceptionGroup` repr changing when original exception ↵dr-carlos2025-12-071-11/+76
| | | | sequence is mutated (#141736)
* gh-142218: Fix split table dictionary crash (gh-142229)Sam Gross2025-12-031-3/+7
| | | | | This fixes a regression introduced in gh-140558. The interpreter would crash if we inserted a non `str` key into a split table that matches an existing key.
* gh-142038: Expand guard for types_world_is_stopped() to fix debug builds ↵Uwe L. Korn2025-12-031-1/+1
| | | | without assertions (#142039)
* gh-142217: Remove internal _Py_Identifier functions (#142219)Victor Stinner2025-12-034-116/+0
| | | | | | | | | | | | | | | | Remove internal functions: * _PyDict_ContainsId() * _PyDict_DelItemId() * _PyDict_GetItemIdWithError() * _PyDict_SetItemId() * _PyEval_GetBuiltinId() * _PyObject_CallMethodIdNoArgs() * _PyObject_CallMethodIdObjArgs() * _PyObject_CallMethodIdOneArg() * _PyObject_VectorcallMethodId() * _PyUnicode_EqualToASCIIId() These functions were not exported and so no usable outside CPython.
* gh-139165: Make Py_SIZE, Py_IS_TYPE,Py_ SET_SIZE regular functions in stable ↵Petr Viktorin2025-11-251-18/+13
| | | | | | | | | | | | ABI (GH-139166) * Make Py_{SIZE,IS_TYPE,SET_SIZE} regular functions in stable ABI Group them together with Py_TYPE & Py_SET_TYPE to cut down on repetitive preprocessor macros. Format repetitive definitions in object.c more concisely. Py_SET_TYPE is still left out of the Limited API.
* gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (GH-141785)Petr Viktorin2025-11-241-0/+17
|
* gh-139871: Optimize small takes in bytearray.take_bytes (GH-141741)Cody Maloney2025-11-201-1/+13
| | | | | When less than half the buffer is taken just copy that small part out rather than doing a big alloc + memmove + big shrink.
* gh-41779: Allow defining the __dict__ and __weakref__ __slots__ for any ↵Serhiy Storchaka2025-11-191-13/+16
| | | | class (GH-141755)
* gh-139103: fix free-threading `dataclass.__init__` perf issue (gh-141596)Edward Xu2025-11-191-0/+12
| | | The dataclasses `__init__` function is generated dynamically by a call to `exec()` and so doesn't have deferred reference counting enabled. Enable deferred reference counting on functions when assigned as an attribute to type objects to avoid reference count contention when creating dataclass instances.
* gh-141070: Add PyUnstable_Object_Dump() function (#141072)Victor Stinner2025-11-182-3/+4
| | | | | | | | | | * Promote _PyObject_Dump() as a public function. * Keep _PyObject_Dump() alias to PyUnstable_Object_Dump() for backward compatibility. * Replace _PyObject_Dump() with PyUnstable_Object_Dump(). Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* GH-141312: Allow only integers to longrangeiter_setstate state (GH-141317)Sergey Miryanov2025-11-141-0/+5
| | | This fixes an assertion error when the new computed start is not an integer.
* gh-131510: Use PyUnstable_Unicode_GET_CACHED_HASH() (GH-141520)Victor Stinner2025-11-142-3/+2
| | | | | | | | Replace code that directly accesses PyASCIIObject.hash with PyUnstable_Unicode_GET_CACHED_HASH(). Remove redundant "assert(PyUnicode_Check(op))" from PyUnstable_Unicode_GET_CACHED_HASH(), _PyASCIIObject_CAST() already implements the check.
* gh-140550: Use a bool for the Py_mod_gil value (GH-141519)Petr Viktorin2025-11-141-7/+8
| | | | | | | | This needs a single bit, but was stored as a void* in the module struct. This didn't matter due to packing, but now that there's another bool in the struct, we can save a bit of memory by making md_gil a bool. Variables that changed type are renamed, to detect conflicts.
* gh-139109: A new tracing JIT compiler frontend for CPython (GH-140310)Ken Jin2025-11-133-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR changes the current JIT model from trace projection to trace recording. Benchmarking: better pyperformance (about 1.7% overall) geomean versus current https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251108-3.15.0a1%2B-7e2bc1d-JIT/bm-20251108-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-7e2bc1d-vs-base.svg, 100% faster Richards on the most improved benchmark versus the current JIT. Slowdown of about 10-15% on the worst benchmark versus the current JIT. **Note: the fastest version isn't the one merged, as it relies on fixing bugs in the specializing interpreter, which is left to another PR**. The speedup in the merged version is about 1.1%. https://raw.githubusercontent.com/facebookexperimental/free-threading-benchmarking/refs/heads/main/results/bm-20251112-3.15.0a1%2B-f8a764a-JIT/bm-20251112-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-f8a764a-vs-base.svg Stats: 50% more uops executed, 30% more traces entered the last time we ran them. It also suggests our trace lengths for a real trace recording JIT are too short, as a lot of trace too long aborts https://github.com/facebookexperimental/free-threading-benchmarking/blob/main/results/bm-20251023-3.15.0a1%2B-eb73378-CLANG%2CJIT/bm-20251023-vultr-x86_64-Fidget%252dSpinner-tracing_jit-3.15.0a1%2B-eb73378-pystats-vs-base.md . This new JIT frontend is already able to record/execute significantly more instructions than the previous JIT frontend. In this PR, we are now able to record through custom dunders, simple object creation, generators, etc. None of these were done by the old JIT frontend. Some custom dunders uops were discovered to be broken as part of this work gh-140277 The optimizer stack space check is disabled, as it's no longer valid to deal with underflow. Pros: * Ignoring the generated tracer code as it's automatically created, this is only additional 1k lines of code. The maintenance burden is handled by the DSL and code generator. * `optimizer.c` is now significantly simpler, as we don't have to do strange things to recover the bytecode from a trace. * The new JIT frontend is able to handle a lot more control-flow than the old one. * Tracing is very low overhead. We use the tail calling interpreter/computed goto interpreter to switch between tracing mode and non-tracing mode. I call this mechanism dual dispatch, as we have two dispatch tables dispatching to each other. Specialization is still enabled while tracing. * Better handling of polymorphism. We leverage the specializing interpreter for this. Cons: * (For now) requires tail calling interpreter or computed gotos. This means no Windows JIT for now :(. Not to fret, tail calling is coming soon to Windows though https://github.com/python/cpython/pull/139962 Design: * After each instruction, the `record_previous_inst` function/label is executed. This does as the name suggests. * The tracing interpreter lowers bytecode to uops directly so that it can obtain "fresh" values at the point of lowering. * The tracing version behaves nearly identical to the normal interpreter, in fact it even has specialization! This allows it to run without much of a slowdown when tracing. The actual cost of tracing is only a function call and writes to memory. * The tracing interpreter uses the specializing interpreter's deopt to naturally form the side exit chains. This allows it to side exit chain effectively, without repeating much code. We force a re-specializing when tracing a deopt. * The tracing interpreter can even handle goto errors/exceptions, but I chose to disable them for now as it's not tested. * Because we do not share interpreter dispatch, there is should be no significant slowdown to the original specializing interpreter on tailcall and computed got with JIT disabled. With JIT enabled, there might be a slowdown in the form of the JIT trying to trace. * Things that could have dynamic instruction pointer effects are guarded on. The guard deopts to a new instruction --- `_DYNAMIC_EXIT`.
* gh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` ↵Cody Maloney2025-11-133-85/+198
| | | | | | | | | | | | | | | | | | | | | | | (GH-140128) Update `bytearray` to contain a `bytes` and provide a zero-copy path to "extract" the `bytes`. This allows making several code paths more efficient. This does not move any codepaths to make use of this new API. The documentation changes include common code patterns which can be made more efficient with this API. --- When just changing `bytearray` to contain `bytes` I ran pyperformance on a `--with-lto --enable-optimizations --with-static-libpython` build and don't see any major speedups or slowdowns with this; all seems to be in the noise of my machine (Generally changes under 5% or benchmarks that don't touch bytes/bytearray). Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Maurycy Pawłowski-Wieroński <5383+maurycy@users.noreply.github.com>
* gh-141004: soft-deprecate Py_INFINITY macro (#141033)Sergey B Kirpichev2025-11-122-5/+5
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-141042: fix sNaN's packing for mixed floating-point formats (#141107)Sergey B Kirpichev2025-11-121-4/+12
|
* gh-140476: optimize `PySet_Add` for `frozenset` in free-threading (#140440)Alper2025-11-111-9/+16
| | | | | Avoids critical section in `PySet_Add` when adding items to newly created frozensets. Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-132657: optimize `PySet_Contains` for `frozenset` (#141183)Kumar Aditya2025-11-111-1/+3
|
* gh-141376: Fix exported symbols (GH-141377)Victor Stinner2025-11-111-8/+8
| | | | | | | | | | * gh-141376: Fix exported symbols * _io module: add "_Py_" prefix to "spec" variables. For example, rename bufferedrandom_spec to _Py_bufferedrandom_spec. * typevarobject.c: add "static" to "spec" and "slots" variables. * import.c: add "static" to "pkgcontext" variable. * No longer export textiowrapper_slots
* gh-111389: replace deprecated occurrences of `_PyHASH_*` macros (#141236)Bénédikt Tran2025-11-092-20/+20
|
* gh-140939: Fix memory leak in `_PyBytes_FormatEx` error path (#140957)Stan Ulbrych2025-11-061-0/+1
|
* gh-133467: Fix typeobject `tp_base` race in free threading (gh-140549)Edward Xu2025-11-051-0/+10
|
* gh-140550: Initial implementation of PEP 793 – PyModExport (GH-140556)Petr Viktorin2025-11-052-82/+301
| | | | Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-140815: Fix faulthandler for invalid/freed frame (#140921)Victor Stinner2025-11-041-3/+20
| | | | | | | | | | | | | faulthandler now detects if a frame or a code object is invalid or freed. Add helper functions: * _PyCode_SafeAddr2Line() * _PyFrame_SafeGetCode() * _PyFrame_SafeGetLasti() _PyMem_IsPtrFreed() now detects pointers in [-0xff, 0xff] range as freed.
* gh-140348: Fix using | on unusual objects plus Unions (#140383)Jelle Zijlstra2025-11-031-1/+16
|
* gh-134786: raise error if `Py_TPFLAGS_MANAGED_WEAKREF` or ↵Sergey Miryanov2025-11-021-0/+14
| | | | `Py_TPFLAGS_MANAGED_DICT` is used without `Py_TPFLAGS_HAVE_GC` set (#135863)
* gh-140373: Correctly emit `PY_UNWIND` event when generator is closed (GH-140767)Mikhail Efimov2025-10-311-1/+2
|
* gh-55531: Implement `normalize_encoding` in C (#136643)Stan Ulbrych2025-10-301-7/+8
| | | Closes gh-55531
* gh-139353: Add Objects/unicode_writer.c file (#139911)Victor Stinner2025-10-302-638/+668
| | | | | | | Move the public PyUnicodeWriter API and the private _PyUnicodeWriter API to a new Objects/unicode_writer.c file. Rename a few helper functions to share them between unicodeobject.c and unicode_writer.c, such as resize_compact() or unicode_result().
* gh-129117: Add unicodedata.isxidstart() function (#140269)Stan Ulbrych2025-10-302-0/+2
| | | | | | Expose `_PyUnicode_IsXidContinue/Start` in `unicodedata`: add isxidstart() and isxidcontinue() functions. Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-140551: Fix `dict` crash if `clear` is called at `lookup` stage (#140558)Mikhail Efimov2025-10-291-50/+32
| | | Co-authored-by: Inada Naoki <songofacandy@gmail.com>
* Remove dead stores to 'size' in UTF-8 decoder (unicodeobject.c) (#140637)Shamil2025-10-271-2/+0
|
* gh-140544: use faster `_PyInterpreterState_GET` for type lock (#140584)Kumar Aditya2025-10-251-1/+1
|
* gh-140431: Fix GC crash due to partially initialized coroutines (gh-140470)Sam Gross2025-10-231-0/+1
| | | | | | The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC.
* gh-132835: Add defensive NULL checks to MRO resolution (GH-134763)Emma Smith2025-10-211-4/+10
| | | | | | | | | | Currently, there are a few places where tp_mro could theoretically become NULL, but do not in practice. This commit adds defensive checks for NULL values to ensure that any changes do not introduce a crash and that state invariants are upheld. The assertions added in this commit are all instances where a NULL value would get passed to something not expecting a NULL, so it is better to catch an assertion failure than crash later on. There are a few cases where it is OK for the return of lookup_tp_mro to be NULL, such as when passed to is_subtype_with_mro, which handles this explicitly.
* GH-139951: Fix major GC performance regression (GH-140262)Mark Shannon2025-10-211-4/+35
| | | | | * Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead * Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.