summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* gh-127085: fix some data races in memoryview in free-threading (#127412)Edward Xu2024-12-161-7/+26
|
* gh-126024: unicodeobject: optimize find_first_nonascii (GH-127790)Inada Naoki2024-12-131-9/+14
| | | Remove 1 branch.
* gh-127691: add type checks when using `PyUnicodeError` objects (GH-127694)Bénédikt Tran2024-12-131-68/+148
|
* gh-102471, PEP 757: Add PyLong import and export API (#121339)Victor Stinner2024-12-131-0/+120
| | | | | 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>
* gh-126868: Add freelist for compact int objects (GH-126865)Pieter Eendebak2024-12-132-19/+60
|
* GH-125174: Mark objects as statically allocated. (#127797)Mark Shannon2024-12-111-1/+11
| | | | | * Set a bit in the unused part of the refcount on 64 bit machines and the free-threaded build. * Use the top of the refcount range on 32 bit machines
* GH-127058: Make `PySequence_Tuple` safer and probably faster. (#127758)Mark Shannon2024-12-112-47/+59
| | | | * Use a small buffer, then list when constructing a tuple from an arbitrary sequence.
* gh-127740: For odd-length input to bytes.fromhex(...) change the error ↵Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి)2024-12-111-4/+14
| | | | message to ValueError: fromhex() arg must be of even length (#127756)
* gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568)Bénédikt Tran2024-12-101-1/+4
| | | | This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
* gh-126491: Revert "GH-126491: Lower heap size limit with faster marking ↵Petr Viktorin2024-12-103-17/+69
| | | | | | | | (GH-127519)" (GH-127770) Revert "GH-126491: Lower heap size limit with faster marking (GH-127519)" This reverts commit 023b7d2141467017abc27de864f3f44677768cb3, which introduced a refleak.
* gh-125420: implement `Sequence.count` API on `memoryview` objects (#125443)Bénédikt Tran2024-12-102-1/+60
|
* gh-125420: implement `Sequence.index` API on `memoryview` objects (#125446)Bénédikt Tran2024-12-102-1/+134
|
* gh-123378: fix post-merge typos in comments and NEWS (#127739)Bénédikt Tran2024-12-081-3/+3
|
* gh-127314: Don't mention the GIL when calling without a thread state on the ↵Peter Bierma2024-12-061-0/+7
| | | | | free-threaded build (#127315) Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-126024: fix UBSan failure in `unicodeobject.c:find_first_nonascii` ↵Bénédikt Tran2024-12-061-6/+3
| | | | (GH-127566)
* GH-126491: Lower heap size limit with faster marking (GH-127519)Mark Shannon2024-12-063-69/+17
| | | | | | | * Faster marking of reachable objects * Changes calculation of work to do and work done. * Merges transitive closure calculations
* gh-120010: Fix invalid (nan+nanj) results in _Py_c_prod() (GH-120287)Sergey B Kirpichev2024-12-061-4/+56
| | | | | | | | | | | | | | | | | | | | In some cases, previously computed as (nan+nanj), we could recover meaningful component values in the result, see e.g. the C11, Annex G.5.1, routine _Cmultd(): >>> z = 1e300+1j >>> z*(nan+infj) # was (nan+nanj) (-inf+infj) That also fix some complex powers for small integer exponents, computed with optimized algorithm (by squaring): >>> z**5 # was (nan+nanj) Traceback (most recent call last): File "<python-input-1>", line 1, in <module> z**5 ~^^~ OverflowError: complex exponentiation
* gh-127582: Make object resurrection thread-safe for free threading. (GH-127612)Sam Gross2024-12-054-20/+41
| | | | | | | | | | | | Objects may be temporarily "resurrected" in destructors when calling finalizers or watcher callbacks. We previously undid the resurrection by decrementing the reference count using `Py_SET_REFCNT`. This was not thread-safe because other threads might be accessing the object (modifying its reference count) if it was exposed by the finalizer, watcher callback, or temporarily accessed by a racy dictionary or list access. This adds internal-only thread-safe functions for temporary object resurrection during destructors.
* gh-127536: Add missing locks in listobject.c (GH-127580)Sam Gross2024-12-041-10/+40
| | | | We were missing locks around some list operations in the free threading build.
* gh-123378: Ensure results of `PyUnicode*Error_Get{Start,End}` are clamped ↵Bénédikt Tran2024-12-041-109/+139
| | | | | | (GH-123380) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
* gh-115999: Enable specialization of `CALL` instructions in free-threaded ↵mpage2024-12-031-7/+55
| | | | | | | | | | | | | | | | | | | | | | builds (#127123) The CALL family of instructions were mostly thread-safe already and only required a small number of changes, which are documented below. A few changes were needed to make CALL_ALLOC_AND_ENTER_INIT thread-safe: Added _PyType_LookupRefAndVersion, which returns the type version corresponding to the returned ref. Added _PyType_CacheInitForSpecialization, which takes an init method and the corresponding type version and only populates the specialization cache if the current type version matches the supplied version. This prevents potentially caching a stale value in free-threaded builds if we race with an update to __init__. Only cache __init__ functions that are deferred in free-threaded builds. This ensures that the reference to __init__ that is stored in the specialization cache is valid if the type version guard in _CHECK_AND_ALLOCATE_OBJECT passes. Fix a bug in _CREATE_INIT_FRAME where the frame is pushed to the stack on failure. A few other miscellaneous changes were also needed: Use {LOCK,UNLOCK}_OBJECT in LIST_APPEND. This ensures that the list's per-object lock is held while we are appending to it. Add missing co_tlbc for _Py_InitCleanup. Stop/start the world around setting the eval frame hook. This allows us to read interp->eval_frame non-atomically and preserves the behavior of _CHECK_PEP_523 documented below.
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-033-45/+81
| | | | | | | | | | | | | | | | | | * 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-115999: Specialize `LOAD_SUPER_ATTR` in free-threaded builds (gh-127128)Neil Schemenauer2024-12-031-2/+3
| | | | | | Use existing helpers to atomically modify the bytecode. Add unit tests to ensure specializing is happening as expected. Add test_specialize.py that can be used with ThreadSanitizer to detect data races. Fix thread safety issue with cell_set_contents().
* gh-127521: Mark list as "shared" before resizing if necessary (#127524)Sam Gross2024-12-021-0/+20
| | | | | | | | | In the free threading build, if a non-owning thread resizes a list, it must use QSBR to free the old list array because there may be a concurrent access (without a lock) from the owning thread. To match the pattern in dictobject.c, we just mark the list as "shared" before resizing if it's from a non-owning thread and not already marked as shared.
* Fix Unicode encode_wstr_utf8() (#127420)Victor Stinner2024-12-021-1/+1
| | | Raise RuntimeError instead of RuntimeWarning.
* gh-115999: Add partial free-thread specialization for BINARY_SUBSCR (gh-127227)Donghee Na2024-12-021-0/+6
|
* gh-127417: fix UTF-8 decoder optimization on AIX (#127433)Inada Naoki2024-11-301-10/+14
|
* gh-127316: fix incorrect assertion in setting `__class__` in free-threading ↵Kumar Aditya2024-11-291-1/+1
| | | | (#127399)
* gh-126024: optimize UTF-8 decoder for short non-ASCII string (#126025)Inada Naoki2024-11-291-45/+259
|
* gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)Sergey B Kirpichev2024-11-262-68/+180
| | | | | | | | | | | | | | | "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).
* gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415)Jelle Zijlstra2024-11-261-2/+2
|
* gh-113841: fix possible undefined division by 0 in _Py_c_pow() (GH-127211)Sergey B Kirpichev2024-11-241-1/+1
| | | `x**y == 1/x**-y ` thus changing `/=` to `*=` by negating the exponent.
* gh-119786: add code object doc, inline locations.md into it (#126832)Irit Katriel2024-11-221-1/+1
|
* gh-126091: Always link generator frames when propagating a thrown-in ↵Jacob Bower2024-11-211-6/+12
| | | | | exception through a yield-from chain (#126092) Always link generator frames when propagating a thrown-in exception through a yield-from chain.
* gh-115999: Add free-threaded specialization for ``TO_BOOL`` (gh-126616)Donghee Na2024-11-211-0/+18
|
* gh-115999: Specialize `LOAD_GLOBAL` in free-threaded builds (#126607)mpage2024-11-212-10/+60
| | | | | | | | | | | | | | Enable specialization of LOAD_GLOBAL in free-threaded builds. Thread-safety of specialization in free-threaded builds is provided by the following: A critical section is held on both the globals and builtins objects during specialization. This ensures we get an atomic view of both builtins and globals during specialization. Generation of new keys versions is made atomic in free-threaded builds. Existing helpers are used to atomically modify the opcode. Thread-safety of specialized instructions in free-threaded builds is provided by the following: Relaxed atomics are used when loading and storing dict keys versions. This avoids potential data races as the dict keys versions are read without holding the dictionary's per-object lock in version guards. Dicts keys objects are passed from keys version guards to the downstream uops. This ensures that we are loading from the correct offset in the keys object. Once a unicode key has been stored in a keys object for a combined dictionary in free-threaded builds, the offset that it is stored in will never be reused for a different key. Once the version guard passes, we know that we are reading from the correct offset. The dictionary read fast-path is used to read values from the dictionary once we know the correct offset.
* gh-114940: Add _Py_FOR_EACH_TSTATE_UNLOCKED(), and Friends (gh-127077)Eric Snow2024-11-213-4/+6
| | | This is a precursor to the actual fix for gh-114940, where we will change these macros to use the new lock. This change is almost entirely mechanical; the exceptions are the loops in codeobject.c and ceval.c, which now hold the "head" lock. Note that almost all of the uses of _Py_FOR_EACH_TSTATE_UNLOCKED() here will change to _Py_FOR_EACH_TSTATE_BEGIN() once we add the new per-interpreter lock.
* gh-124470: Fix crash when reading from object instance dictionary while ↵Dino Viehland2024-11-212-46/+180
| | | | | replacing it (#122489) Delay free a dictionary when replacing it
* gh-127020: Make `PyCode_GetCode` thread-safe for free threading (#127043)Sam Gross2024-11-211-27/+51
| | | | Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
* GH-127010: Don't lazily track and untrack dicts (GH-127027)Mark Shannon2024-11-202-94/+19
|
* gh-126980: Fix `bytearray.__buffer__` crash on `PyBUF_{READ,WRITE}` (#126981)sobolevn2024-11-191-2/+3
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-126076: Account for relocated objects in tracemalloc (#126077)Pablo Galindo Salgado2024-11-194-15/+5
|
* Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Hugo van Kemenade2024-11-192-19/+98
| | | | collection (GH-126502)" (#126983)
* gh-126594: Fix typeobject.c wrap_buffer() cast (#126754)Victor Stinner2024-11-191-3/+3
| | | | | Reject flags smaller than INT_MIN. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-11-182-98/+19
| | | | | | | | | | | | | | | | 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-123465: Ensure PyType_FromMetaclass avoids extra strcmp (GH-125460)neonene2024-11-131-2/+2
| | | use else
* gh-123619: Add an unstable C API function for enabling deferred reference ↵Peter Bierma2024-11-131-0/+29
| | | | | | counting (GH-123635) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-126341: add release check to `__iter__` method of `memoryview` (#126759)Ritvik Pasham2024-11-131-0/+1
| | | | | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: sobolevn <mail@sobolevn.me>
* gh-126061: Add PyLong_IsPositive/Zero/Negative() functions (#126065)RUANG (James Roy)2024-11-121-0/+33
| | | | | 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-126547: Pre-assign version numbers for a few common classes (GH-126551)Mark Shannon2024-11-0810-1/+13
|