summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* gh-111178: fix UBSan failures in `Objects/descrobject.c` (GH-128245)Bénédikt Tran2025-01-061-7/+10
| | | fix UBSan failures for `propertyobject`
* gh-128137: Update PyASCIIObject to handle interned field with the atomic ↵Donghee Na2025-01-051-3/+3
| | | | operation (gh-128196)
* gh-127903: Fix a crash on debug builds when calling ↵Alexander Shadchin2025-01-031-3/+6
| | | | `Objects/unicodeobject::_copy_characters`` (#127876)
* gh-111178: fix UBSan failures in `Objects/tupleobject.c` (GH-128251)Bénédikt Tran2025-01-031-14/+20
| | | fix UBSan failures for `_PyTupleIterObject`
* gh-111178: fix UBSan failures in `Objects/enumobject.c` (GH-128246)Bénédikt Tran2025-01-031-22/+35
| | | | * fix UBSan failures for `enumobject` * fix UBSan failures for `reversedobject`
* gh-127787: refactor helpers for `PyUnicodeErrorObject` internal interface ↵Bénédikt Tran2025-01-031-155/+287
| | | | | | | | | | | | | | | | | | | | | | (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-128133: use relaxed atomics for hash of bytes (#128412)Abhijeet2025-01-031-31/+39
|
* gh-128212: Fix race in `_PyUnicode_CheckConsistency` (GH-128367)Sam Gross2025-01-021-1/+1
| | | | | There was a data race on the utf8 field between `PyUnicode_SET_UTF8` and `_PyUnicode_CheckConsistency`. Use the `_PyUnicode_UTF8()` accessor, which uses an atomic load internally, to avoid the data race.
* gh-128100: Use atomic dictionary load in `_PyObject_GenericGetAttrWithDict` ↵Bogdan Romanyuk2024-12-301-0/+4
| | | | (GH-128297)
* gh-126868: Add freelist for compact ints to `_PyLong_New` (#128181)Pieter Eendebak2024-12-261-12/+18
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* Clean up redundant ifdef in list getitem (#128257)da-woods2024-12-261-4/+0
| | | It's already inside a `Py_GIL_DISABLED` block so the `#else` clause is always unused.
* gh-128198: Add missing error checks for usages of PyIter_Next() (GH-128199)Yan Yanchii2024-12-252-0/+8
|
* GH-127705: Add debug mode for `_PyStackRef`s inspired by HPy debug mode ↵Mark Shannon2024-12-201-2/+2
| | | | (GH-128121)
* gh-127274: Defer nested methods (#128012)mpage2024-12-191-1/+5
| | | | | | | 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-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)Neil Schemenauer2024-12-191-17/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add `_PyDictKeys_StringLookupSplit` which does locking on dict keys and use in place of `_PyDictKeys_StringLookup`. * Change `_PyObject_TryGetInstanceAttribute` to use that function in the case of split keys. * Add `unicodekeys_lookup_split` helper which allows code sharing between `_Py_dict_lookup` and `_PyDictKeys_StringLookupSplit`. * Fix locking for `STORE_ATTR_INSTANCE_VALUE`. Create `_GUARD_TYPE_VERSION_AND_LOCK` uop so that object stays locked and `tp_version_tag` cannot change. * Pass `tp_version_tag` to `specialize_dict_access()`, ensuring the version we store on the cache is the correct one (in case of it changing during the specalize analysis). * Split `analyze_descriptor` into `analyze_descriptor_load` and `analyze_descriptor_store` since those don't share much logic. Add `descriptor_is_class` helper function. * In `specialize_dict_access`, double check `_PyObject_GetManagedDict()` in case we race and dict was materialized before the lock. * Avoid borrowed references in `_Py_Specialize_StoreAttr()`. * Use `specialize()` and `unspecialize()` helpers. * Add unit tests to ensure specializing happens as expected in FT builds. * Add unit tests to attempt to trigger data races (useful for running under TSAN). * Add `has_split_table` function to `_testinternalcapi`.
* GH-122548: Implement branch taken and not taken events for sys.monitoring ↵Mark Shannon2024-12-191-0/+7
| | | | (GH-122564)
* gh-128008: Add `PyWeakref_IsDead()` (GH-128009)Sam Gross2024-12-191-0/+13
| | | | | | | | | 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-128013: fix data race in `PyUnicode_AsUTF8AndSize` on free-threading ↵Kumar Aditya2024-12-191-17/+32
| | | | (#128021)
* gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (gh-127737)Donghee Na2024-12-191-0/+25
|
* gh-128013: Convert unicodeobject.c macros to functions (#128061)Victor Stinner2024-12-181-45/+78
| | | | | | | Convert unicodeobject.c macros to static inline functions. * Add _PyUnicode_SET_UTF8() and _PyUnicode_SET_UTF8_LENGTH() macros. * Add PyUnicode_HASH() and PyUnicode_SET_HASH() macros. * Remove unused _PyUnicode_KIND() and _PyUnicode_GET_LENGTH() macros.
* 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).