aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/bltinmodule.c
Commit message (Collapse)AuthorAge
* gh-130070: Fix `exec(<string>, closure=<non-None>)` unexpected path (#130071)Bartosz Sławecki2025-04-17
| | | | | | Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled) for `exec` when the `source` argument is a string and the `closure` argument is not `None`. Co-authored-by: sobolevn <mail@sobolevn.me>
* gh-131525: Cache the result of tuple_hash (#131529)Michael Droettboom2025-03-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* gh-131586: Avoid refcount contention in some "special" calls (#131588)Sam Gross2025-03-26
| | | | | | | | | | 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.
* gh-131670: Fix crash in `anext()` when `__anext__` is sync and raises (#131682)sobolevn2025-03-24
| | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-131238: Remove more includes from pycore_interp.h (#131480)Victor Stinner2025-03-19
|
* gh-131238: Remove pycore_runtime.h from pycore_pystate.h (#131356)Victor Stinner2025-03-19
| | | | | | | | | | | | * Remove includes from pycore_pystate.h: * pycore_runtime_structs.h * pycore_runtime.h * pycore_tstate.h * pycore_interp.h * Reorganize internal headers. Move _gc_thread_state from pycore_interp_structs.h to pycore_tstate.h. * Add 3 new header files to PCbuild/pythoncore.vcxproj.
* gh-130080: implement PEP 765 (#130087)Irit Katriel2025-03-17
|
* GH-131238: More refactoring of core header files (GH-131351)Mark Shannon2025-03-17
| | | | Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-11
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)Serhiy Storchaka2025-02-25
| | | | | | | | The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
* gh-130139: always check ast node type in ast.parse() with ast input (#130140)Irit Katriel2025-02-16
|
* gh-111178: fix UBSan failures in `Python/bltinmodule.c` (GH-128235)Bénédikt Tran2025-01-10
| | | | | * fix UBSan failures for `filterobject` * fix UBSan failures for `mapobject` * fix UBSan failures for `zipobject`
* gh-127271: Replace use of PyCell_GET/SET (gh-127272)Neil Schemenauer2024-12-03
| | | | | | | | | | | | | | | | | | * Replace uses of `PyCell_GET` and `PyCell_SET`. These macros are not safe to use in the free-threaded build. Use `PyCell_GetRef()` and `PyCell_SetTakeRef()` instead. * Since `PyCell_GetRef()` returns a strong rather than borrowed ref, some code restructuring was required, e.g. `frame_get_var()` returns a strong ref now. * Add critical sections to `PyCell_GET` and `PyCell_SET`. * Move critical_section.h earlier in the Python.h file. * Add `PyCell_GET` to the free-threading howto table of APIs that return borrowed refs. * Add additional unit tests for free-threading.
* gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)Sergey B Kirpichev2024-11-26
| | | | | | | | | | | | | | | "Generally, mixed-mode arithmetic combining real and complex variables should be performed directly, not by first coercing the real to complex, lest the sign of zero be rendered uninformative; the same goes for combinations of pure imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for complex elementary functions. This patch implements mixed-mode arithmetic rules, combining real and complex variables as specified by C standards since C99 (in particular, there is no special version for the true division with real lhs operand). Most C compilers implementing C99+ Annex G have only these special rules (without support for imaginary type, which is going to be deprecated in C2y).
* gh-126757: fix minor typo (GH-126758)Yuxuan Zhang2024-11-12
|
* gh-122943: Remove the object converter for var-positional parameter (GH-126560)Serhiy Storchaka2024-11-08
|
* gh-119793: Add optional length-checking to `map()` (GH-120471)Nice Zombies2024-11-04
| | | | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
* gh-125900: Clean-up logic around immortalization in free-threading (#125901)Sam Gross2024-10-24
| | | | | | | | | * Remove `@suppress_immortalization` decorator * Make suppression flag per-thread instead of per-interpreter * Suppress immortalization in `eval()` to avoid refleaks in three tests (test_datetime.test_roundtrip, test_logging.test_config8_ok, and test_random.test_after_fork). * frozenset() is constant, but not a singleton. When run multiple times, the test could fail due to constant interning.
* gh-123271: Make builtin zip method safe under free-threading (#123272)Pieter Eendebak2024-08-27
| | | | | | | | | | | | | | | | The `zip_next` function uses a common optimization technique for methods that generate tuples. The iterator maintains an internal reference to the returned tuple. When the method is called again, it checks if the internal tuple's reference count is 1. If so, the tuple can be reused. However, this approach is not safe under the free-threading build: after checking the reference count, another thread may perform the same check and also reuse the tuple. This can result in a double decref on the items of the replaced tuple and a double incref (memory leak) on the items of the tuple being set. This adds a function, `_PyObject_IsUniquelyReferenced` that encapsulates the stricter logic necessary for the free-threaded build: the internal tuple must be owned by the current thread, have a local refcount of one, and a shared refcount of zero.
* gh-122234: Add DECREFs to error paths (#122406)Petr Viktorin2024-07-29
| | | Co-Authored-By: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-122234: fix accuracy issues for sum() (#122236)Sergey B Kirpichev2024-07-29
| | | | | | | | * Use compensated summation for complex sums with floating-point items. This amends #121176. * sum() specializations for floats and complexes now use PyLong_AsDouble() instead of PyLong_AsLongAndOverflow() and compensated summation as well.
* gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)Serhiy Storchaka2024-07-13
| | | | | | * 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-121149: improve accuracy of builtin sum() for complex inputs (gh-121176)Sergey B Kirpichev2024-07-05
|
* gh-120526: Correct signature of map() builtin (GH-120528)Adam Williamson2024-06-15
| | | | | map() requires at least one iterable arg. Signed-off-by: Adam Williamson <awilliam@redhat.com>
* gh-117657: Fix race involving immortalizing objects (#119927)Sam Gross2024-06-03
| | | | | | | | | The free-threaded build currently immortalizes objects that use deferred reference counting (see gh-117783). This typically happens once the first non-main thread is created, but the behavior can be suppressed for tests, in subinterpreters, or during a compile() call. This fixes a race condition involving the tracking of whether the behavior is suppressed.
* gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE (#119619)Sergey B Kirpichev2024-05-29
|
* gh-118527: Intern code consts in free-threaded build (#118667)Sam Gross2024-05-06
| | | | | | We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
* gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL ↵Petr Viktorin2024-05-06
| | | | (GH-118645)
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-03
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-105879: Add support for keyword arguments to eval and exec (#105885)Raphael Gaschignard2024-05-02
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-117764: Fix and add signatures for many builtins (GH-117769)Serhiy Storchaka2024-04-12
|
* gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)Serhiy Storchaka2024-03-07
|
* gh-76763: Make chr() always raising ValueError for out-of-range values ↵Serhiy Storchaka2024-02-10
| | | | | | (GH-114882) Previously it raised OverflowError for very large or very small values.
* gh-111417: Remove unused code block in math.trunc() and round() (GH-111454)Jason Zhang2024-02-03
| | | _PyObject_LookupSpecial() now ensures that the type is ready.
* gh-90350: Optimize builtin functions min() and max() (GH-30286)colorfulappl2023-12-11
| | | | Builtin functions min() and max() now use METH_FASTCALL
* gh-74616: Raise ValueError in case of null character in input prompt (GH-1738)Kushal Das2023-12-07
| | | | | | | If the input prompt to the builtin input function on terminal has any null character, then raise ValueError instead of silently truncating it. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-111789: Use PyDict_GetItemRef() in Python/bltinmodule.c (gh-112081)Serhiy Storchaka2023-11-27
|
* gh-111999: Add signatures and improve docstrings for builtins (GH-112000)Serhiy Storchaka2023-11-13
|
* gh-111933: fix broken link to A.Neumaier article (gh-111937)Sergey B Kirpichev2023-11-11
|
* gh-110014: Include explicitly <unistd.h> header (#110155)Victor Stinner2023-09-30
| | | | | | | | | | | * Remove unused <locale.h> includes. * Remove unused <fcntl.h> include in traceback.h. * Remove redundant <assert.h> and <stddef.h> includes. They are already included by "Python.h". * Remove <object.h> include in faulthandler.c. Python.h already includes it. * Add missing <stdbool.h> in pycore_pythread.h if HAVE_PTHREAD_STUBS is defined. * Fix also warnings in pthread_stubs.h: don't redefine macros if they are already defined, like the __NEED_pthread_t macro.
* gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)Serhiy Storchaka2023-09-23
|
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-03
| | | | | | | | | | | | | | | | | | | | | | | Remove <ctype.h> in C files which don't use it; only sre.c and _decimal.c still use it. Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h: * Code added by commit b5047fd01948ab108edcc1b3c2c901d915814cfd in 2004 for MacOSX and FreeBSD. * Test removed by commit 52ddaefb6bab1a74ecffe8519c02735794ebfbe1 in 2007, since Python str type now uses locale independent functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode database. Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new functions: sre_isalnum(), sre_tolower(), sre_toupper(). Remove unused includes: * _localemodule.c: remove <stdio.h>. * getargs.c: remove <float.h>. * dynload_win.c: remove <direct.h>, it no longer calls _getcwd() since commit fb1f68ed7cc1536482d1debd70a53c5442135fe2 (in 2001).
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API. Change Py_TRACE_REFS build: * Remove _PyObject_EXTRA_INIT macro. * The PyObject structure no longer has two extra members (_ob_prev and _ob_next). * Use a hash table (_Py_hashtable_t) to trace references (all objects): PyInterpreterState.object_state.refchain. * Py_TRACE_REFS build is now ABI compatible with release build and debug build. * Limited C API extensions can now be built with Py_TRACE_REFS: xxlimited, xxlimited_35, _testclinic_limited. * No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2() functions to PyModule_Create2TraceRefs() and PyModule_FromDefAndSpec2TraceRefs(). * _Py_PrintReferenceAddresses() is now called before finalize_interp_delete() which deletes the refchain hash table. * test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace(). Test changes for Py_TRACE_REFS: * Add test.support.Py_TRACE_REFS constant. * Add test_sys.test_getobjects() to test sys.getobjects() function. * test_exceptions skips test_recursion_normalizing_with_no_memory() and test_memory_error_in_PyErr_PrintEx() if Python is built with Py_TRACE_REFS. * test_repl skips test_no_memory(). * test_capi skisp test_set_nomemory().
* gh-106320: Remove private pythonrun API (#108599)Victor Stinner2023-08-29
| | | | | | | | | | | Remove these private functions from the public C API: * _PyRun_AnyFileObject() * _PyRun_InteractiveLoopObject() * _PyRun_SimpleFileObject() * _Py_SourceAsString() Move them to the internal C API: add a new pycore_pythonrun.h header file. No longer export these functions.
* gh-106320: Remove private _PySys functions (#108452)Victor Stinner2023-08-24
| | | | | | | | | | Move private functions to the internal C API (pycore_sysmodule.h): * _PySys_GetAttr() * _PySys_GetSizeOf() No longer export most of these functions. Fix also a typo in Include/cpython/optimizer.h: add a missing space.
* gh-108113: Make it possible to optimize an AST (#108282)Irit Katriel2023-08-23
|
* gh-107526: Revert "gh-100357: Convert several functions in bltinsmodule to ↵Nikita Sobolev2023-08-20
| | | | AC" (#107542)
* gh-106320: Remove private _PyDict C API (#107145)Victor Stinner2023-07-24
| | | | | | | | | | | | | Move private _PyDict functions to the internal C API (pycore_dict.h): * _PyDict_Contains_KnownHash() * _PyDict_DebugMallocStats() * _PyDict_DelItemIf() * _PyDict_GetItemWithError() * _PyDict_HasOnlyStringKeys() * _PyDict_MaybeUntrack() * _PyDict_MergeEx() No longer export these functions.
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-12
|
* gh-106572: Convert PyObject_DelAttr() to a function (#106611)Victor Stinner2023-07-11
| | | | | | | | * Convert PyObject_DelAttr() and PyObject_DelAttrString() macros to functions. * Add PyObject_DelAttr() and PyObject_DelAttrString() functions to the stable ABI. * Replace PyObject_SetAttr(obj, name, NULL) with PyObject_DelAttr(obj, name).