summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* GH-120024: Use pointer for stack pointer (GH-121923)Mark Shannon2024-07-181-11/+13
|
* gh-121266: Remove Py_ALWAYS_INLINE in dictobject.c (#121493)Victor Stinner2024-07-181-3/+3
| | | | | compare_unicode_generic(), compare_unicode_unicode() and compare_generic() are callbacks used by do_lookup(). When enabling assertions, it's not possible to inline these functions.
* gh-121266: Change dict check_lookup() return type to int (#121581)Victor Stinner2024-07-171-11/+11
|
* gh-121863: Immortalize names in code objects to avoid crash (GH-121903)Petr Viktorin2024-07-171-1/+1
|
* gh-121849: Fix PyUnicodeWriter_WriteSubstring() crash if len=0 (#121896)Victor Stinner2024-07-171-11/+12
| | | Do nothing if start=end.
* gh-118934: Make PyEval_GetLocals return borrowed reference (#119769)Tian Gao2024-07-161-0/+4
| | | Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* gh-121860: Fix crash when materializing managed dict (#121866)Sam Gross2024-07-161-5/+12
| | | | The object's inline values may be marked invalid if the materialized dict was already initialized and then deleted.
* gh-113993: Don't immortalize in PyUnicode_InternInPlace; keep immortalizing ↵Petr Viktorin2024-07-161-1/+1
| | | | | | | | | | | | | | | | | in other API (#121364) * Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs * Document immortality in some functions that take `const char *` This is PyUnicode_InternFromString; PyDict_SetItemString, PyObject_SetAttrString; PyObject_DelAttrString; PyUnicode_InternFromString; and the PyModule_Add convenience functions. Always point out a non-immortalizing alternative. * Don't immortalize user-provided attr names in _ctypes
* gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal ↵Petr Viktorin2024-07-161-7/+8
| | | | | | (GH-121358) Older stable ABI extensions are allowed to make immortal objects mortal. Instead, use `_PyUnicode_STATE` (`interned` and `statically_allocated`).
* gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (#121799)Sam Gross2024-07-151-2/+6
| | | | | | | | | | | | We should maintain the invariant that a zero `ob_tid` implies the refcount fields are merged. * Move the assignment in `_Py_MergeZeroLocalRefcount` to immediately before the refcount merge. * Update `_PyTrash_thread_destroy_chain` to set `ob_ref_shared` to `_Py_REF_MERGED` when setting `ob_tid` to zero. Also check this invariant with assertions in the GC in debug builds. That uncovered a bug when running out of memory during GC.
* gh-84978: Add float.from_number() and complex.from_number() (GH-26827)Serhiy Storchaka2024-07-154-18/+97
| | | | | | They are alternate constructors which only accept numbers (including objects with special methods __float__, __complex__ and __index__), but not strings.
* gh-121731: Fix mimalloc compile error on GNU/Hurd (#121732)Samuel Thibault2024-07-141-0/+1
|
* gh-121660: Fix `ga_getitem` by explicitly checking for `NULL` result (#121661)sobolevn2024-07-141-0/+4
|
* gh-121562: optimized hex_from_char (#121563)Bruno Lima2024-07-141-62/+32
| | | | | Performance improvement to `float.fromhex`: use a lookup table for computing the hexadecimal value of a character, in place of the previous switch-case construct. Patch by Bruno Lima.
* gh-121652: Handle `allocate_weakref` returning NULL (#121653)Sam Gross2024-07-131-0/+7
| | | | The `allocate_weakref` may return NULL when out of memory. We need to handle that case and propagate the error.
* gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)Serhiy Storchaka2024-07-131-13/+55
| | | | | | * The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit. * Fix integer overflow check in sum().
* gh-95144: Improve error message of `... in None` (GH-119888)Zachary Ware2024-07-121-2/+10
|
* gh-117482: Fix Builtin Types Slot Wrappers (gh-121602)Eric Snow2024-07-111-10/+30
| | | When builtin static types are initialized for a subinterpreter, various "tp" slots have already been inherited (for the main interpreter). This was interfering with the logic in add_operators() (in Objects/typeobject.c), causing a wrapper to get created when it shouldn't. This change fixes that by preserving the original data from the static type struct and checking that.
* gh-117657: Fix TSan race in _PyDict_CheckConsistency (#121551)Sam Gross2024-07-101-9/+15
| | | | The only remaining race in dictobject.c was in _PyDict_CheckConsistency when the dictionary has shared keys.
* gh-120198: Stop the world when setting __class__ on free-threaded build ↵Ken Jin2024-07-102-49/+62
| | | | (GH-120672)
* gh-121460: Skip freeing unallocated arenas (gh-121491)Stefano Rivera2024-07-101-0/+8
| | | | | `munmap(NULL)` is not noop, like `free(NULL)` is. Fixes an observed testsuite hang on 32-bit ARM systems.
* GH-121439: Allow PyTupleObjects with an ob_size of 20 in the free_list to be ↵satori19952024-07-101-1/+1
| | | | reused (gh-121428)
* gh-117657: Fix TSAN races in setobject.c (#121511)Sam Gross2024-07-091-8/+10
| | | | | The `used` field must be written using atomic stores because `set_len` and iterators may access the field concurrently without holding the per-object lock.
* gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#121388)Sam Gross2024-07-081-1/+1
| | | | | | | | | The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The missing fence can trigger bugs on macOS arm64. Additionally, we need a release fence in `_PySeqLock_LockWrite` to ensure that the sequence update is visible before any modifications to the cache entry.
* gh-121288: Make error message for index() methods consistent (GH-121395)Serhiy Storchaka2024-07-052-2/+2
| | | | | | | | | Make error message for index() methods consistent Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
* updated tp_flags initialization to use inplace or (#120625)byundojin2024-07-031-1/+1
|
* gh-117139: Add _PyTuple_FromStackRefSteal and use it (#121244)Sam Gross2024-07-021-0/+21
| | | Avoids the extra conversion from stack refs to PyObjects.
* 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>