Commit Graph

8726 Commits

Author SHA1 Message Date
Kumar Aditya ed99e28d5b
gh-132213: use relaxed atomics for set hash (#132215) 2025-04-07 21:59:24 +05:30
Jelle Zijlstra 9a6b702f3a
dictobject.c: Fix incorrect function name in errors (#132193) 2025-04-07 07:48:55 -07:00
Pieter Eendebak dff8bcfa3c
gh-126703: Add freelist for range and range_iter objects (GH-128619) 2025-04-07 04:40:52 +08:00
Pieter Eendebak 29772b0647
gh-126703: Add PyCFunction freelist (GH-128692) 2025-04-05 23:51:05 +08:00
Kumar Aditya 76f6b5e64a
gh-132013: use relaxed atomics in hash of frozenset (#132014)
Use relaxed atomics in hash of `frozenset` to fix TSAN warning.
2025-04-02 20:01:05 +05:30
mpage 053c285f6b
gh-130704: Strength reduce `LOAD_FAST{_LOAD_FAST}` (#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
2025-04-01 10:18:42 -07:00
Bénédikt Tran edbf7fb129
gh-111178: remove redundant casts for functions with correct signatures (#131673) 2025-04-01 17:18:11 +02:00
Chris Eibl a175d64e30
GH-129149: Add fast path for medium-sized integers in `PyLong_From*` functions (#131211)
Add a fast path for medium-sized integers in `PyLong_FromInt{32,64}` and `PyLong_FromUInt{32,64}`.
2025-03-30 10:12:42 +02:00
Dino Viehland 2984ff9e51
gh-130373: Avoid locking in _LOAD_ATTR_WITH_HINT (#130372)
Avoid locking in _LOAD_ATTR_WITH_HINT
2025-03-28 15:16:41 -07:00
Irit Katriel 2c8f329dc6
gh-131738: optimize builtin any/all/tuple calls with a generator expression arg (#131737) 2025-03-28 10:35:20 +00:00
Michael Droettboom 8614f86b71
gh-131525: Cache the result of tuple_hash (#131529)
* gh-131525: Cache the result of tuple_hash

* Fix debug builds

* Add blurb

* Fix formatting

* Pre-compute empty tuple singleton

* Mostly set the cache within tuple_alloc

* Fixes for TSAN

* Pre-compute empty tuple singleton

* Fix for 32-bit platforms

* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE

* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro

* Update Include/internal/pycore_tuple.h

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix alignment

* atomic load

* Update Objects/tupleobject.c

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00
Sam Gross 67fbfb42bd
gh-131586: Avoid refcount contention in some "special" calls (#131588)
In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to
reference count contention on the returned function object becuase it
doesn't use stackrefs. Refactor some of the callers to use
`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.

This fixes the scaling bottleneck in the "lookup_special" microbenchmark
in `ftscalingbench.py`. However, the are still some uses of
`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
2025-03-26 14:38:47 -04:00
Sam Gross 5abff6960b
gh-117657: Fix data race in `compare_unicode_unicode_threadsafe` (gh-131746)
We can't safely check the type of the found key until we incref it or if we know that it's immortal.
2025-03-26 09:01:57 -04:00
Tomasz Pytel 0a91456ad1
gh-131719: add NULL pointer check to `_PyMem_FreeDelayed` (gh-131720) 2025-03-25 10:49:18 -04:00
Sergey Muraviov 44605aa93d
gh-131711: Preventing the use of a null pointer in set_tp_mro (#131713) 2025-03-25 14:28:38 +01:00
Bénédikt Tran 1393bd3548
gh-131666: mark `anext_awaitable.close` as a `METH_NOARGS` instead of `METH_VARARGS` (#131671) 2025-03-25 09:03:22 +05:30
Ageev Maxim 7c3692fe27
gh-130928: Fix error message during bytes formatting for the `'i'` flag (#130967) 2025-03-24 22:07:03 +03:00
Bénédikt Tran 4efe397d8e
gh-111178: fix UBSan failures for `anextawaitableobject` (#131609) 2025-03-24 14:43:48 +00:00
Sam Gross da6730caa5
gh-128421: Avoid TSAN warnings in `sys._current_frames()` (gh-131548)
This tells TSAN not to sanitize `PyUnstable_InterpreterFrame_GetLine()`.
There's a possible data race on the access to the frame's `instr_ptr`
if the frame is currently executing. We don't really care about the
race. In theory, we could use relaxed atomics for every access to
`instr_ptr`, but that would create more code churn and current compilers
are overly conservative with optimizations around relaxed atomic
accesses.

We also don't sanitize `_PyFrame_IsIncomplete()` because it accesses
`instr_ptr` and is called from assertions within PyFrame_GetCode().
2025-03-24 09:49:39 -04:00
Bénédikt Tran a1205ef524
gh-111178: fix UBSan failures for `PyBytesObject` (#131603) 2025-03-24 11:02:09 +01:00
Bénédikt Tran 27f81e82df
gh-111178: fix UBSan failures for `PyStdPrinter_Object` (#131607) 2025-03-24 10:57:14 +01:00
Bénédikt Tran aa444bc4af
gh-111178: fix UBSan failures for `PyBufferWrapper` (#131616) 2025-03-24 10:52:52 +01:00
Dino Viehland d9411ae3c2
gh-130312: SET_ADD should not lock (#130136)
SET_ADD should not lock
2025-03-21 15:58:32 -07:00
Victor Stinner 7101cba6bf
gh-131238: Move _Py_VISIT_STACKREF() to pycore_stackref.h (#131560)
* Move _Py_VISIT_STACKREF() from pycore_gc.h to pycore_stackref.h.
* Remove pycore_interpframe.h include from pycore_genobject.h.
* Remove now useless includes from C files.
* Add pycore_interpframe_structs.h to Makefile.pre.in and
  pythoncore.vcxproj.
2025-03-21 23:24:14 +01:00
Victor Stinner 61317074d4
gh-131238: Add pycore_interpframe_structs.h header (#131553)
Add an explicit include to pycore_interpframe_structs.h in
pycore_runtime_structs.h to fix a dependency cycle.
2025-03-21 17:19:47 +00:00
Victor Stinner 1a082085ae
gh-131238: Remove pycore_object_deferred.h from pycore_object.h (#131549)
Remove also pycore_function.h from pycore_typeobject.h.
2025-03-21 16:44:10 +00:00
Sam Gross 4f32516804
gh-128421: Add locking to most frame object functions (gh-131479)
This makes more operations on frame objects thread-safe in the free
threaded build, which fixes some data races that occurred when passing
exceptions between threads.

However, accessing local variables from another thread while its running
is still not thread-safe and may crash the interpreter.
2025-03-21 11:10:07 -04:00
Mark Shannon 7ebd71ee14
GH-131498: Remove conditional stack effects (GH-131499)
* Adds some missing #includes
2025-03-20 15:39:38 +00:00
Victor Stinner b69da006a4
gh-131238: Remove includes from pycore_interp.h (#131495)
Remove also now unused includes in C files.
2025-03-20 11:35:23 +00:00
Victor Stinner 34c1ea3109
gh-111178: Fix function signatures for multiple tests (#131496) 2025-03-20 12:27:03 +01:00
Victor Stinner 20c5f969dd
gh-131238: Remove more includes from pycore_interp.h (#131480) 2025-03-19 23:01:32 +01:00
Victor Stinner 22706843e0
gh-131238: Remove many includes from pycore_interp.h (#131472) 2025-03-19 17:46:24 +00:00
Victor Stinner 5c44d7d99c
gh-130931: Add pycore_interpframe.h internal header (#131249)
Move _PyInterpreterFrame and associated functions
to a new pycore_interpframe.h header.
2025-03-19 18:17:44 +01:00
Victor Stinner bbe5baad6c
gh-111178: Fix function signatures for test_types (#131455) 2025-03-19 13:46:17 +00:00
Victor Stinner f5e4c2955b
gh-111178: Fix function signatures for test_iter (#131456) 2025-03-19 14:42:51 +01:00
Mark Shannon a45f25361d
GH-131238: More refactoring of core header files (GH-131351)
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
2025-03-17 14:41:05 +00:00
Victor Stinner 978e37bb5f
gh-131238: Add explicit includes to pycore headers (#131257) 2025-03-17 12:32:43 +01:00
Mark Shannon a1aeec61c4
GH-131238: Core header refactor (GH-131250)
* Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h

* Removes many cross-header dependencies
2025-03-17 09:19:04 +00:00
Victor Stinner db62557e3d
gh-111178: Fix function signatures for test_os (#131227) 2025-03-14 13:53:06 +00:00
Victor Stinner a5776639c8
gh-111178: Fix function signatures to fix undefined behavior (#131191) 2025-03-14 09:52:15 +00:00
Victor Stinner c497f83ad8
gh-111178: Fix function signatures for PyStdPrinter (#131192) 2025-03-14 10:24:38 +01:00
Pieter Eendebak ec46a55d63
gh-121464: Make concurrent iteration over enumerate safe under free-threading (#125734) 2025-03-14 00:14:05 +05:30
Victor Stinner 9a63138e09
gh-111178: Fix function signatures in misc files (#131180) 2025-03-13 16:55:08 +01:00
Chris Eibl 119bcfad9c
gh-129149: Add fast path for medium-sized integers in `PyLong_FromSsize_t()` (#129301)
The implementation of `PyLong_FromLong()`, `PyLong_FromLongLong()` and `PyLong_FromSsize_t()`
are now handled by a common macro `PYLONG_FROM_INT` which contains fast paths depending on the
size of the integer to convert. Consequently, `PyLong_FromSsize_t()` for medium-sized integers is faster
by roughly 25%.

---------

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-03-13 12:06:56 +01:00
Victor Stinner d12d8c50cd
gh-111178: Fix function signatures in odictobject.c (#131160)
Add _PyODictObject_CAST() macro.
2025-03-13 10:14:59 +00:00
Victor Stinner 50e9eba32c
gh-111178: Fix function signatures in rangeobject.c (#131161) 2025-03-13 09:56:06 +00:00
Victor Stinner 0c6c52f496
gh-111178: Fix PyRangeIter_Type deallocator (#131162)
Don't use PyObject_Free() as tp_dealloc to avoid an undefined
behavior. Instead, use the default deallocator which just calls
tp_free which is PyObject_Free().
2025-03-13 10:46:20 +01:00
Victor Stinner 36978f7ef3
gh-111178: Fix function signatures in iterobject.c (#131163) 2025-03-13 10:42:59 +01:00
Victor Stinner 2ed671b5e3
gh-111178: Change Argument Clinic signature for `@staticmethod` (#131157) (#131159)
Use "PyObject*", instead of "void*", for `@staticmethod` functions to
fix an undefined behavior.
2025-03-13 10:22:58 +01:00
Mark Shannon f30376c650
GH-127705: Fix _Py_RefcntAdd to handle objects becoming immortal (GH-131140) 2025-03-12 16:54:10 +00:00