summaryrefslogtreecommitdiffstats
path: root/Modules/_testinternalcapi.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.14] gh-124621: Emscripten: Add support for async input devices ↵Miss Islington (bot)2025-07-221-0/+34
| | | | | | | | | | | | | | | | | | | | | | | (GH-136822) (GH-136935) This is useful for implementing proper `input()`. It requires the JavaScript engine to support the wasm JSPI spec which is now stage 4. It is supported on Chrome since version 137 and on Firefox and node behind a flag. We override the `__wasi_fd_read()` syscall with our own variant that checks for a readAsync operation. If it has it, we use our own async variant of `fd_read()`, otherwise we use the original `fd_read()`. We also add a variant of `FS.createDevice()` called `FS.createAsyncInputDevice()`. Finally, if JSPI is available, we wrap the `main()` symbol with `WebAssembly.promising()` so that we can stack switch from `fd_read()`. If JSPI is not available, attempting to read from an AsyncInputDevice will raise an `OSError`. (cherry picked from commit 7ae4749d064bd49b0dd96172fee20c1f1678d9e9) Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
* [3.14] gh-130396: Move PYOS_LOG2_STACK_MARGIN to internal headers ↵Miss Islington (bot)2025-07-011-1/+1
| | | | | | | | | | | | | (GH-135928) (#136173) gh-130396: Move PYOS_LOG2_STACK_MARGIN to internal headers (GH-135928) Move PYOS_LOG2_STACK_MARGIN, PYOS_STACK_MARGIN, PYOS_STACK_MARGIN_BYTES and PYOS_STACK_MARGIN_SHIFT macros to pycore_pythonrun.h internal header. Add underscore (_) prefix to the names to make them private. Rename _PYOS to _PyOS. (cherry picked from commit 28940e8e4884eb3444a8ea15a5634f76b154d7ed) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.14] gh-135755: Move `PyFunction_GET_BUILTINS` to the private API ↵Miss Islington (bot)2025-06-261-2/+3
| | | | | | | (GH-135938) (GH-135972) (cherry picked from commit 10a3d431881bb9169abde97f85ea6a670e1ef3cc) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* [3.14] gh-134939: Add the concurrent.interpreters Module (gh-135414)Eric Snow2025-06-121-2/+2
| | | | | | | | PEP-734 has been accepted (for 3.14). (FTR, I'm opposed to putting this under the concurrent package, but doing so is the SC condition under which the module can land in 3.14.) (cherry picked from commit 62143736b, AKA gh-133958)
* [3.14] gh-133891: Add missing error check to `SET_COUNT` macro in ↵Miss Islington (bot)2025-05-311-0/+3
| | | | | | | | `_testinternalcapi.c` (GH-133892) (#134988) gh-133891: Add missing error check to `SET_COUNT` macro in `_testinternalcapi.c` (GH-133892) (cherry picked from commit cebae977a63f32c3c03d14c040df3cea55b8f585) Co-authored-by: sobolevn <mail@sobolevn.me>
* [3.14] gh-132775: Support Fallbacks in _PyObject_GetXIData() (gh-134418)Miss Islington (bot)2025-05-211-1/+8
| | | | | | | | It now supports a "full" fallback to _PyFunction_GetXIData() and then `_PyPickle_GetXIData()`. There's also room for other fallback modes if that later makes sense. (cherry picked from commit 88f8102a8f, AKA gh-133482) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.14] gh-134144: Fix use-after-free in zapthreads() (GH-134145) (#134182)Miss Islington (bot)2025-05-181-4/+25
| | | | | | gh-134144: Fix use-after-free in zapthreads() (GH-134145) (cherry picked from commit f2de1e6861c27bd498f598efc01600450979b5f9) Co-authored-by: b-pass <b-pass@users.noreply.github.com>
* [3.14] gh-132775: Add _PyFunction_GetXIData() (gh-133955)Miss Islington (bot)2025-05-121-0/+5
| | | | | (cherry picked from commit 8cf4947b0f, AKA gh-133481) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.14] gh-132775: Add _PyCode_GetScriptXIData() (gh-133676)Miss Islington (bot)2025-05-081-0/+10
| | | | | | | | | | | This converts functions, code, str, bytes, bytearray, and memoryview objects to PyCodeObject, and ensure that the object looks like a script. That means no args, no return, and no closure. _PyCode_GetPureScriptXIData() takes it a step further and ensures there are no globals. We also add _PyObject_SupportedAsScript() to the internal C-API. (cherry picked from commit c81fa2b9cd1ed4d4ff5c13984d6582c27e5f2633, AKA gh-133480) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.14] gh-132775: Unrevert "Add _PyCode_VerifyStateless()" (gh-133625)Eric Snow2025-05-081-0/+43
| | | | | | | | This reverts commit 3c73cf5 (gh-133497), which itself reverted the original commit d270bb5 (gh-133221). We reverted the original change due to failing android tests. The checks in _PyCode_CheckNoInternalState() were too strict, so we've relaxed them.
* gh-132775: Revert "gh-132775: Add _PyCode_VerifyStateless() (gh-133221)" ↵Petr Viktorin2025-05-061-43/+0
| | | | (#133497)
* gh-132775: Add _PyCode_GetXIData() (gh-133475)Eric Snow2025-05-051-0/+5
|
* GH-133231: Add JIT utilities in sys._jit (GH-133233)Brandt Bucher2025-05-051-8/+0
|
* gh-132775: Add _PyCode_VerifyStateless() (gh-133221)Eric Snow2025-05-051-0/+44
| | | | | | | | "Stateless" code is a function or code object which does not rely on external state or internal state. It may rely on arguments and builtins, but not globals or a closure. I've left a comment in pycore_code.h that provides more detail. We also add _PyFunction_VerifyStateless(). The new functions will be used in several later changes that facilitate "sharing" functions and code objects between interpreters.
* gh-132775: Unrevert "Add _PyCode_GetVarCounts()" (gh-133265)Eric Snow2025-05-051-0/+168
| | | | | | This reverts commit 811edcf (gh-133232), which itself reverted the original commit 811edcf (gh-133128). We reverted the original change due to failing s390 builds (a big-endian architecture). It ended up that I had not accommodated op caches.
* Revert "gh-132775: Add _PyCode_GetVarCounts() (gh-133128)" (gh-133232)Eric Snow2025-05-011-168/+0
| | | | | The change broke the s390 builds, so I'm reverting it while I investigate. This reverts commit 94b4fcd806e7b692955173d309ea3b70a193ad96.
* gh-132775: Add _PyPickle_GetXIData() (gh-133107)Eric Snow2025-04-301-0/+5
| | | There's some extra complexity due to making sure we we get things right when handling functions and classes defined in the __main__ module. This is also reflected in the tests, including the addition of extra functions in test.support.import_helper.
* gh-132775: Add _PyCode_GetVarCounts() (gh-133128)Eric Snow2025-04-301-0/+168
| | | | | | | This helper is useful in a variety of ways, including in demonstrating how the different counts relate to one another. It will be used in a later change to help identify if a function is "stateless", meaning it doesn't have any free vars or globals. Note that a majority of this change is tests.
* gh-87859: Track Code Object Local Kinds For Arguments (gh-132980)Eric Snow2025-04-291-0/+32
| | | | | Doing this was always the intention. I was finally motivated to find the time to do it. See #87859 (comment).
* gh-132775: Add _PyCode_ReturnsOnlyNone() (gh-132981)Eric Snow2025-04-291-0/+13
| | | | | The function indicates whether or not the function has a return statement. This is used by a later change related treating some functions like scripts.
* gh-132775: Add _PyMarshal_GetXIData() (gh-133108)Eric Snow2025-04-281-0/+5
| | | Note that the bulk of this change is tests.
* gh-122320: Limit dict key versions used by test_opcache. (gh-132961)Neil Schemenauer2025-04-281-0/+13
| | | | | The `test_load_global_module()` test consumes a lot of dict key versions. Skip the test if we have consumed half of the available versions that can be used for the "load global" cache.
* gh-132775: Cleanup Related to crossinterp.c Before Further Changes (gh-132974)Eric Snow2025-04-281-20/+48
| | | This change consists of adding tests and moving code around, with some renaming thrown in.
* gh-132781: Cleanup Code Related to NotShareableError (gh-132782)Eric Snow2025-04-251-6/+2
| | | | | | | | | | The following are added to the internal C-API: * _PyErr_FormatV() * _PyErr_SetModuleNotFoundError() * _PyXIData_GetNotShareableErrorType() * _PyXIData_FormatNotShareableError() We also drop _PyXIData_lookup_context_t and _PyXIData_GetLookupContext().
* gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703)Sergey B Kirpichev2025-04-221-0/+3
|
* gh-111178: remove redundant casts for functions with correct signatures ↵Bénédikt Tran2025-04-011-1/+1
| | | | (#131673)
* GH-131498: Remove conditional stack effects (GH-131499)Mark Shannon2025-03-201-0/+1
| | | * Adds some missing #includes
* gh-131238: Remove includes from pycore_interp.h (#131495)Victor Stinner2025-03-201-3/+3
| | | Remove also now unused includes in C files.
* gh-131238: Remove more includes from pycore_interp.h (#131480)Victor Stinner2025-03-191-0/+2
|
* gh-130519: Fix crash in QSBR when destructor reenters QSBR (gh-130553)Sam Gross2025-02-261-0/+8
| | | | | | | The `free_work_item()` function in QSBR may call arbitrary code via Python object destructors, which may reenter the QSBR code. Reorder the processing of work items to be robust to reentrancy. Also fix the TODO for the out of memory situation.
* GH-130396: Use computed stack limits on linux (GH-130398)Mark Shannon2025-02-251-1/+4
| | | | | | | | | | | * Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not ↵Petr Viktorin2025-02-241-5/+1
| | | | | | | | | counters. (GH-130007)" for now (GH130413) Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now Unfortunatlely, the change broke some buildbots. This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
* GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)Mark Shannon2025-02-191-1/+5
| | | | | | | | | | | | * Implement C recursion protection with limit pointers * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* GH-129386: Use symbolic constants for specialization tests (GH-129415)Brandt Bucher2025-01-291-0/+15
|
* GH-126599: Remove the PyOptimizer API (GH-129194)Brandt Bucher2025-01-291-30/+3
|
* gh-128863: Deprecate _PyLong_Sign() function (#129176)Victor Stinner2025-01-231-4/+3
| | | Replace _PyLong_Sign() with PyLong_GetSign().
* GH-128939: Refactor JIT optimize structs (GH-128940)Mark Shannon2025-01-201-1/+1
|
* gh-129033: Remove _PyInterpreterState_SetConfig() function (#129048)Victor Stinner2025-01-201-38/+0
| | | | | | Remove _PyInterpreterState_GetConfigCopy() and _PyInterpreterState_SetConfig() private functions. PEP 741 "Python Configuration C API" added a better public C API: PyConfig_Get() and PyConfig_Set().
* GH-126599: Remove the "counter" optimizer/executor (GH-126853)Xuanteng Huang2025-01-161-13/+0
|
* gh-115999: Specialize `STORE_ATTR` in free-threaded builds. (gh-127838)Neil Schemenauer2024-12-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add `_PyDictKeys_StringLookupSplit` which does locking on dict keys and use in place of `_PyDictKeys_StringLookup`. * Change `_PyObject_TryGetInstanceAttribute` to use that function in the case of split keys. * Add `unicodekeys_lookup_split` helper which allows code sharing between `_Py_dict_lookup` and `_PyDictKeys_StringLookupSplit`. * Fix locking for `STORE_ATTR_INSTANCE_VALUE`. Create `_GUARD_TYPE_VERSION_AND_LOCK` uop so that object stays locked and `tp_version_tag` cannot change. * Pass `tp_version_tag` to `specialize_dict_access()`, ensuring the version we store on the cache is the correct one (in case of it changing during the specalize analysis). * Split `analyze_descriptor` into `analyze_descriptor_load` and `analyze_descriptor_store` since those don't share much logic. Add `descriptor_is_class` helper function. * In `specialize_dict_access`, double check `_PyObject_GetManagedDict()` in case we race and dict was materialized before the lock. * Avoid borrowed references in `_Py_Specialize_StoreAttr()`. * Use `specialize()` and `unspecialize()` helpers. * Add unit tests to ensure specializing happens as expected in FT builds. * Add unit tests to attempt to trigger data races (useful for running under TSAN). * Add `has_split_table` function to `_testinternalcapi`.
* GH-125174: Mark objects as statically allocated. (#127797)Mark Shannon2024-12-111-0/+10
| | | | | * Set a bit in the unused part of the refcount on 64 bit machines and the free-threaded build. * Use the top of the refcount range on 32 bit machines
* gh-127791: Fix, document, and test `PyUnstable_AtExit` (#127793)Peter Bierma2024-12-111-34/+0
|
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-12-021-0/+6
| | | | | | | | | | | | | collection (GH-127110) * Mark almost all reachable objects before doing collection phase * Add stats for objects marked * Visit new frames before each increment * Update docs * Clearer calculation of work to do.
* Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Hugo van Kemenade2024-11-191-7/+0
| | | | collection (GH-126502)" (#126983)
* GH-126795: Increase the JIT threshold from 16 to 4096 (GH-126816)Brandt Bucher2024-11-181-1/+1
|
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-11-181-0/+7
| | | | | | | | | | | | | | | | collection (GH-126502) * Mark almost all reachable objects before doing collection phase * Add stats for objects marked * Visit new frames before each increment * Remove lazy dict tracking * Update docs * Clearer calculation of work to do.
* gh-123619: Add an unstable C API function for enabling deferred reference ↵Peter Bierma2024-11-131-0/+9
| | | | | | counting (GH-123635) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-76785: Improved Subinterpreters Compatibility with 3.12 (2/2) (gh-126707)Eric Snow2024-11-121-1/+7
| | | | | | | | | These changes makes it easier to backport the _interpreters, _interpqueues, and _interpchannels modules to Python 3.12. This involves the following: * add the _PyXI_GET_STATE() and _PyXI_GET_GLOBAL_STATE() macros * add _PyXIData_lookup_context_t and _PyXIData_GetLookupContext() * add _Py_xi_state_init() and _Py_xi_state_fini()
* gh-76785: Minor Cleanup of "Cross-interpreter" Code (gh-126457)Eric Snow2024-11-071-12/+10
| | | | | | | | The primary objective here is to allow some later changes to be cleaner. Mostly this involves renaming things and moving a few things around. * CrossInterpreterData -> XIData * crossinterpdatafunc -> xidatafunc * split out pycore_crossinterp_data_registry.h * add _PyXIData_lookup_t
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-041-1/+45
| | | | | | | | | `BINARY_OP` (#123926) Each thread specializes a thread-local copy of the bytecode, created on the first RESUME, in free-threaded builds. All copies of the bytecode for a code object are stored in the co_tlbc array on the code object. Threads reserve a globally unique index identifying its copy of the bytecode in all co_tlbc arrays at thread creation and release the index at thread destruction. The first entry in every co_tlbc array always points to the "main" copy of the bytecode that is stored at the end of the code object. This ensures that no bytecode is copied for programs that do not use threads. Thread-local bytecode can be disabled at runtime by providing either -X tlbc=0 or PYTHON_TLBC=0. Disabling thread-local bytecode also disables specialization. Concurrent modifications to the bytecode made by the specializing interpreter and instrumentation use atomics, with specialization taking care not to overwrite an instruction that was instrumented concurrently.