summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
...
* gh-121165: protect macro expansion of `ADJUST_INDICES` with do-while(0) ↵Bénédikt Tran2024-07-022-26/+36
| | | | (#121166)
* gh-117657: Fix data races reported by TSAN in some set methods (#120914)AN Long2024-07-013-114/+64
| | | | | | Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed atomic loads in the free-threaded build. After this change, the TSAN doesn't report data races for this method.
* gh-119372: Recover inf's and zeros in _Py_c_quot (GH-119457)Sergey B Kirpichev2024-06-291-2/+23
| | | | | | 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.2, routine _Cdivd().
* gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118)Steve Dower2024-06-281-1/+5
|
* gh-120686: remove unused internal c api functions (#120687)Irit Katriel2024-06-272-30/+0
|
* gh-121040: Use __attribute__((fallthrough)) (#121044)Victor Stinner2024-06-273-8/+8
| | | | | | | | | | | | | Fix warnings when using -Wimplicit-fallthrough compiler flag. Annotate explicitly "fall through" switch cases with a new _Py_FALLTHROUGH macro which uses __attribute__((fallthrough)) if available. Replace "fall through" comments with _Py_FALLTHROUGH. Add _Py__has_attribute() macro. No longer define __has_attribute() macro if it's not defined. Move also _Py__has_builtin() at the top of pyport.h. Co-Authored-By: Nikita Sobolev <mail@sobolevn.me>
* gh-117139: Convert the evaluation stack to stack refs (#118450)Ken Jin2024-06-263-32/+33
| | | | | | | | | | | | | | | | | This PR sets up tagged pointers for CPython. The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly. Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out. This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it. The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs. Please read Include/internal/pycore_stackref.h for more information! --------- Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
* gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053)Victor Stinner2024-06-261-2/+2
| | | | | | | | | | | | | | | | | | Remove the const qualifier of the argument of functions: * _PyLong_IsCompact() * _PyLong_CompactValue() Py_TYPE() argument is not const. Fix the compiler warning: Include/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’: Include/pyport.h:19:31: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual] (...) Include/cpython/longintrepr.h:133:30: note: in expansion of macro ‘Py_TYPE’ assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
* gh-119786: move frames documentation to InternalDocs and add details (#121009)Irit Katriel2024-06-261-157/+0
|
* gh-120858: PyDict_Next should not lock the dict (#120859)Sam Gross2024-06-241-7/+1
| | | | | | | | | PyDict_Next no longer locks the dictionary in the free-threaded build. Locking around individual PyDict_Next calls is not sufficient because the function returns borrowed references and because it allows concurrent modifications during the iteraiton loop. The internal locking also interferes with correct external synchronization because it may suspend outer critical sections created by the caller.
* gh-120860: Fix a few bugs in `type_setattro` error paths. (#120861)Sam Gross2024-06-241-37/+41
| | | | | | Moves the logic to update the type's dictionary to its own function in order to make the lock scoping more clear. Also, ensure that `name` is decref'd on the error path.
* Fix typos in comments (#120821)Xie Yanbo2024-06-248-10/+10
|
* gh-120834: fix over-allocation in PyGenObject, PyCoroObject, ↵Irit Katriel2024-06-241-3/+3
| | | | PyAsyncGenObject. (#120941)
* Fixes loop variables to be the same types as their limit (GH-120958)Steve Dower2024-06-243-6/+5
|
* gh-119182: Add PyUnicodeWriter_WriteUCS4() function (#120849)Victor Stinner2024-06-241-5/+48
|
* gh-70278: Fix PyUnicode_FromFormat() with precision for %s and %V (GH-120365)Serhiy Storchaka2024-06-241-2/+11
| | | | | | PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.
* gh-119521: Rename IncompleteInputError to _IncompleteInputError and remove ↵Pablo Galindo Salgado2024-06-241-8/+12
| | | | | | | from public API/ABI (GH-119680) Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-120834: fix type of *_iframe field in _PyGenObject_HEAD declaration (#120835)Irit Katriel2024-06-242-21/+17
|
* gh-119182: Add checks to PyUnicodeWriter APIs (#120870)Victor Stinner2024-06-221-0/+13
|
* gh-119182: Use PyUnicodeWriter_WriteWideChar() (#120851)Victor Stinner2024-06-221-6/+8
| | | Use PyUnicodeWriter_WriteWideChar() in PyUnicode_FromFormat()
* gh-119344: Make critical section API public (#119353)Sam Gross2024-06-213-45/+34
| | | | | | | | | | This makes the following macros public as part of the non-limited C-API for locking a single object or two objects at once. * `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()` * `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()` The supporting functions and structs used by the macros are also exposed for cases where C macros are not available.
* gh-119182: Add PyUnicodeWriter_DecodeUTF8Stateful() (#120639)Victor Stinner2024-06-211-65/+136
| | | | | | Add PyUnicodeWriter_WriteWideChar() and PyUnicodeWriter_DecodeUTF8Stateful() functions. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-113993: Allow interned strings to be mortal, and fix related issues ↵Petr Viktorin2024-06-215-127/+454
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-120520) * Add an InternalDocs file describing how interning should work and how to use it. * Add internal functions to *explicitly* request what kind of interning is done: - `_PyUnicode_InternMortal` - `_PyUnicode_InternImmortal` - `_PyUnicode_InternStatic` * Switch uses of `PyUnicode_InternInPlace` to those. * Disallow using `_Py_SetImmortal` on strings directly. You should use `_PyUnicode_InternImmortal` instead: - Strings should be interned before immortalization, otherwise you're possibly interning a immortalizing copy. - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in backports, as they are now part of public API and version-specific ABI. * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery. * Make sure the statically allocated string singletons are unique. This means these sets are now disjoint: - `_Py_ID` - `_Py_STR` (including the empty string) - one-character latin-1 singletons Now, when you intern a singleton, that exact singleton will be interned. * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic). * Intern `_Py_STR` singletons at startup. * For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup. * Beef up the tests. Cover internal details (marked with `@cpython_only`). * Add lots of assertions Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
* gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (#120442)Nikita Sobolev2024-06-211-12/+33
|
* gh-119182: Optimize PyUnicode_FromFormat() (#120796)Victor Stinner2024-06-201-26/+26
| | | | Use strchr() and ucs1lib_find_max_char() to optimize the code path formatting sub-strings between '%' formats.
* gh-119182: Use public PyUnicodeWriter API in union_repr() (#120797)Victor Stinner2024-06-201-24/+30
| | | | | | | | | | | | | | | The public PyUnicodeWriter API enables overallocation by default and so is more efficient. Benchmark: python -m pyperf timeit \ -s 't = int | float | complex | str | bytes | bytearray' \ ' | memoryview | list | dict' \ 'str(t)' Result: 1.29 us +- 0.02 us -> 1.00 us +- 0.02 us: 1.29x faster
* gh-119182: Use public PyUnicodeWriter API in ga_repr() (#120799)Victor Stinner2024-06-201-33/+35
| | | | | | | | | | | | | | | The public PyUnicodeWriter API enables overallocation by default and so is more efficient. Benchmark: python -m pyperf timeit \ -s 't = list[int, float, complex, str, bytes, bytearray, ' \ 'memoryview, list, dict]' \ 'str(t)' Result: 1.49 us +- 0.03 us -> 1.10 us +- 0.02 us: 1.35x faster
* gh-117511: Make PyMutex public in the non-limited API (#117731)Sam Gross2024-06-201-1/+1
|
* gh-119786: move locations doc to InternalDocs (#120445)Irit Katriel2024-06-191-69/+0
|
* GH-120097: Make FrameLocalsProxy a mapping (#120101)Mark Shannon2024-06-191-1/+1
| | | | | * Register FrameLocalsProxy as a subclass of collections.abc.Mapping * Allow FrameLocalsProxy to matching mapping patterns
* GH-119462: Enforce invariants of type versioning (GH-120731)Mark Shannon2024-06-191-92/+56
| | | | * Remove uses of Py_TPFLAGS_VALID_VERSION_TAG
* gh-120600: Make Py_TYPE() opaque in limited C API 3.14 (#120601)Victor Stinner2024-06-181-0/+8
| | | | In the limited C API 3.14 and newer, Py_TYPE() is now implemented as an opaque function call to hide implementation details.
* gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)Sam Gross2024-06-182-3/+11
| | | | | | | | | | | | This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable C-API function to provide a thread-safe mechanism for clearing weakrefs without executing callbacks. Some C-API extensions need to clear weakrefs without calling callbacks, such as after running finalizers like we do in subtype_dealloc. Previously they could use `_PyWeakref_ClearRef` on each weakref, but that's not thread-safe in the free-threaded build. Co-authored-by: Petr Viktorin <encukou@gmail.com>
* GH-120507: Lower the `BEFORE_WITH` and `BEFORE_ASYNC_WITH` instructions. ↵Mark Shannon2024-06-181-0/+28
| | | | | | | | | (#120640) * Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions. * Add LOAD_SPECIAL instruction * Reimplement `with` and `async with` statements using LOAD_SPECIAL
* gh-120524: Avoid a Race On ↵Eric Snow2024-06-171-2/+4
| | | | | _PyRuntime.types.managed_static.types[i].interp_count (gh-120529) gh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race.
* gh-119182: Add PyUnicodeWriter C API (#119184)Victor Stinner2024-06-171-16/+165
|
* gh-114091: Reword error message for unawaitable types (#114090)Steele Farnsworth2024-06-171-1/+1
| | | | | Reword error message for unawaitable types.
* gh-120196: Reuse find_max_char() for bytes objects (#120497)Ruben Vorderman2024-06-172-55/+25
|
* gh-83754: Use the Py_TYPE() macro (#120599)Victor Stinner2024-06-171-1/+1
| | | | Don't access directly PyObject.ob_type, but use the Py_TYPE() macro instead.
* gh-117657: Make PyType_HasFeature (exported version) atomic (#120484)Ken Jin2024-06-151-1/+1
| | | Make PyType_HasFeature (exported version) atomic
* gh-120161: Fix a Crash in the _datetime Module (gh-120182)Eric Snow2024-06-141-15/+70
| | | | | | | In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here. Also, credit goes to @mgorny and @neonene for the new tests. FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
* gh-120397: Optimize str.count() for single characters (#120398)Ruben Vorderman2024-06-131-0/+19
|
* gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)Ken Jin2024-06-121-1/+7
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
* gh-120198: Fix race condition when editing __class__ with an audit hook ↵Ken Jin2024-06-111-1/+2
| | | | active (GH-120195)
* gh-120298: Fix use-after-free in `list_richcompare_impl` (#120303)Nikita Sobolev2024-06-111-1/+8
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-24766: doc= argument to subclasses of property not handled correctly ↵E. M. Bray2024-06-101-15/+4
| | | | | (GH-2487) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher (GH-119365)Saul Shanabrook2024-06-081-11/+67
| | | | | | | Co-authored-by: parmeggiani <parmeggiani@spaziodati.eu> Co-authored-by: dpdani <git@danieleparmeggiani.me> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com> Co-authored-by: Ken Jin <kenjin@python.org>
* gh-120155: Fix copy/paste error in HAVE_SUBOFFSETS_IN_LAST_DIM() (#120228)Victor Stinner2024-06-071-1/+1
| | | | | | | | | | | | | | | | Don't hardcode 'dest' in HAVE_SUBOFFSETS_IN_LAST_DIM() macro of memoryobject.c, but use its 'view' parameter instead. Fix the Coverity issue: Error: COPY_PASTE_ERROR (CWE-398): Python-3.12.2/Objects/memoryobject.c:273:14: original: ""dest->suboffsets + (dest->ndim - 1)"" looks like the original copy. Python-3.12.2/Objects/memoryobject.c:274:14: copy_paste_error: ""dest"" in ""src->suboffsets + (dest->ndim - 1)"" looks like a copy-paste error. Python-3.12.2/Objects/memoryobject.c:274:14: remediation: Should it say ""src"" instead? # 272| assert(dest->ndim > 0 && src->ndim > 0); # 273| return (!HAVE_SUBOFFSETS_IN_LAST_DIM(dest) && # 274|-> !HAVE_SUBOFFSETS_IN_LAST_DIM(src) && # 275| dest->strides[dest->ndim-1] == dest->itemsize && # 276| src->strides[src->ndim-1] == src->itemsize);
* gh-120080: Accept ``None`` as a valid argument for direct call of the ↵Kirill Podoprigora2024-06-072-6/+6
| | | | | ``int.__round__`` (#120088) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-119999: Fix potential race condition in `_Py_ExplicitMergeRefcount` (#120000)Sam Gross2024-06-041-8/+11
| | | | | | We need to write to `ob_ref_local` and `ob_tid` before `ob_ref_shared`. Once we mark `ob_ref_shared` as merged, some other thread may free the object because the caller also passes in `-1` as `extra` to give up its only reference.