summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* gh-111178: Fix function signatures for test_os (#131227)Victor Stinner2025-03-141-3/+5
|
* gh-111178: Fix function signatures to fix undefined behavior (#131191)Victor Stinner2025-03-143-15/+21
|
* gh-111178: Fix function signatures for PyStdPrinter (#131192)Victor Stinner2025-03-141-11/+15
|
* gh-121464: Make concurrent iteration over enumerate safe under ↵Pieter Eendebak2025-03-131-20/+38
| | | | free-threading (#125734)
* gh-111178: Fix function signatures in misc files (#131180)Victor Stinner2025-03-131-4/+6
|
* gh-129149: Add fast path for medium-sized integers in `PyLong_FromSsize_t()` ↵Chris Eibl2025-03-131-105/+40
| | | | | | | | | | | | (#129301) The implementation of `PyLong_FromLong()`, `PyLong_FromLongLong()` and `PyLong_FromSsize_t()` are now handled by a common macro `PYLONG_FROM_INT` which contains fast paths depending on the size of the integer to convert. Consequently, `PyLong_FromSsize_t()` for medium-sized integers is faster by roughly 25%. --------- Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
* gh-111178: Fix function signatures in odictobject.c (#131160)Victor Stinner2025-03-131-57/+77
| | | Add _PyODictObject_CAST() macro.
* gh-111178: Fix function signatures in rangeobject.c (#131161)Victor Stinner2025-03-131-24/+27
|
* gh-111178: Fix PyRangeIter_Type deallocator (#131162)Victor Stinner2025-03-131-1/+1
| | | | | Don't use PyObject_Free() as tp_dealloc to avoid an undefined behavior. Instead, use the default deallocator which just calls tp_free which is PyObject_Free().
* gh-111178: Fix function signatures in iterobject.c (#131163)Victor Stinner2025-03-131-10/+15
|
* gh-111178: Change Argument Clinic signature for `@staticmethod` (#131157) ↵Victor Stinner2025-03-133-6/+6
| | | | | | (#131159) Use "PyObject*", instead of "void*", for `@staticmethod` functions to fix an undefined behavior.
* GH-127705: Fix _Py_RefcntAdd to handle objects becoming immortal (GH-131140)Mark Shannon2025-03-121-1/+1
|
* gh-111178: Change Argument Clinic signature for `@classmethod` (#131157)Victor Stinner2025-03-1212-28/+93
| | | | Use "PyObject*", instead of "PyTypeObject*", for `@classmethod` functions to fix an undefined behavior.
* gh-115999: Add free-threaded specialization for FOR_ITER (#128798)T. Wouters2025-03-121-0/+26
| | | | Add free-threaded versions of existing specialization for FOR_ITER (list, tuples, fast range iterators and generators), without significantly affecting their thread-safety. (Iterating over shared lists/tuples/ranges should be fine like before. Reusing iterators between threads is not fine, like before. Sharing generators between threads is a recipe for significant crashes, like before.)
* gh-120608: Make reversed iterator work with free-threading (#120971)Pieter Eendebak2025-03-121-9/+20
| | | | | Co-authored-by: Sam Gross <colesbury@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* gh-129349: Accept bytes in bytes.fromhex()/bytearray.fromhex() (#129844)Daniel Pope2025-03-124-68/+54
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-111178: Fix function signatures in rangeobject.c (#131101)Victor Stinner2025-03-121-23/+34
|
* gh-131113: Fix data race in dict.popitem() (gh-131115)Sam Gross2025-03-111-8/+8
| | | | The clearing of the key, hash, and value need to use atomic operations to avoid a data race with concurrent read operations.
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-1117-60/+190
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* GH-127705: Use `_PyStackRef`s in the default build. (GH-127875)Mark Shannon2025-03-102-14/+20
|
* gh-130851: Only intern constants of types generated by the compiler (#130901)Sam Gross2025-03-071-2/+41
| | | | | | | | | | | | | The free-threading build interns and immortalizes most constants generated by the bytecode compiler. However, users can construct their own code objects with arbitrary constants. We should not intern or immortalize these objects if they are not of a type that we know how to handle. This change fixes a reference leak failure in the recently added `test_code.test_unusual_constants` test. It also addresses a potential crash that could occur when attempting to destroy an immortalized object during interpreter shutdown.
* gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing ↵Shantanu2025-03-071-1/+3
| | | | | | | | | | | | | | (#130934) I chose to not raise an exception here because I think it would be confusing for module attribute access to start raising something other than AttributeError if e.g. the cwd goes away Without the change in moduleobject.c ``` ./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure ... Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253. ```
* gh-118331: Fix a couple of issues when list allocation fails (#130811)mpage2025-03-051-0/+1
| | | | | | | | | | | | | | | | * Fix use after free in list objects Set the items pointer in the list object to NULL after the items array is freed during list deallocation. Otherwise, we can end up with a list object added to the free list that contains a pointer to an already-freed items array. * Mark `_PyList_FromStackRefStealOnSuccess` as escaping I think technically it's not escaping, because the only object that can be decrefed if allocation fails is an exact list, which cannot execute arbitrary code when it is destroyed. However, this seems less intrusive than trying to special cases objects in the assert in `_Py_Dealloc` that checks for non-null stackpointers and shouldn't matter for performance.
* gh-130851: Don't crash when deduping unusual code constants (#130853)Sam Gross2025-03-051-6/+12
| | | | | | | | | | The bytecode compiler only generates a few different types of constants, like str, int, tuple, slices, etc. Users can construct code objects with various unusual constants, including ones that are not hashable or not even constant. The free threaded build previously crashed with a fatal error when confronted with these constants. Instead, treat distinct objects of otherwise unhandled types as not equal for the purposes of deduplication.
* GH-127705: better double free message. (GH-130785)Mark Shannon2025-03-051-1/+1
| | | | | * Add location information when accessing already closed stackref * Add #def option to track closed stackrefs to provide precise information for use after free and double frees.
* gh-130794: Process interpreter QSBR queue in _PyMem_AbandonDelayed. (gh-130808)Sam Gross2025-03-041-9/+22
| | | | | This avoids a case where the interpreter's queue of memory to be freed could grow rapidly if there are many short lived threads.
* gh-105499: Merge typing.Union and types.UnionType (#105511)Jelle Zijlstra2025-03-042-110/+342
| | | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Ken Jin <kenjin@python.org> Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-126085: Add `tp_iter` to TypeAliasType to allow star unpacking (#127981)Tomas R.2025-03-041-7/+8
|
* gh-130547: Fix race between dict_dealloc and split_keys_entry_added (gh-130778)Donghee Na2025-03-041-1/+1
|
* gh-111178: Fix function signatures in structseq.c (#130683)Victor Stinner2025-03-041-9/+12
|
* gh-111178: Fix function signatures of unicodeiter (#130684)Victor Stinner2025-03-041-19/+23
|
* gh-130599: use static constants str-to-int conversion (gh-130714)Neil Schemenauer2025-03-041-22/+53
| | | | | | Avoid a data race in free-threaded builds due to mutating global arrays at runtime. Instead, compute the constants with an external Python script and then define them as static global constant arrays. These constants are used by `long_from_non_binary_base()`.
* gh-124445: Allow specializing generic ParamSpec aliases (#124512)Tomas R.2025-03-031-2/+71
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-130790: Remove references about unicode's readiness from comments (#130801)Sergey Miryanov2025-03-032-2/+0
|
* gh-128974: Fix `UnicodeError.__str__` when custom attributes have ↵Bénédikt Tran2025-03-011-15/+44
| | | | | side-effects (#128975) Fix some crashes when (custom) attributes of `UnicodeError` objects implement `object.__str__` with side-effects.
* Postpone <stdbool.h> inclusion after Python.h (#130641)Hugo Beauzée-Luyssen2025-02-281-2/+2
| | | | | | | Remove inclusions prior to Python.h. <stdbool.h> will cause <features.h> to be included before Python.h can define some macros to enable some additional features, causing multiple types not to be defined down the line.
* gh-127271: Remove the PyCell_Get usage for framelocalsproxy (#130383)Tian Gao2025-02-271-20/+59
|
* gh-129107: fix thread safety of `bytearray` where two critical sections are ↵Tomasz Pytel2025-02-271-6/+20
| | | | needed (#130227)
* gh-111178: Fix function signatures in sliceobject.c (#130575)Victor Stinner2025-02-261-9/+17
| | | Rename slicehash() to slice_hash() for consistency.
* gh-111178: Fix function signatures in namespaceobject.c (#130590)Victor Stinner2025-02-261-10/+16
|
* gh-130519: Fix crash in QSBR when destructor reenters QSBR (gh-130553)Sam Gross2025-02-261-9/+31
| | | | | | | The `free_work_item()` function in QSBR may call arbitrary code via Python object destructors, which may reenter the QSBR code. Reorder the processing of work items to be robust to reentrancy. Also fix the TODO for the out of memory situation.
* gh-117657: Use an atomic store to set type flags. (gh-127588)Neil Schemenauer2025-02-261-47/+83
| | | | | The `PyType_HasFeature()` function reads the flags with a relaxed atomic load and without holding the type lock. To avoid data races, use atomic stores if `PyType_Ready()` has already been called.
* gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)Serhiy Storchaka2025-02-251-1/+7
| | | | | | | | The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
* gh-130202: Fix bug in `_PyObject_ResurrectEnd` in free threaded build ↵Sam Gross2025-02-251-14/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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-87790: support thousands separators for formatting fractional part of ↵Sergey B Kirpichev2025-02-252-12/+28
| | | | | | | | | | | | | | floats (#125304) ```pycon >>> f"{123_456.123_456:_._f}" # Whole and fractional '123_456.123_456' >>> f"{123_456.123_456:_f}" # Integer component only '123_456.123456' >>> f"{123_456.123_456:._f}" # Fractional component only '123456.123_456' >>> f"{123_456.123_456:.4_f}" # with precision '123456.1_235' ```
* gh-111178: fix UBSan failures in `Objects/typevarobject.c` (GH-129800)Bénédikt Tran2025-02-251-89/+114
| | | | | | | Fix UBSan failures for `typealiasobject`, `paramspecobject`, `typevarobject`, `typevartupleobject`, `paramspecattrobject` Use _PyCFunction_CAST macros Use macro for `constevaluatorobject` casts
* gh-111178: fix UBSan failures in `Objects/typeobject.c` (#129799)Bénédikt Tran2025-02-251-68/+92
| | | | | | Fix UBSan failures for `PyTypeObject`. Introduce a macro cast for `superobject` and remove redundant casts. Rename the unused parameter in getter/setter methods to `closure` for semantic purposes.
* GH-130396: Use computed stack limits on linux (GH-130398)Mark Shannon2025-02-251-30/+1
| | | | | | | | | | | * 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-241-1/+30
| | | | | | | | | 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-130313: Avoid locking when clearing objects (#130126)Dino Viehland2025-02-201-44/+73
| | | Avoid locking when clearing objects in the free-threaded build