summaryrefslogtreecommitdiffstats
path: root/Modules
Commit message (Collapse)AuthorAgeFilesLines
* gh-109593: Fix reentrancy issue in multiprocessing resource_tracker (#109629)Antoine Pitrou2023-09-261-0/+14
| | | | | --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-109631: Allow interruption of short repeated regex matches (GH-109867)Serhiy Storchaka2023-09-262-2/+5
| | | | Counting for signal checking now continues in new match from the point where it ended in the previous match instead of starting from 0.
* gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw ↵Radislav Chugunov2023-09-251-3/+6
| | | | memory allocator (#109808)
* gh-109723: Fix build of _testclinic_limited on WASM (#109842)Victor Stinner2023-09-251-0/+6
| | | Make sure that the Py_BUILD_CORE macro is not defined.
* gh-104469: Convert _testcapi/vectorcall_limited.c to use AC (#109691)Victor Stinner2023-09-252-5/+47
| | | Co-authored-by: nahyeon <55136494+nahyeon-an@users.noreply.github.com>
* gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)Serhiy Storchaka2023-09-235-55/+27
|
* gh-109723: Disable Py_BUILD_CORE in _testcapi (#109727)Victor Stinner2023-09-227-95/+103
| | | | | | | | | | | | | | | | | | Make sure that the internal C API is not tested by mistake by _testcapi. Undefine Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE macros in Modules/_testcapi/parts.h: move code from _testcapimodule.c. heaptype_relative.c and vectorcall_limited.c are using the limited C API which is incompatible with the internal C API. Move test_long_numbits() from _testcapi to _testinternalcapi since it uses the internal C API "pycore_long.h". Fix Modules/_testcapi/pyatomic.c: don't include Python.h directly, just include _testcapi/parts.h. Ajust "make check-c-globals" for these changes.
* gh-109693: Remove pycore_atomic_funcs.h (#109694)Sam Gross2023-09-211-13/+0
| | | _PyUnicode_FromId() now uses pyatomic.h functions instead.
* gh-109613: _pystat_fromstructstat() checks for exceptions (#109618)Victor Stinner2023-09-211-49/+72
| | | | | | | | | | | | | Fix os.stat() and os.DirEntry.stat(): check for exceptions. Previously, on Python built in debug mode, these functions could trigger a fatal Python error (and abort the process) when a function succeeded with an exception set. _pystat_fromstructstat() now exits immediately if an exception is raised, rather only checking for exceptions at the end. It fix following fatal error in fill_time(): Fatal Python error: _Py_CheckSlotResult: Slot * of type int succeeded with an exception set
* fixes gh-109559: Update `unicodedata` for Unicode 15.1.0 (GH-109560)James Gerity2023-09-203-17533/+17882
| | | | | --------- Co-authored-by: Benjamin Peterson <benjamin@python.org>
* gh-109033: Return filename with os.utime errors (#109034)Ronan Pigott2023-09-191-7/+2
| | | | | | | The filename was previously intentionally omitted from exception because "it might confuse the user". Uncaught exceptions are not generally a replacement for user-facing error messages, so obscuring this information only has the effect of making the programmer's life more difficult.
* gh-76785: Use Pending Calls When Releasing Cross-Interpreter Data (gh-109556)Eric Snow2023-09-192-28/+31
| | | This fixes some crashes in the _xxinterpchannels module, due to a race between interpreters.
* gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344)Sam Gross2023-09-196-2/+432
| | | | | | | | | | | | | | | | | | | | | | | | | | PyMutex is a one byte lock with fast, inlineable lock and unlock functions for the common uncontended case. The design is based on WebKit's WTF::Lock. PyMutex is built using the _PyParkingLot APIs, which provides a cross-platform futex-like API (based on WebKit's WTF::ParkingLot). This internal API will be used for building other synchronization primitives used to implement PEP 703, such as one-time initialization and events. This also includes tests and a mini benchmark in Tools/lockbench/lockbench.py to compare with the existing PyThread_type_lock. Uncontended acquisition + release: * Linux (x86-64): PyMutex: 11 ns, PyThread_type_lock: 44 ns * macOS (arm64): PyMutex: 13 ns, PyThread_type_lock: 18 ns * Windows (x86-64): PyMutex: 13 ns, PyThread_type_lock: 38 ns PR Overview: The primary purpose of this PR is to implement PyMutex, but there are a number of support pieces (described below). * PyMutex: A 1-byte lock that doesn't require memory allocation to initialize and is generally faster than the existing PyThread_type_lock. The API is internal only for now. * _PyParking_Lot: A futex-like API based on the API of the same name in WebKit. Used to implement PyMutex. * _PyRawMutex: A word sized lock used to implement _PyParking_Lot. * PyEvent: A one time event. This was used a bunch in the "nogil" fork and is useful for testing the PyMutex implementation, so I've included it as part of the PR. * pycore_llist.h: Defines common operations on doubly-linked list. Not strictly necessary (could do the list operations manually), but they come up frequently in the "nogil" fork. ( Similar to https://man.freebsd.org/cgi/man.cgi?queue) --------- Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-109469: Silence compiler warnings on string comparisons in _testcapi ↵Serhiy Storchaka2023-09-191-1/+2
| | | | (GH-109533)
* gh-102757: fix function signature mismatch for `functools.reduce` between ↵Xuehai Pan2023-09-181-1/+1
| | | | code and documentation (#102759)
* gh-109496: Detect Py_DECREF() after dealloc in debug mode (#109539)Victor Stinner2023-09-181-0/+21
| | | | | | | | | On a Python built in debug mode, Py_DECREF() now calls _Py_NegativeRefcount() if the object is a dangling pointer to deallocated memory: memory filled with 0xDD "dead byte" by the debug hook on memory allocators. The fix is to check the reference count *before* checking for _Py_IsImmortal(). Add test_decref_freed_object() to test_capi.test_misc.
* gh-108511: Add C API functions which do not silently ignore errors (GH-109025)Serhiy Storchaka2023-09-178-18/+65
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* Add missing `PyDoc_STR` calls (#109393)Nikita Sobolev2023-09-152-4/+4
| | | | | | | | | In files: * Modules/_ctypes/cfield.c * Modules/_struct.c * Objects/dictobject.c * Objects/typevarobject.c * Objects/unionobject.c
* gh-107782: Use _testcapi to test non-representable signatures (GH-109325)Serhiy Storchaka2023-09-141-0/+44
| | | | | | | | | Builtin functions and methods that have non-representable signatures today will have representable signatures yesterday, and they will become unusable for testing this feature. So we need to add special functions and methods to the _testcapi module that always have non-representable signatures.
* gh-108346: Fix failed benchmark in decimal (#108353)Charlie Zhao2023-09-131-53/+74
| | | Fix benchmark in decimal to work again after the int str conversion limits.
* gh-108987: Fix _thread.start_new_thread() race condition (#109135)Victor Stinner2023-09-111-16/+31
| | | | | | | | | | | | | Fix _thread.start_new_thread() race condition. If a thread is created during Python finalization, the newly spawned thread now exits immediately instead of trying to access freed memory and lead to a crash. thread_run() calls PyEval_AcquireThread() which checks if the thread must exit. The problem was that tstate was dereferenced earlier in _PyThreadState_Bind() which leads to a crash most of the time. Move _PyThreadState_CheckConsistency() from thread_run() to _PyThreadState_Bind().
* gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068)Serhiy Storchaka2023-09-091-52/+0
|
* gh-104690: thread_run() checks for tstate dangling pointer (#109056)Victor Stinner2023-09-081-2/+5
| | | | | | | | thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.
* GH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT (#108507)Victor Stinner2023-09-082-0/+6
| | | | | | | Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on "#include <Python.h>". test.pythoninfo now logs Py_C_RECURSION_LIMIT constant and other _testcapi and _testinternalcapi constants.
* gh-109045: Remove remaining LIMITED_API_AVAILABLE checks in tests (#109046)Anders Kaseorg2023-09-073-16/+0
| | | | | | | | | Commit 13a00078b81776b23b0b6add69b848382240d1f2 (#108663) made all Python builds compatible with the Limited API, and removed the LIMITED_API_AVAILABLE flag. However, some tests were still checking for that flag, so they were now being incorrectly skipped. Remove these checks to let these tests run again. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
* gh-107211: No longer export internal _PyLong_FromUid() (#109037)Victor Stinner2023-09-071-11/+17
| | | | No longer export _PyLong_FromUid() and _Py_Sigset_Converter() internal C API function.
* gh-108751: Add copy.replace() function (GH-108752)Serhiy Storchaka2023-09-061-0/+6
| | | | | | | | | It creates a modified copy of an object by calling the object's __replace__() method. It is a generalization of dataclasses.replace(), named tuple's _replace() method and replace() methods in various classes, and supports all these stdlib classes.
* C API tests: use special markers to test that output parameters were set ↵Serhiy Storchaka2023-09-067-30/+60
| | | | (GH-109014)
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-061-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Statistics gathering is now off by default. Use the "-X pystats" command line option or set the new PYTHONSTATS environment variable to 1 to turn statistics gathering on at Python startup. Statistics are no longer dumped at exit if statistics gathering was off or statistics have been cleared. Changes: * Add PYTHONSTATS environment variable. * sys._stats_dump() now returns False if statistics are not dumped because they are all equal to zero. * Add PyConfig._pystats member. * Add tests on sys functions and on setting PyConfig._pystats to 1. * Add Include/cpython/pystats.h and Include/internal/pycore_pystats.h header files. * Rename '_py_stats' variable to '_Py_stats'. * Exclude Include/cpython/pystats.h from the Py_LIMITED_API. * Move pystats.h include from object.h to Python.h. * Add _Py_StatsOn() and _Py_StatsOff() functions. Remove '_py_stats_struct' variable from the API: make it static in specialize.c. * Document API in Include/pystats.h and Include/cpython/pystats.h. * Complete pystats documentation in Doc/using/configure.rst. * Don't write "all zeros" stats: if _stats_off() and _stats_clear() or _stats_dump() were called. * _PyEval_Fini() now always call _Py_PrintSpecializationStats() which does nothing if stats are all zeros. Co-authored-by: Michael Droettboom <mdboom@gmail.com>
* gh-108717: Speedup `os.DirEntry.is_junction` function (#108718)Nikita Sobolev2023-09-062-13/+7
|
* gh-108294: Add error handling for time.sleep audit event (GH-108363)Petr Viktorin2023-09-051-1/+3
| | | | | I've also cleaned the tests up a bit to make this easier to test.
* gh-106320: Remove private _PyErr_WriteUnraisableMsg() (#108863)Victor Stinner2023-09-0410-70/+76
| | | | | | Move the private _PyErr_WriteUnraisableMsg() functions to the internal C API (pycore_pyerrors.h). Move write_unraisable_exc() from _testcapi to _testinternalcapi.
* Revert "gh-46376: Return existing pointer when possible in ctypes (#1… ↵Victor Stinner2023-09-041-35/+0
| | | | | | | | (#108688) This reverts commit 08447b5deb47e2a0df87fa0a0576d300e5c909b4. Revert also _ctypes.c changes of the PyDict_ContainsString() change, commit 67266266469fe0e817736227f39537182534c1a5.
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-037-44/+57
| | | | | | | | | | | | | | | | | | | | | | | 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-108494: Argument Clinic: inline parsing code for positional-only ↵Serhiy Storchaka2023-09-0310-41/+51
| | | | parameters in the limited C API (GH-108622)
* gh-102837: improve test coverage for math module (#102523)Sergey B Kirpichev2023-09-031-10/+7
| | | | | | | | - input checks for math_1(L989), math_1a(L1023), math_2(L1064,L1071), hypot(L2682), log(L2307), ldexp(L2168), ceil(L1165), floor(L1236,L1239) and dist(L2587,L2588,L2628). - drop inaccessible "if" branch (L3518) in perm_comb_small() - improve fsum coverage for exceptional cases (L1433,L1438,L1451,L1497), ditto fmod(L2378) - rewrite modf to fix inaccessible case(L2229), ditto for pow(L2988) (all line numbers are wrt the main branch at 5e6661bce9)
* gh-108765: include <unistd.h> in termios.c on Solaris (#108825)Jakub Kulík2023-09-021-0/+3
|
* gh-63760: Don't declare gethostname() on Solaris (#108817)Victor Stinner2023-09-021-5/+0
| | | | | | | | | | | | | Since 2005, Solaris defines gethostname(). socketmodule.c no longer has to define gethostname() for Solaris. Oracle Solaris and OpenSolaris have patches to remove the gethostname() definition in Python: * https://github.com/oracle/solaris-userland/blob/master/components/python/python37/patches/15-gethostname.patch * https://github.com/OpenIndiana/oi-userland/blob/oi/hipster/components/python/python37/patches/15-gethostname.patch * https://github.com/omniosorg/omnios-build/blob/master/build/python27/patches/24-gethostname.patch Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
* gh-108765: multiprocessing.h includes <unistd.h> (#108823)Victor Stinner2023-09-021-0/+4
|
* gh-108765: Python.h no longer includes <sys/time.h> (#108775)Victor Stinner2023-09-027-18/+24
| | | | | | | | | Python.h no longer includes <time.h>, <sys/select.h> and <sys/time.h> standard header files. * Add <time.h> include to xxsubtype.c. * Add <sys/time.h> include to posixmodule.c and semaphore.c. * readline.c includes <sys/select.h> instead of <sys/time.h>. * resource.c no longer includes <time.h> and <sys/time.h>.
* gh-108765: Python.h no longer includes <unistd.h> (#108783)Victor Stinner2023-09-0210-30/+35
|
* gh-108765: Remove old prototypes from pyport.h (#108782)Victor Stinner2023-09-023-4/+22
| | | | | | | Move prototypes of gethostname(), _getpty() and struct termios from pyport.h to the C code using them: posixmodule.c, socketmodule.c and termios.c. Replace "#ifdef SOLARIS" with "#ifdef __sun".
* gh-108777: Split _PyTime tests from _testinternalcapi.c (gh-108787)Sam Gross2023-09-026-262/+306
|
* Add Modules/_testcapi/util.h header (GH-108774)Serhiy Storchaka2023-09-016-93/+48
| | | It contains common macros used in C API tests.
* gh-108767: Replace ctype.h functions with pyctype.h functions (#108772)Victor Stinner2023-09-013-9/+10
| | | | | | | | | | | | | | Replace <ctype.h> locale dependent functions with Python "pyctype.h" locale independent functions: * Replace isalpha() with Py_ISALPHA(). * Replace isdigit() with Py_ISDIGIT(). * Replace isxdigit() with Py_ISXDIGIT(). * Replace tolower() with Py_TOLOWER(). Leave Modules/_sre/sre.c unchanged, it uses locale dependent functions on purpose. Include explicitly <ctype.h> in _decimal.c to get isascii().
* gh-106320: Remove private _PyLong_Sign() (#108743)Victor Stinner2023-09-012-0/+6
| | | | | | Move the private _PyLong_Sign() and _PyLong_NumBits() functions to the internal C API (pycore_long.h). Modules/_testcapi/long.c now uses the internal C API.
* gh-107603: Argument Clinic: Only include pycore_gc.h if needed (#108726)Victor Stinner2023-08-3193-508/+246
| | | | | | | | | | | | | | | | | | | | Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed, and only includes pycore_runtime.h if _Py_ID() is needed. * Add 'condition' optional argument to Clinic.add_include(). * deprecate_keyword_use() includes pycore_runtime.h when using the _PyID() function. * Fix rendering of includes: comments start at the column 35. * Mark PC/clinic/_wmimodule.cpp.h and "Objects/stringlib/clinic/*.h.h" header files as generated in .gitattributes. Effects: * 42 header files generated by AC no longer include the internal C API, instead of 4 header files before. For example, Modules/clinic/_abc.c.h no longer includes the internal C API. * Fix _testclinic_depr.c.h: it now always includes pycore_runtime.h to get _Py_ID().
* gh-108337: Add pyatomic.h header (#108701)Victor Stinner2023-08-314-1/+185
| | | | | | | | This adds a new header that provides atomic operations on common data types. The intention is that this will be exposed through Python.h, although that is not the case yet. The only immediate use is in the test file. Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-311-21/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: winconsoleio.c includes pycore_pyerrors.h (#108720)Victor Stinner2023-08-311-0/+1
| | | | | Fix compiler warning: warning C4013: '_PyErr_ChainExceptions1' undefined