summaryrefslogtreecommitdiffstats
path: root/Include
Commit message (Collapse)AuthorAgeFilesLines
* gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)Serhiy Storchaka2023-09-231-0/+2
|
* gh-109596: Ensure repeated rules in the grammar are not allowed and fix ↵Pablo Galindo Salgado2023-09-221-3/+0
| | | | incorrect soft keywords (#109606)
* gh-104469: Disallow using Py_LIMITED_API with Py_BUILD_CORE (#109690)Victor Stinner2023-09-211-0/+4
| | | | Fix make check-c-globals: complete USE_LIMITED_C_API list of the c-analyzer.
* gh-109693: Remove pycore_atomic_funcs.h (#109694)Sam Gross2023-09-211-94/+0
| | | _PyUnicode_FromId() now uses pyatomic.h functions instead.
* gh-76785: Use Pending Calls When Releasing Cross-Interpreter Data (gh-109556)Eric Snow2023-09-193-2/+5
| | | This fixes some crashes in the _xxinterpchannels module, due to a race between interpreters.
* gh-108724: Fix _PySemaphore compile error on WASM (gh-109583)Sam Gross2023-09-191-1/+2
| | | Some WASM platforms have POSIX semaphores, but not sem_timedwait.
* gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344)Sam Gross2023-09-198-7/+448
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-109496: Detect Py_DECREF() after dealloc in debug mode (#109539)Victor Stinner2023-09-181-6/+4
| | | | | | | | | 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-172-0/+35
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* gh-106213: Make Emscripten trampolines work with JSPI (GH-106219)Hood Chatham2023-09-153-0/+89
| | | | | | | | | | | | | | | | | | | | | | | | There is a WIP proposal to enable webassembly stack switching which have been implemented in v8: https://github.com/WebAssembly/js-promise-integration It is not possible to switch stacks that contain JS frames so the Emscripten JS trampolines that allow calling functions with the wrong number of arguments don't work in this case. However, the js-promise-integration proposal requires the [type reflection for Wasm/JS API](https://github.com/WebAssembly/js-types) proposal, which allows us to actually count the number of arguments a function expects. For better compatibility with stack switching, this PR checks if type reflection is available, and if so we use a switch block to decide the appropriate signature. If type reflection is unavailable, we should use the current EMJS trampoline. We cache the function argument counts since when I didn't cache them performance was negatively affected. Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: Brett Cannon <brett@python.org>
* gh-109287: Desugar inst(X) to op(X); macro(X) = X (#109294)Guido van Rossum2023-09-151-2/+18
| | | This makes the internal representation in the code generator simpler: there's a list of ops, and a list of macros, and there's no special-casing needed for ops that aren't macros. (There's now special-casing for ops that are also macros, but that's simpler.)
* GH-104584: Don't call executors from JUMP_BACKWARD (GH-109347)Brandt Bucher2023-09-131-1/+1
|
* GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)Brandt Bucher2023-09-133-130/+140
|
* gh-109256: allocate opcode IDs for internal opcodes in their own range (#109269)Irit Katriel2023-09-122-283/+283
|
* gh-109214: Rename SAVE_IP to _SET_IP, and similar (#109285)Guido van Rossum2023-09-111-35/+35
| | | | | | | | * Rename SAVE_IP to _SET_IP * Rename EXIT_TRACE to _EXIT_TRACE * Rename SAVE_CURRENT_IP to _SAVE_CURRENT_IP * Rename INSERT to _INSERT (This is for Ken Jin's abstract interpreter) * Rename IS_NONE to _IS_NONE * Rename JUMP_TO_TOP to _JUMP_TO_TOP
* gh-109039: Branch prediction for Tier 2 interpreter (#109038)Guido van Rossum2023-09-112-10/+13
| | | | | | | | | | | This adds a 16-bit inline cache entry to the conditional branch instructions POP_JUMP_IF_{FALSE,TRUE,NONE,NOT_NONE} and their instrumented variants, which is used to keep track of the branch direction. Each time we encounter these instructions we shift the cache entry left by one and set the bottom bit to whether we jumped. Then when it's time to translate such a branch to Tier 2 uops, we use the bit count from the cache entry to decided whether to continue translating the "didn't jump" branch or the "jumped" branch. The counter is initialized to a pattern of alternating ones and zeros to avoid bias. The .pyc file magic number is updated. There's a new test, some fixes for existing tests, and a few miscellaneous cleanups.
* gh-108987: Fix _thread.start_new_thread() race condition (#109135)Victor Stinner2023-09-111-0/+2
| | | | | | | | | | | | | 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-109118: Fix runtime crash when NameError happens in PEP 695 function ↵Jelle Zijlstra2023-09-091-52/+38
| | | | (#109123)
* GH-108614: Unbreak emscripten build (GH-109132)Mark Shannon2023-09-081-0/+1
|
* gh-104690: thread_run() checks for tstate dangling pointer (#109056)Victor Stinner2023-09-081-0/+4
| | | | | | | | 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-081-10/+9
| | | | | | | 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-108716: Turn off deep-freezing of code objects. (GH-108722)Mark Shannon2023-09-083-3/+1
|
* GH-108614: Add `RESUME_CHECK` instruction (GH-108630)Mark Shannon2023-09-072-143/+150
|
* gh-107265: Remove all ENTER_EXECUTOR when execute _Py_Instrument (gh-108539)Dong-hee Na2023-09-071-0/+3
|
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-065-120/+168
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-108765: Cleanup #include in Python/*.c files (#108977)Victor Stinner2023-09-061-0/+2
| | | Mention one symbol imported by each #include.
* GH-108390: Prevent non-local events being set with ↵Mark Shannon2023-09-053-8/+13
| | | | `sys.monitoring.set_local_events()` (GH-108420)
* gh-106320: Remove private _PyErr_WriteUnraisableMsg() (#108863)Victor Stinner2023-09-042-4/+5
| | | | | | Move the private _PyErr_WriteUnraisableMsg() functions to the internal C API (pycore_pyerrors.h). Move write_unraisable_exc() from _testcapi to _testinternalcapi.
* GH-108614: Remove `TIER_ONE` and `TIER_TWO` from `_PUSH_FRAME` (GH-108725)Mark Shannon2023-09-041-3/+3
|
* gh-108765: Move export code from pyport.h to exports.h (#108855)Victor Stinner2023-09-032-71/+72
| | | There is no API change, since pyport.h includes exports.h.
* gh-108765: Move stat() fiddling from pyport.h to fileutils.h (#108854)Victor Stinner2023-09-032-37/+36
|
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-032-39/+0
| | | | | | | | | | | | | | | | | | | | | | | 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-108765: Python.h no longer includes <sys/time.h> (#108775)Victor Stinner2023-09-021-19/+0
| | | | | | | | | 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-021-6/+5
|
* gh-108765: Python.h no longer includes <ieeefp.h> (#108781)Victor Stinner2023-09-022-6/+1
| | | | Remove also the HAVE_IEEEFP_H macro: remove ieeefp.h from the AC_CHECK_HEADERS() check of configure.ac.
* gh-108765: Remove old prototypes from pyport.h (#108782)Victor Stinner2023-09-021-26/+0
| | | | | | | 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-108765: Move standard includes to Python.h (#108769)Victor Stinner2023-09-0110-59/+43
| | | | | | | | | | | | * Move <ctype.h>, <limits.h> and <stdarg.h> standard includes to Python.h. * Move "pystats.h" include from object.h to Python.h. * Remove redundant "pymem.h" include in objimpl.h and "pyport.h" include in pymem.h; Python.h already includes them earlier. * Remove redundant <wchar.h> include in unicodeobject.h; Python.h already includes it. * Move _SGI_MP_SOURCE define from Python.h to pyport.h. * pycore_condvar.h includes explicitly <unistd.h> for the _POSIX_THREADS macro.
* gh-108765: Reformat Include/pymacconfig.h (#108764)Victor Stinner2023-09-011-77/+69
| | | Replace "MacOSX" with "macOS".
* gh-108765: Reformat Include/osdefs.h (#108766)Victor Stinner2023-09-011-21/+27
|
* gh-108634: PyInterpreterState_New() no longer calls Py_FatalError() (#108748)Victor Stinner2023-09-013-4/+9
| | | | | | | | | | | | pycore_create_interpreter() now returns a status, rather than calling Py_FatalError(). * PyInterpreterState_New() now calls Py_ExitStatusException() instead of calling Py_FatalError() directly. * Replace Py_FatalError() with PyStatus in init_interpreter() and _PyObject_InitState(). * _PyErr_SetFromPyStatus() now raises RuntimeError, instead of ValueError. It can now call PyErr_NoMemory(), raise MemoryError, if it detects _PyStatus_NO_MEMORY() error message.
* gh-106320: Remove private _PyLong_Sign() (#108743)Victor Stinner2023-09-012-15/+17
| | | | | | 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-108337: Add pyatomic.h header (#108701)Victor Stinner2023-08-315-3/+2824
| | | | | | | | 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-316-43/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
* Run make regen-global-objects (#108714)Victor Stinner2023-08-314-30/+0
|
* gh-106320: Remove private _PyErr_ChainExceptions() (#108713)Victor Stinner2023-08-314-6/+11
| | | | | | | | | | | | | Remove _PyErr_ChainExceptions(), _PyErr_ChainExceptions1() and _PyErr_SetFromPyStatus() functions from the public C API. * Move the private _PyErr_ChainExceptions() and _PyErr_ChainExceptions1() function to the internal C API (pycore_pyerrors.h). * Move the private _PyErr_SetFromPyStatus() to the internal C API (pycore_initconfig.h). * No longer export the _PyErr_ChainExceptions() function. * Move run_in_subinterp_with_config() from _testcapi to _testinternalcapi.
* gh-106320: Don't export _Py_ForgetReference() function (#108712)Victor Stinner2023-08-311-2/+8
| | | | | There is no need to export the _Py_ForgetReference() function of the Py_TRACE_REFS build. It's not used by shared extensions. Enhance also its comment.
* gh-107149: Make PyUnstable_ExecutableKinds public (#108440)Victor Stinner2023-08-312-8/+8
| | | | | | Move PyUnstable_ExecutableKinds and associated macros from the internal C API to the public C API. Rename constants: replace "PY_" prefix with "PyUnstable_" prefix.
* gh-106320: Remove private _Py_ForgetReference() (#108664)Victor Stinner2023-08-302-5/+5
| | | | Move the private _Py_ForgetReference() function to the internal C API (pycore_object.h).
* gh-107557: Remove unnecessary SAVE_IP instructions (#108583)Guido van Rossum2023-08-291-195/+255
| | | | | Also remove NOP instructions. The "stubs" are not optimized in this fashion (their SAVE_IP should always be preserved since it's where to jump next, and they don't contain NOPs by their nature).
* gh-108635: Make parameters of some implementations of special methods ↵Serhiy Storchaka2023-08-294-6/+0
| | | | positional-only (GH-108636)