summaryrefslogtreecommitdiffstats
path: root/Include/internal
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-106905: Use separate structs to track recursion depth in each ↵Serhiy Storchaka2023-12-251-2/+2
| | | | | | | | | PyAST_mod2obj call. (GH-113035) (GH-113472) (GH-113476) (cherry picked from commit 48c49739f5502fc7aa82f247ab2e4d7b55bdca62) (cherry picked from commit d58a5f453f59f44ccf09b1a9b11a0b879ac6f35b) Co-authored-by: Yilei Yang <yileiyang@google.com> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* [3.11] gh-108987: Fix _thread.start_new_thread() race condition (#109135) ↵Victor Stinner2023-09-111-0/+2
| | | | | | | | | | | | | | | | | | | (#109272) gh-108987: Fix _thread.start_new_thread() race condition (#109135) 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(). (cherry picked from commit 517cd82ea7d01b344804413ef05610934a43a241)
* [3.11] gh-104690: thread_run() checks for tstate dangling pointer (#109056) ↵Victor Stinner2023-09-081-0/+4
| | | | | | | | | | | | | | (#109134) gh-104690: thread_run() checks for tstate dangling pointer (#109056) 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. (cherry picked from commit f63d37877ad166041489a968233b57540f8456e8)
* [3.11] gh-106242: Fix path truncation in os.path.normpath (GH-106816) (#107982)Steve Dower2023-08-151-1/+2
| | | Co-authored-by: Finn Womack <flan313@gmail.com>
* [3.11] gh-104018: remove unused format "z" handling in string formatfloat() ↵Miss Islington (bot)2023-05-071-2/+0
| | | | | | | | | | (GH-104107) (#104260) gh-104018: remove unused format "z" handling in string formatfloat() (GH-104107) This is a cleanup overlooked in PR GH-104033. (cherry picked from commit 69621d1b09c996e43a1e13d2fa4c317d3dd4d738) Co-authored-by: John Belmonte <john@neggie.net>
* [3.11] gh-99110: Initialize frame->previous in init_frame to fix ↵Bill Fisher2022-12-241-1/+4
| | | | | | | segmentation fault (GH-100182) (#100478) (cherry picked from commit 88d565f32a709140664444c6dea20ecd35a10e94) Co-authored-by: Bill Fisher <william.w.fisher@gmail.com>
* [3.11] GH-96569: Avoid undefined behavior (#96616)Mark Shannon2022-09-081-8/+16
| | | Co-authored-by: Michael Droettboom <mdboom@gmail.com>
* gh-95778: Correctly pre-check for int-to-str conversion (GH-96537)Miss Islington (bot)2022-09-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Converting a large enough `int` to a decimal string raises `ValueError` as expected. However, the raise comes _after_ the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. Oops! =) The quick fix: essentially we catch _most_ values that exceed the threshold up front. Those that slip through will still be on the small side (read: sufficiently fast), and will get caught by the existing check so that the limit remains exact. The justification for the current check. The C code check is: ```c max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10 ``` In GitHub markdown math-speak, writing $M$ for `max_str_digits`, $L$ for `PyLong_SHIFT` and $s$ for `size_a`, that check is: $$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$ From this it follows that $$\frac{M}{3L} < \frac{s-1}{10}$$ hence that $$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$ So $$2^{L(s-1)} > 10^M.$$ But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything _below_ the intended limit in the check. <!-- gh-issue-number: gh-95778 --> * Issue: gh-95778 <!-- /gh-issue-number --> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org> (cherry picked from commit b126196838bbaf5f4d35120e0e6bcde435b0b480) Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* [3.11] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96500)Gregory P. Smith2022-09-023-0/+39
| | | | | | | | | | | | | | | | | | Integer to and from text conversions via CPython's bignum `int` type is not safe against denial of service attacks due to malicious input. Very large input strings with hundred thousands of digits can consume several CPU seconds. This PR comes fresh from a pile of work done in our private PSRT security response team repo. This backports https://github.com/python/cpython/pull/96499 aka 511ca9452033ef95bc7d7fc404b8161068226002 Signed-off-by: Christian Heimes [Red Hat] <christian@python.org> Tons-of-polishing-up-by: Gregory P. Smith [Google] <greg@krypto.org> Reviews via the private PSRT repo via many others (see the NEWS entry in the PR). <!-- gh-issue-number: gh-95778 --> * Issue: gh-95778 <!-- /gh-issue-number --> I wrote up [a one pager for the release managers](https://docs.google.com/document/d/1KjuF_aXlzPUxTK4BMgezGJ2Pn7uevfX7g0_mvgHlL7Y/edit#).
* gh-46845: clean up unused DK_IXSIZE (GH-96405)Miss Islington (bot)2022-08-301-9/+0
| | | | | (cherry picked from commit d21d2f0793ce32d72759d5cfc11622d13e3e6b81) Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
* Fix typo in internal/pycore_atomic.h (GH-95939)Miss Islington (bot)2022-08-131-1/+1
| | | | | (cherry picked from commit 8281cbddc6f0fbc94f0c21cacfac79a2d4057a4b) Co-authored-by: fluesvamp <105884371+fluesvamp@users.noreply.github.com>
* GH-90081: Run python tracers at full speed (GH-95328) (#95363)Miss Islington (bot)2022-07-291-2/+3
| | | | | | | (cherry picked from commit b8b2990fb3218cffedfe7bc92e9e7ae2275b3c98) Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Mark Shannon <mark@hotpy.org>
* [3.11] gh-95185: Check recursion depth in the AST constructor (GH-95186) ↵Miss Islington (bot)2022-07-261-0/+2
| | | | | | | | (GH-95208) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit 00474472944944b346d8409cfded84bb299f601a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.11] GH-94739: Backport GH-94958 to 3.11 (#94965)Mark Shannon2022-07-251-0/+13
|
* [3.11] GH-95113: Don't use EXTENDED_ARG_QUICK in unquickened code (GH-95121) ↵Brandt Bucher2022-07-221-186/+0
| | | | | (GH-95143) (cherry picked from commit e402b26b7fb953a2f0c17a0044bb6d6cbd726e54)
* [3.11] GH-94262: Don't create frame objects for frames that aren't yet ↵Miss Islington (bot)2022-07-041-0/+17
| | | | | complete. (GH-94371) (#94482) Co-authored-by: Mark Shannon <mark@hotpy.org>
* [3.11] GH-93354: Use exponential backoff to avoid excessive specialization ↵Mark Shannon2022-06-301-3/+44
| | | | | | attempts (GH-93355) (GH-93379) Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* [3.11] gh-90473: Reduce recursion limit on WASI even further (GH-94333) ↵Christian Heimes2022-06-271-3/+4
| | | | | (GH-94334) Co-authored-by: Christian Heimes <christian@python.org>
* [3.11] GH-93516: Backport GH-93769: Speedup line number checks when tracing ↵Mark Shannon2022-06-221-0/+29
| | | | | (GH-94127) Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* [3.11] gh-91162: Support splitting of unpacked arbitrary-length tuple over ↵Miss Islington (bot)2022-06-142-0/+2
| | | | | | | | | | | | TypeVar and TypeVarTuple parameters (alt) (GH-93412) (GH-93746) For example: A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]] A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int] (cherry picked from commit 3473817106c23eca7341c931453da0341c367e1d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-91162: Fix substitution of unpacked tuples in generic aliases ↵Miss Islington (bot)2022-06-012-2/+4
| | | | | | | | | | | | | (GH-92335) (#92484) * gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335) (cherry picked from commit 9d25db9db1617f012d7dba118b5b8f2b9e25e116) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Regenerate ABI file Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* [3.11] bpo-40514: Drop EXPERIMENTAL_ISOLATED_SUBINTERPRETERS (gh-93185) ↵Eric Snow2022-05-284-21/+0
| | | | | | | | | | | | | (GH-93306) (cherry picked from commit caa279d6fd5f151e57f891cd4f6ba51b532501c6) This was added for bpo-40514 (gh-84694) to test out a per-interpreter GIL. However, it has since proven unnecessary to keep the experiment in the repo. (It can be done as a branch in a fork like normal.) So here we are removing: * the configure option * the macro * the code enabled by the macro Automerge-Triggered-By: GH:ericsnowcurrently
* gh-93065: Fix HAMT to iterate correctly over 7-level deep trees (GH-93066) ↵Miss Islington (bot)2022-05-241-1/+13
| | | | | | | | | | | | (GH-93145) Also while there, clarify a few things about why we reduce the hash to 32 bits. Co-authored-by: Eli Libman <eli@hyro.ai> Co-authored-by: Yury Selivanov <yury@edgedb.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit c1f5c903a7e4ed27190488f4e33b00d3c3d952e5)
* gh-90473: Decrease recursion limit and skip tests on WASI (GH-92803)Miss Islington (bot)2022-05-191-1/+7
| | | | | (cherry picked from commit 137fd3d88aa46669f5717734e823f4c594ab2843) Co-authored-by: Christian Heimes <christian@python.org>
* gh-87390: Fix starred tuple equality and pickling (GH-92337)Serhiy Storchaka2022-05-052-0/+2
|
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-041-12/+8
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* Add more stats for freelist use and allocations. (GH-92211)Mark Shannon2022-05-031-0/+8
|
* gh-92031: Deoptimize Static Code at Finalization (GH-92039)Dennis Sweeney2022-05-031-0/+186
|
* bpo-43224: Implement substitution of unpacked TypeVarTuple in C (GH-31828)Serhiy Storchaka2022-04-302-0/+2
| | | | Co-authored-by: Matthew Rahtz <mrahtz@gmail.com>
* gh-91603: Speed up isinstance/issubclass on union types (GH-91631)Yurii Karabas2022-04-281-0/+1
| | | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-89479: Export _Py_GetSpecializationStats() internal function (#92011)Victor Stinner2022-04-281-2/+3
| | | | | | When Python is built with "./configure --enable-pystats" (if the Py_STATS macro is defined), the _Py_GetSpecializationStats() function must be exported, since it's used by the _opcode extension which is built as a shared library.
* gh-91869: Fix tracing of specialized instructions with extended args (GH-91945)Dennis Sweeney2022-04-281-18/+18
|
* gh-91719: Add pycore_opcode.h internal header file (#91906)Victor Stinner2022-04-251-0/+581
| | | | | | | | | | | Move the following API from Include/opcode.h (public C API) to a new Include/internal/pycore_opcode.h header file (internal C API): * EXTRA_CASES * _PyOpcode_Caches * _PyOpcode_Deopt * _PyOpcode_Jump * _PyOpcode_OpName * _PyOpcode_RelativeJump
* gh-64783: Fix signal.NSIG value on FreeBSD (#91929)Victor Stinner2022-04-252-16/+35
| | | | | | | | | Fix signal.NSIG value on FreeBSD to accept signal numbers greater than 32, like signal.SIGRTMIN and signal.SIGRTMAX. * Add Py_NSIG constant. * Add pycore_signal.h internal header file. * _Py_Sigset_Converter() now includes the range of valid signals in the error message.
* gh-91768: C API no longer use "const PyObject*" type (#91769)Victor Stinner2022-04-211-2/+2
| | | | | | | | | | | | | Py_REFCNT(), Py_TYPE(), Py_SIZE() and Py_IS_TYPE() functions argument type is now "PyObject*", rather than "const PyObject*". * Replace also "const PyObject*" with "PyObject*" in functions: * _Py_strhex_impl() * _Py_strhex_with_sep() * _Py_strhex_bytes_with_sep() * Remove _PyObject_CAST_CONST() and _PyVarObject_CAST_CONST() macros. * Py_IS_TYPE() can now use Py_TYPE() in its implementation.
* GH-88116: Use a compact format to represent end line and column offsets. ↵Mark Shannon2022-04-211-14/+35
| | | | | | | | | | | | (GH-91666) * Stores all location info in linetable to conform to PEP 626. * Remove column table from code objects. * Remove end-line table from code objects. * Document new location table format
* gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)Dennis Sweeney2022-04-194-8/+39
|
* gh-91576: Speed up iteration of strings (#91574)Kumar Aditya2022-04-181-0/+1
|
* gh-78607: Replace __ltrace__ with __lltrace__ (GH-91619)Dennis Sweeney2022-04-162-2/+2
|
* gh-89770: Implement PEP-678 - Exception notes (GH-31317)Irit Katriel2022-04-162-2/+2
|
* GH-89480: Document motivation, design and implementation of 3.11 frame ↵Mark Shannon2022-04-111-0/+8
| | | | stack. (GH-32304)
* bpo-45995: add "z" format specifer to coerce negative 0 to zero (GH-30049)John Belmonte2022-04-111-0/+2
| | | | | | | | Add "z" format specifier to coerce negative 0 to zero. See https://github.com/python/cpython/issues/90153 (originally https://bugs.python.org/issue45995) for discussion. This covers `str.format()` and f-strings. Old-style string interpolation is not supported. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-47177: Replace `f_lasti` with `prev_instr` (GH-32208)Brandt Bucher2022-04-071-7/+10
|
* Revert "bpo-46850: Move _PyEval_EvalFrameDefault() to internal C API ↵Victor Stinner2022-04-063-21/+2
| | | | | | | | | | | (GH-32052)" (GH-32343) * Revert "bpo-46850: Move _PyInterpreterState_SetEvalFrameFunc() to internal C API (GH-32054)" This reverts commit f877b40e3f7e0d97878884d80fbec879a85ab7e8. * Revert "bpo-46850: Move _PyEval_EvalFrameDefault() to internal C API (GH-32052)" This reverts commit b9a5522dd952125a99ff554f01f311cae25f5a91.
* Revert "bpo-44800: Document internal frame naming conventions (GH-32281)" ↵Mark Shannon2022-04-041-69/+0
| | | | | (#32301) This reverts commit 124227c95f310d2ecd4b567271ab1919fc7000cb.
* bpo-47000: Make `io.text_encoding()` respects UTF-8 mode (GH-32003)Inada Naoki2022-04-042-0/+2
| | | Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* bpo-47176: Interrupt handling for wasm32-emscripten builds without pthreads ↵Hood Chatham2022-04-031-0/+25
| | | | | | (GH-32209) Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Brett Cannon <brett@python.org>
* bpo-44800: Document internal frame naming conventions (GH-32281)Nick Coghlan2022-04-031-0/+69
| | | | | | | | | | The fact interpreter frames were split out from full frame objects rather than always being part of the eval loop implementation means that it's tricky to infer the expected naming conventions simply from looking at the code. Documenting the de facto conventions in pycore_frame.h means future readers of the code will have a clear explanation of the rationale for those conventions (i.e. minimising non-functional code churn).
* bpo-47009: Streamline list.append for the common case (GH-31864)Dennis Sweeney2022-04-011-0/+18
|
* bpo-46850: Move _PyInterpreterState_SetEvalFrameFunc() to internal C API ↵Victor Stinner2022-04-012-2/+16
| | | | | | | | | | | (GH-32054) Move the private _PyFrameEvalFunction type, and private _PyInterpreterState_GetEvalFrameFunc() and _PyInterpreterState_SetEvalFrameFunc() functions to the internal C API. The _PyFrameEvalFunction callback function type now uses the _PyInterpreterFrame type which is part of the internal C API. Update the _PyFrameEvalFunction documentation.