summaryrefslogtreecommitdiffstats
path: root/Include
Commit message (Collapse)AuthorAgeFilesLines
* gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)Donghee Na2023-10-101-0/+2
| | | | | | --------- Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* gh-109693: Use pyatomic.h for signal module (gh-110480)Donghee Na2023-10-091-9/+7
|
* gh-76785: Add SendChannel.send_buffer() (#110246)Eric Snow2023-10-094-2/+39
| | | (This is still a test module.)
* gh-108277: Add os.timerfd_create() function (#108382)Masaru Tsuchiyama2023-10-075-1/+11
| | | | | | | | Add wrapper for timerfd_create, timerfd_settime, and timerfd_gettime to os module. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-110397: Add Py_IsFinalizing() to the stable ABI (#110441)Victor Stinner2023-10-072-2/+4
|
* gh-85283: Add PySys_AuditTuple() function (#108965)Victor Stinner2023-10-051-1/+5
| | | | | | sys.audit() now has assertions to check that the event argument is not NULL and that the format argument does not use the "N" format. Add tests on PySys_AuditTuple().
* gh-109549: Add new states to PyThreadState to support PEP 703 (gh-109915)Sam Gross2023-10-053-1/+46
| | | This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, or _Py_THREAD_GC. The "attached" and "detached" states correspond closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for --disable-gil builds in the near future.
* gh-109329: Add stat for "trace too short" (GH-110402)Michael Droettboom2023-10-051-0/+1
|
* gh-88402: Add new sysconfig variables on Windows (GH-110049)Sam Gross2023-10-041-0/+57
| | | | Co-authored-by: Filipe Laíns <filipe.lains@gmail.com>
* gh-110310: Add a Per-Interpreter XID Registry for Heap Types (gh-110311)Eric Snow2023-10-042-19/+30
| | | | | | | | | | | We do the following: * add a per-interpreter XID registry (PyInterpreterState.xidregistry) * put heap types there (keep static types in _PyRuntimeState.xidregistry) * clear the registries during interpreter/runtime finalization * avoid duplicate entries in the registry (when _PyCrossInterpreterData_RegisterClass() is called more than once for a type) * use Py_TYPE() instead of PyObject_Type() in _PyCrossInterpreterData_Lookup() The per-interpreter registry helps preserve isolation between interpreters. This is important when heap types are registered, which is something we haven't been doing yet but I will likely do soon.
* GH-109329: Add tier 2 stats (GH-109913)Michael Droettboom2023-10-042-4/+39
|
* GH-109369: Merge all eval-breaker flags and monitoring version into one ↵Mark Shannon2023-10-044-18/+39
| | | | word. (GH-109846)
* gh-104909: Split more LOAD_ATTR specializations (GH-110317)Guido van Rossum2023-10-041-35/+111
| | | | | | | | | | | | | | | | | | | * Split LOAD_ATTR_MODULE * Split LOAD_ATTR_WITH_HINT * Split _GUARD_TYPE_VERSION out of the latter * Split LOAD_ATTR_CLASS * Split LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES * Fix indent of DEOPT_IF in macros * Split LOAD_ATTR_METHOD_LAZY_DICT * Split LOAD_ATTR_NONDESCRIPTOR_NO_DICT * Fix omission of _CHECK_ATTR_METHOD_LAZY_DICT
* gh-109979: Unify _GUARD_TYPE_VERSION{,_STORE} (#110301)Guido van Rossum2023-10-031-39/+32
| | | | | Now the target for `DEOPT_IF()` is auto-filled, we don't need a separate `_GUARD_TYPE_VERSION_STORE` uop.
* gh-108867: Add PyThreadState_GetUnchecked() function (#108870)Victor Stinner2023-10-034-4/+4
| | | | | | Add PyThreadState_GetUnchecked() function: similar to PyThreadState_Get(), but don't issue a fatal error if it is NULL. The caller is responsible to check if the result is NULL. Previously, this function was private and known as _PyThreadState_UncheckedGet().
* gh-109860: Use a New Thread State When Switching Interpreters, When ↵Eric Snow2023-10-033-1/+14
| | | | | | | | | Necessary (gh-110245) In a few places we switch to another interpreter without knowing if it has a thread state associated with the current thread. For the main interpreter there wasn't much of a problem, but for subinterpreters we were *mostly* okay re-using the tstate created with the interpreter (located via PyInterpreterState_ThreadHead()). There was a good chance that tstate wasn't actually in use by another thread. However, there are no guarantees of that. Furthermore, re-using an already used tstate is currently fragile. To address this, now we create a new thread state in each of those places and use it. One consequence of this change is that PyInterpreterState_ThreadHead() may not return NULL (though that won't happen for the main interpreter).
* gh-105716: Support Background Threads in Subinterpreters Consistently ↵Eric Snow2023-10-023-0/+8
| | | | | | | (gh-109921) The existence of background threads running on a subinterpreter was preventing interpreters from getting properly destroyed, as well as impacting the ability to run the interpreter again. It also affected how we wait for non-daemon threads to finish. We add PyInterpreterState.threads.main, with some internal C-API functions.
* gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994)Eric Snow2023-10-021-0/+3
| | | This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This PR does not address the broader concerns from gh-109853.
* gh-107073: Make PyObject_VisitManagedDict() public (#108763)Victor Stinner2023-10-021-2/+2
| | | | | | | | Make PyObject_VisitManagedDict() and PyObject_ClearManagedDict() functions public in Python 3.13 C API. * Rename _PyObject_VisitManagedDict() to PyObject_VisitManagedDict(). * Rename _PyObject_ClearManagedDict() to PyObject_ClearManagedDict(). * Document these functions.
* gh-110014: Remove PY_TIMEOUT_MAX from limited C API (#110217)Victor Stinner2023-10-022-13/+12
| | | | | | | | If the timeout is greater than PY_TIMEOUT_MAX, PyThread_acquire_lock_timed() uses a timeout of PY_TIMEOUT_MAX microseconds, which is around 280.6 years. This case is unlikely and limiting a timeout to 280.6 years sounds like a reasonable trade-off. The constant PY_TIMEOUT_MAX is not used in PyPI top 5,000 projects.
* gh-110014: Include explicitly <unistd.h> header (#110155)Victor Stinner2023-09-302-8/+25
| | | | | | | | | | | * 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-110014: Fix _POSIX_THREADS and _POSIX_SEMAPHORES usage (#110139)Victor Stinner2023-09-304-51/+28
| | | | | | | | | | | | | | | | * pycore_pythread.h is now the central place to make sure that _POSIX_THREADS and _POSIX_SEMAPHORES macros are defined if available. * Make sure that pycore_pythread.h is included when _POSIX_THREADS and _POSIX_SEMAPHORES macros are tested. * PY_TIMEOUT_MAX is now defined as a constant, since its value depends on _POSIX_THREADS, instead of being defined as a macro. * Prevent integer overflow in the preprocessor when computing PY_TIMEOUT_MAX_VALUE on Windows: replace "0xFFFFFFFELL * 1000 < LLONG_MAX" with "0xFFFFFFFELL < LLONG_MAX / 1000". * Document the change and give hints how to fix affected code. * Add an exception for PY_TIMEOUT_MAX name to smelly.py * Add PY_TIMEOUT_MAX to the stable ABI
* gh-110024: Fix Pointer Type Warnings (gh-110053)Eric Snow2023-09-291-8/+16
| | | The warnings were introduced by gh-109794 (for gh-109793).
* gh-104909: Split some more insts into ops (#109943)Guido van Rossum2023-09-272-27/+95
| | | | | | | | | | | | | | | | | | | | These are the most popular specializations of `LOAD_ATTR` and `STORE_ATTR` that weren't already viable uops: * Split LOAD_ATTR_METHOD_WITH_VALUES * Split LOAD_ATTR_METHOD_NO_DICT * Split LOAD_ATTR_SLOT * Split STORE_ATTR_SLOT * Split STORE_ATTR_INSTANCE_VALUE Also: * Add `-v` flag to code generator which prints a list of non-viable uops (easter-egg: it can print execution counts -- see source) * Double _Py_UOP_MAX_TRACE_LENGTH to 128 I had dropped one of the DEOPT_IF() calls! :-(
* gh-109793: Allow Switching Interpreters During Finalization (gh-109794)Eric Snow2023-09-274-2/+55
| | | Essentially, we should check the thread ID rather than the thread state pointer.
* 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>