summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* gh-114329: Add `PyList_GetItemRef` function (GH-114504)Sam Gross2024-02-021-0/+15
| | | | | | | The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
* GH-113710: Add a "globals to constants" pass (GH-114592)Mark Shannon2024-02-021-1/+2
| | | Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
* gh-111968: Use per-thread freelists for dict in free-threading (gh-114323)Donghee Na2024-02-014-49/+51
|
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build ↵Sam Gross2024-02-011-2/+11
| | | | | | | | | | | | | | | | | (#114564) * gh-112529: Remove PyGC_Head from object pre-header in free-threaded build This avoids allocating space for PyGC_Head in the free-threaded build. The GC implementation for free-threaded CPython does not use the PyGC_Head structure. * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev` in the free-threaded build. * The GDB libpython.py file now determines the offset of the managed dict field based on whether the running process is a free-threaded build. Those are identified by the `ob_ref_local` field in PyObject. * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the size of `PyGC_Head` in the size of static `PyTypeObject`.
* gh-112087: Make PyList_{Append,Size,GetSlice} to be thread-safe (gh-114651)Donghee Na2024-01-311-7/+15
|
* gh-113939: Frame clear, clear locals (#113940)Albert Zeyer2024-01-311-0/+1
|
* gh-114685: Check flags in PyObject_GetBuffer() (GH-114707)Serhiy Storchaka2024-01-311-0/+6
| | | | | PyObject_GetBuffer() now raises a SystemError if called with PyBUF_READ or PyBUF_WRITE as flags. These flags should only be used with the PyMemoryView_* C API.
* gh-112075: refactor dictionary lookup functions for better re-usability ↵Dino Viehland2024-01-301-97/+95
| | | | | (#114629) Refactor dict lookup functions to use force inline helpers
* gh-113744: Add a new IncompleteInputError exception to improve incomplete ↵Pablo Galindo Salgado2024-01-301-0/+6
| | | | | input detection in the codeop module (#113745) Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-114569: Use PyMem_* APIs for non-PyObjects in unicodeobject.c (#114690)Erlend E. Aasland2024-01-291-6/+6
|
* gh-112075: Use PyMem_* for allocating dict keys objects (#114543)Dino Viehland2024-01-291-43/+23
| | | Use PyMem_* for keys allocation
* gh-55664: Add warning when creating a type using a namespace dictionary with ↵Furkan Onder2024-01-281-0/+11
| | | | | non-string keys. (GH-105338) Co-authored-by: Daniel Urban <durban@users.noreply.github.com>
* gh-113560: Improve docstrings for set.issubset() and set.issuperset() ↵Charlie Zhao2024-01-271-2/+10
| | | | (GH-113562)
* gh-113055: Use pointer for interp->obmalloc state (gh-113412)Neil Schemenauer2024-01-271-6/+115
| | | | | | | | | For interpreters that share state with the main interpreter, this points to the same static memory structure. For interpreters with their own obmalloc state, it is heap allocated. Add free_obmalloc_arenas() which will free the obmalloc arenas and radix tree structures for interpreters with their own obmalloc state. Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-112087: Make list_repr and list_length to be thread-safe (gh-114582)Donghee Na2024-01-261-10/+17
|
* gh-111968: Unify freelist naming schema to Eric's suggestion (gh-114581)Donghee Na2024-01-265-14/+14
|
* gh-114569: Use PyMem_* APIs for most non-PyObject uses (#114574)Erlend E. Aasland2024-01-262-12/+12
| | | Fix usage in Modules, Objects, and Parser subdirectories.
* gh-114312: Collect stats for unlikely events (GH-114493)Michael Droettboom2024-01-252-0/+12
|
* gh-112075: Adapt more dict methods to Argument Clinic (#114256)Dino Viehland2024-01-232-81/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Move more dict objects to argument clinic * Improve doc strings * More doc string improvements * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> * Update Objects/dictobject.c Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> --------- Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-112532: Improve mimalloc page visiting (#114133)Sam Gross2024-01-222-34/+130
| | | | | | | | | | | | | | | This adds support for visiting abandoned pages in mimalloc and improves the performance of the page visiting code. Abandoned pages contain memory blocks from threads that have exited. At some point, they may be later reclaimed by other threads. We still need to visit those pages in the free-threaded GC because they contain live objects. This also reduces the overhead of visiting mimalloc pages: * Special cases for full, empty, and pages containing only a single block. * Fix free_map to use one bit instead of one byte per block. * Use fast integer division by a constant algorithm when computing block offset from block size and index.
* gh-112529: Use GC heaps for GC allocations in free-threaded builds (gh-114157)Sam Gross2024-01-201-1/+2
| | | | | | | | | | * gh-112529: Use GC heaps for GC allocations in free-threaded builds The free-threaded build's garbage collector implementation will need to find GC objects by traversing mimalloc heaps. This hooks up the allocation calls with the correct heaps by using a thread-local "current_obj_heap" variable. * Refactor out setting heap based on type
* gh-111968: Fix --without-freelists build (gh-114270)Donghee Na2024-01-181-5/+14
|
* gh-112087: Remove duplicated critical_section (gh-114268)Donghee Na2024-01-181-6/+3
|
* gh-111968: Use per-thread freelists for generator in free-threading (gh-114189)Donghee Na2024-01-181-40/+24
|
* gh-114050: Fix crash when more than two arguments are passed to int() ↵kcatss2024-01-181-1/+1
| | | | | (GH-114067) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-106293: Fix typos in Objects/object_layout.md (#106294)Mano Sriram2024-01-161-3/+3
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* gh-112529: Track if debug allocator is used as underlying allocator (#113747)Sam Gross2024-01-161-6/+15
| | | | | | | | | | | | | | | * gh-112529: Track if debug allocator is used as underlying allocator The GC implementation for free-threaded builds will need to accurately detect if the debug allocator is used because it affects the offset of the Python object from the beginning of the memory allocation. The current implementation of `_PyMem_DebugEnabled` only considers if the debug allocator is the outer-most allocator; it doesn't handle the case of "hooks" like tracemalloc being used on top of the debug allocator. This change enables more accurate detection of the debug allocator by tracking when debug hooks are enabled. * Simplify _PyMem_DebugEnabled
* gh-112087: Update list impl to be thread-safe with manual CS (gh-113863)Donghee Na2024-01-162-18/+91
|
* gh-111968: Use per-thread slice_cache in free-threading (gh-113972)Donghee Na2024-01-151-11/+15
|
* gh-112532: Fix memory block count for free-threaded build (gh-113995)Sam Gross2024-01-151-18/+27
| | | | | | | | This fixes `_PyInterpreterState_GetAllocatedBlocks()` and `_Py_GetGlobalAllocatedBlocks()` in the free-threaded builds. The gh-113263 change that introduced multiple mimalloc heaps per-thread broke the logic for counting the number of allocated blocks. For subtle reasons, this led to reported reference count leaks in the refleaks buildbots.
* gh-109598: make PyComplex_RealAsDouble/ImagAsDouble use __complex__ (GH-109647)Sergey B Kirpichev2024-01-151-4/+29
| | | | | | | | | | `PyComplex_RealAsDouble()`/`PyComplex_ImagAsDouble` now try to convert an object to a `complex` instance using its `__complex__()` method before falling back to the ``__float__()`` method. PyComplex_ImagAsDouble() also will not silently return 0.0 for non-complex types anymore. Instead we try to call PyFloat_AsDouble() and return 0.0 only if this call is successful.
* gh-111968: Explicit handling for finalized freelist (gh-113929)Donghee Na2024-01-122-19/+7
|
* gh-111968: Use per-thread freelists for tuple in free-threading (gh-113921)Donghee Na2024-01-111-22/+15
|
* gh-112640: Add `kwdefaults` parameter to `types.FunctionType.__new__` (#112641)Nikita Sobolev2024-01-112-13/+35
|
* gh-111968: Unify naming scheme for freelist (gh-113919)Donghee Na2024-01-101-2/+2
|
* gh-113753: Clear finalized bit when putting PyAsyncGenASend back into free ↵Sam Gross2024-01-101-0/+2
| | | | list (#113754)
* gh-111968: Use per-thread freelists for float in free-threading (gh-113886)Donghee Na2024-01-101-27/+20
|
* gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584)Donghee Na2024-01-091-11/+11
|
* gh-112087: Update list.{pop,clear,reverse,remove} to use CS (gh-113764)Donghee Na2024-01-092-9/+46
|
* gh-112808: Fix mimalloc build on Solaris (#112809)Jakub Kulík2024-01-081-1/+1
|
* gh-112806: Remove unused function warnings during mimalloc build on Solaris ↵Jakub Kulík2024-01-081-2/+2
| | | | (#112807)
* gh-113750: Fix object resurrection in free-threaded builds (gh-113751)Sam Gross2024-01-061-3/+12
| | | | | | | | | gh-113750: Fix object resurrection on free-threaded builds This avoids the undesired re-initializing of fields like `ob_gc_bits`, `ob_mutex`, and `ob_tid` when an object is resurrected due to its finalizer being called. This change has no effect on the default (with GIL) build.
* gh-112532: Tag mimalloc heaps and pages (#113742)Sam Gross2024-01-054-13/+30
| | | | | | | | | | | | | | | | | | | | | * gh-112532: Tag mimalloc heaps and pages Mimalloc pages are data structures that contain contiguous allocations of the same block size. Note that they are distinct from operating system pages. Mimalloc pages are contained in segments. When a thread exits, it abandons any segments and contained pages that have live allocations. These segments and pages may be later reclaimed by another thread. To support GC and certain thread-safety guarantees in free-threaded builds, we want pages to only be reclaimed by the corresponding heap in the claimant thread. For example, we want pages containing GC objects to only be claimed by GC heaps. This allows heaps and pages to be tagged with an integer tag that is used to ensure that abandoned pages are only claimed by heaps with the same tag. Heaps can be initialized with a tag (0-15); any page allocated by that heap copies the corresponding tag. * Fix conversion warning
* gh-112532: Isolate abandoned segments by interpreter (#113717)Sam Gross2024-01-042-58/+44
| | | | | | | | | | | | | | | * gh-112532: Isolate abandoned segments by interpreter Mimalloc segments are data structures that contain memory allocations along with metadata. Each segment is "owned" by a thread. When a thread exits, it abandons its segments to a global pool to be later reclaimed by other threads. This changes the pool to be per-interpreter instead of process-wide. This will be important for when we use mimalloc to find GC objects in the `--disable-gil` builds. We want heaps to only store Python objects from a single interpreter. Absent this change, the abandoning and reclaiming process could break this isolation. * Add missing '&_mi_abandoned_default' to 'tld_empty'
* Document the `co_lines` method on code objects (#113682)Alex Waygood2024-01-031-1/+1
| | | Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
* gh-111178: Avoid calling functions from incompatible pointer types in ↵Christopher Chavez2024-01-021-100/+126
| | | | | dictobject.c (#112892) Fix undefined behavior warnings (UBSan -fsanitize=function).
* gh-111178: Avoid calling functions from incompatible pointer types in ↵Christopher Chavez2024-01-021-106/+147
| | | | | | | | | | descrobject.c (GH-112861) Fix undefined behavior warnings (UBSan -fsanitize=function), for example: Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' descrobject.c:1160: note: mappingproxy_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
* gh-111178: Avoid calling functions from incompatible pointer types in ↵Christopher Chavez2024-01-021-72/+92
| | | | | | | | | | listobject.c (GH-112820) Fix undefined behavior warnings (UBSan -fsanitize=function), for example: Objects/object.c:674:11: runtime error: call to function list_repr through pointer to incorrect function type 'struct _object *(*)(struct _object *)' listobject.c:382: note: list_repr defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:674:11 in
* gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)Sam Gross2023-12-263-22/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | * gh-112532: Use separate mimalloc heaps for GC objects In `--disable-gil` builds, we now use four separate heaps in anticipation of using mimalloc to find GC objects when the GIL is disabled. To support this, we also make a few changes to mimalloc: * `mi_heap_t` and `mi_tld_t` initialization is split from allocation. This allows us to have a `mi_tld_t` per-`PyThreadState`, which is important to keep interpreter isolation, since the same OS thread may run in multiple interpreters (using different PyThreadStates.) * Heap abandoning (mi_heap_collect_ex) can now be called from a different thread than the one that created the heap. This is necessary because we may clear and delete the containing PyThreadStates from a different thread during finalization and after fork(). * Use enum instead of defines and guard mimalloc includes. * The enum typedef will be convenient for future PRs that use the type. * Guarding the mimalloc includes allows us to unconditionally include pycore_mimalloc.h from other header files that rely on things like `struct _mimalloc_thread_state`. * Only define _mimalloc_thread_state in Py_GIL_DISABLED builds
* gh-111971: Make _PyUnicode_FromId thread-safe in --disable-gil (gh-113489)Donghee Na2023-12-261-3/+7
|