Commit Graph

8116 Commits

Author SHA1 Message Date
cui fliter e7ba6e9dbe
chore: fix typos (#116345)
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 09:05:52 -07:00
Dino Viehland ffcc450a9b
gh-112075: Enable freeing with qsbr and fallback to lock on key changed (GH-116336) 2024-03-05 09:08:18 +00:00
Donghee Na 6cddc731fb
gh-112087: Make list_{slice, ass_slice, subscript} to be threadsafe (gh-116233) 2024-03-05 04:58:14 +00:00
Sam Gross 58c7919d05
gh-116029: Fix unused function warning on macOS (#116340) 2024-03-04 22:06:21 -05:00
Kirill Podoprigora 8a84eb75a9
gh-116316: Fix typo in `UNARY_FUNC(PyNumber_Positive)` macros (GH-116317) 2024-03-04 17:57:01 +00:00
Erlend E. Aasland 17c4849981
gh-116296: Fix refleak in reduce_newobj() corner case (#116297)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2024-03-04 09:46:18 +00:00
Donghee Na fb5e0344e4
gh-112087: Use QSBR technique for list_new/clear for free-thread build (gh-115875) 2024-03-02 08:30:35 +09:00
Humbulani 5e0c7bc1d3
gh-115941: fixes in dictobject.c doc block(#116196) 2024-03-01 12:48:26 -07:00
Sam Gross d7ddd90308
gh-115491: Fix Clang compiler warning (#116153)
gh-115491: Fix compiler warning on macOS
2024-02-29 16:02:44 -08:00
Dino Viehland 556749c3e3
gh-112075: Avoid locking shared keys on every assignment (#116087) 2024-02-29 13:38:50 -08:00
Dino Viehland 81c79961d2
gh-112075: Use relaxed stores for places where we may race with when reading lock-free (#115786) 2024-02-28 14:53:19 -08:00
Sam Gross 75c6c05fea
gh-115891: Fix debug byte filling in free-threaded build (#116018)
The previous code had two bugs. First, the debug offset in the mimalloc
heap includes the two pymalloc debug words, but the pointer passed to
fill_mem_debug does not include them. Second, the current object heap is
correct source for allocations, but not deallocations.
2024-02-28 12:50:09 -08:00
Donghee Na f58f8cef74
gh-112075: Remove compiler warning from apple clang (gh-115855) 2024-02-29 02:51:59 +09:00
Jay Ting 948acd6ed8
gh-115323: Add meaningful error message for using bytearray.extend with str (#115332)
Perform str check after TypeError is raised
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-02-24 18:34:45 -05:00
Dino Viehland 1002fbe12e
gh-112075: Iterating a dict shouldn't require locks (#115108)
Makes iteration of a dict be lock free for the forward iteration case.
2024-02-22 12:02:39 -08:00
Nikita Sobolev 465df8855e
gh-115827: Fix compile warning in `longobject.c` (#115828)
Objects/longobject.c:1186:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2024-02-22 17:57:12 +00:00
Sam Gross 347acded84
gh-115491: Keep some fields valid across allocations in obmalloc (free-threading) (#115745) 2024-02-21 10:00:08 -08:00
Donghee Na 259730bbb5
gh-112087: Make list_{concat, repeat, inplace_repeat, ass_item) to be thread-safe (gh-115605) 2024-02-21 01:38:09 +00:00
Dino Viehland 54071460d7
gh-112075: Accessing a single element should optimistically avoid locking (#115109)
Makes accessing a single element thread safe and typically lock free
2024-02-20 17:08:14 -08:00
Dino Viehland 176df09adb
gh-112075: Make PyDictKeysObject thread-safe (#114741)
Adds locking for shared PyDictKeysObject's for dictionaries
2024-02-20 16:40:37 -08:00
Sam Gross 520403ed4c
gh-115733: Fix crash involving exhausted list iterator (#115740)
* gh-115733: Fix crash involving exhausted iterator

* Add blurb
2024-02-21 05:18:44 +09:00
Sam Gross e3ad6ca56f
gh-115103: Implement delayed free mechanism for free-threaded builds (#115367)
This adds `_PyMem_FreeDelayed()` and supporting functions. The
`_PyMem_FreeDelayed()` function frees memory with the same allocator as
`PyMem_Free()`, but after some delay to ensure that concurrent lock-free
readers have finished.
2024-02-20 13:04:37 -05:00
Sam Gross cc82e33af9
gh-115491: Keep some fields valid across allocations (free-threading) (#115573)
This avoids filling the memory occupied by ob_tid, ob_ref_local, and
ob_ref_shared with debug bytes (e.g., 0xDD) in mimalloc in the
free-threaded build.
2024-02-20 10:36:40 -05:00
Eugene Toder c0b0c2f201
gh-101860: Expose __name__ on property (GH-101876)
Useful for introspection and consistent with functions and other
descriptors.
2024-02-20 17:14:34 +02:00
Serhiy Storchaka 090dd21ab9
gh-115618: Remove improper Py_XDECREFs in property methods (GH-115619) 2024-02-17 23:18:30 +02:00
Donghee Na 8db8d7118e
gh-111968: Split _Py_async_gen_asend_freelist out of _Py_async_gen_fr… (gh-115546) 2024-02-17 10:03:10 +09:00
Benjamin Peterson 2ac9d9f2fb
gh-113743: Give _PyTypes_AfterFork a prototype. (gh-115563)
Fixes a compiler warning.
2024-02-16 08:49:41 -08:00
Sam Gross b24c9161a6
gh-112529: Make the GC scheduling thread-safe (#114880)
The GC keeps track of the number of allocations (less deallocations)
since the last GC. This buffers the count in thread-local state and uses
atomic operations to modify the per-interpreter count. The thread-local
buffering avoids contention on shared state.

A consequence is that the GC scheduling is not as precise, so
"test_sneaky_frame_object" is skipped because it requires that the GC be
run exactly after allocating a frame object.
2024-02-16 11:22:27 -05:00
Donghee Na 321d13fd2b
gh-111968: Split _Py_dictkeys_freelist out of _Py_dict_freelist (gh-115505) 2024-02-16 01:01:36 +00:00
Dino Viehland 454d7963e3
gh-113743: Use per-interpreter locks for types (#115541)
Move type-lock to per-interpreter lock to avoid heavy contention in interpreters test
2024-02-15 16:28:31 -08:00
Dino Viehland ae460d450a
gh-113743: Make the MRO cache thread-safe in free-threaded builds (#113930)
Makes _PyType_Lookup thread safe, including:
    Thread safety of the underlying cache.
    Make mutation of mro and type members thread safe
    Also _PyType_GetMRO and _PyType_GetBases are currently returning borrowed references which aren't safe.
2024-02-15 10:54:57 -08:00
David Hewitt 9e3729bbd7
gh-114626: add PyCFunctionFast and PyCFunctionFastWithKeywords (GH-114627)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-02-15 11:05:20 +01:00
Victor Stinner 3e7b7df5cb
gh-114570: Add PythonFinalizationError exception (#115352)
Add PythonFinalizationError exception. This exception derived from
RuntimeError is raised when an operation is blocked during the Python
finalization.

The following functions now raise PythonFinalizationError, instead of
RuntimeError:

* _thread.start_new_thread()
* subprocess.Popen
* os.fork()
* os.fork1()
* os.forkpty()

Morever, _winapi.Overlapped finalizer now logs an unraisable
PythonFinalizationError, instead of an unraisable RuntimeError.
2024-02-14 23:35:06 +01:00
Donghee Na a2d4281415
gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe (gh-114843) 2024-02-15 02:00:50 +09:00
Donghee Na f15795c9a0
gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329) 2024-02-14 00:32:51 +00:00
Kirill Podoprigora 206f73dc5f
gh-115391: Fix compiler warning in `Objects/longobject.c` (GH-115368) 2024-02-13 20:49:13 +00:00
Steve Dower ea25f32d5f
gh-89240: Enable multiprocessing on Windows to use large process pools (GH-107873)
We add _winapi.BatchedWaitForMultipleObjects to wait for larger numbers of handles.
This is an internal module, hence undocumented, and should be used with caution.
Check the docstring for info before using BatchedWaitForMultipleObjects.
2024-02-13 00:28:35 +00:00
Steve Dower 7861dfd26a
gh-111140: Adds PyLong_AsNativeBytes and PyLong_FromNative[Unsigned]Bytes functions (GH-114886) 2024-02-12 20:13:13 +00:00
Brandt Bucher 235cacff81
GH-114695: Add `sys._clear_internal_caches` (GH-115152) 2024-02-12 09:04:36 +00:00
Donghee Na d4d5bae147
gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists (gh-114899) 2024-02-10 00:57:04 +00:00
Sam Gross a3af3cb4f4
gh-110481: Implement inter-thread queue for biased reference counting (#114824)
Biased reference counting maintains two refcount fields in each object:
`ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two
fields. In some cases, when refcounting operations are split across threads,
the ob_ref_shared field can be negative (although the total refcount must be
at least zero). In this case, the thread that decremented the refcount
requests that the owning thread give up ownership and merge the refcount
fields.
2024-02-09 17:08:32 -05:00
Sam Gross 31633f4473
gh-115184: Fix refleak tracking issues in free-threaded build (#115188)
Fixes a few issues related to refleak tracking in the free-threaded build:

- Count blocks in abandoned segments
- Call `_mi_page_free_collect` earlier during heap traversal in order to get an accurate count of blocks in use.
- Add missing refcount tracking in `_Py_DecRefSharedDebug` and `_Py_ExplicitMergeRefcount`.
- Pause threads in  `get_num_global_allocated_blocks` to ensure that traversing the mimalloc heaps is safe.
2024-02-09 09:23:12 -05:00
Tomas R ed1a8daf10
gh-112069: Adapt set/frozenset methods to Argument Clinic (#115112) 2024-02-08 17:47:27 +01:00
Sam Gross ef3ceab09d
gh-112066: Use `PyDict_SetDefaultRef` in place of `PyDict_SetDefault`. (#112211)
This changes a number of internal usages of `PyDict_SetDefault` to use `PyDict_SetDefaultRef`.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-02-07 13:43:18 -05:00
Mark Shannon 8a3c499ffe
GH-108362: Revert "GH-108362: Incremental GC implementation (GH-108038)" (#115132)
Revert "GH-108362: Incremental GC implementation (GH-108038)"

This reverts commit 36518e69d7.
2024-02-07 12:38:34 +00:00
Dino Viehland 92abb01240
gh-112075: Add critical sections for most dict APIs (#114508)
Starts adding thread safety to dict objects.


Use @critical_section for APIs which are exposed via argument clinic and don't directly correlate with a public C API which needs to acquire the lock
Use a _lock_held suffix for keeping changes to complicated functions simple and just wrapping them with a critical section
Acquire and release the lock in an existing function where it won't be overly disruptive to the existing logic
2024-02-06 14:03:43 -08:00
Donghee Na f7a22a7055
gh-112087: Make list_{count, index, contains} to be thread-safe. (gh-114916) 2024-02-06 16:41:18 +00:00
Sam Gross de61d4bd4d
gh-112066: Add `PyDict_SetDefaultRef` function. (#112123)
The `PyDict_SetDefaultRef` function is similar to `PyDict_SetDefault`,
but returns a strong reference through the optional `**result` pointer
instead of a borrowed reference.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-02-06 11:36:23 -05:00
Serhiy Storchaka 652fbf88c4
gh-82626: Emit a warning when bool is used as a file descriptor (GH-111275) 2024-02-05 22:51:11 +02:00
Mark Shannon 36518e69d7
GH-108362: Incremental GC implementation (GH-108038) 2024-02-05 18:28:51 +00:00