76 Commits
Author SHA1 Message Date
8a09b511a0 [3.13] gh-141536: Fix a crash when running test_capi *after* test_code in the same process (GH-141537) (GH-143625)
(cherry picked from commit b2827de18f)

Co-authored-by: T. Wouters <[email protected]>
2026-01-12 20:07:34 +02:00
e285232c76 [3.13] gh-130851: Don't crash when deduping unusual code constants (GH-130853) (#130880)
The bytecode compiler only generates a few different types of constants,
like str, int, tuple, slices, etc. Users can construct code objects with
various unusual constants, including ones that are not hashable or not
even constant.

The free threaded build previously crashed with a fatal error when
confronted with these constants. Instead, treat distinct objects of
otherwise unhandled types as not equal for the purposes of deduplication.
(cherry picked from commit 2905690a91)

Co-authored-by: Sam Gross <[email protected]>
2025-03-05 15:22:57 -05:00
Sam GrossandGitHub 723d4d2fe8 gh-118527: Intern code consts in free-threaded build (#118667)
We already intern and immortalize most string constants. In the
free-threaded build, other constants can be a source of reference count
contention because they are shared by all threads running the same code
objects.
2024-05-06 20:12:39 -04:00
Sam GrossandGitHub 7ccacb220d gh-117783: Immortalize objects that use deferred reference counting (#118112)
Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.

This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
2024-04-29 14:36:02 -04:00
Sam GrossandGitHub df0f3a738f gh-117683: Fix test_free_different_thread failures with GIL disabled (#117685) 2024-04-16 11:55:56 -04:00
Sam GrossandGitHub 4ad8f090cc gh-117376: Partial implementation of deferred reference counting (#117696)
This marks objects as using deferred refrence counting using the
`ob_gc_bits` field in the free-threaded build and collects those objects
during GC.
2024-04-12 17:36:20 +00:00
Erlend E. AaslandandGitHub ea94b3b149 gh-116303: Skip test module dependent tests if test modules are unavailable (#117341) 2024-04-03 15:11:36 +02:00
Sam GrossandGitHub a3af3cb4f4 gh-110481: Implement inter-thread queue for biased reference counting (#114824)
Biased reference counting maintains two refcount fields in each object:
`ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two
fields. In some cases, when refcounting operations are split across threads,
the ob_ref_shared field can be negative (although the total refcount must be
at least zero). In this case, the thread that decremented the refcount
requests that the owning thread give up ownership and merge the refcount
fields.
2024-02-09 17:08:32 -05:00
Irit KatrielandGitHub 428c9812cb gh-112962: in dis module, put cache information in the Instruction instead of creating fake Instructions to represent it (#113016) 2023-12-13 12:00:21 +00:00
Tian GaoandGitHub 057bc72490 gh-109052: Use the base opcode when comparing code objects (gh-109107) 2023-09-09 10:24:49 +09:00
Serhiy StorchakaandGitHub 6f3c138dfa gh-108751: Add copy.replace() function (GH-108752)
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.
2023-09-06 23:55:42 +03:00
Guido van RossumandGitHub 61c7249759 gh-106581: Project through calls (#108067)
This finishes the work begun in gh-107760. When, while projecting a superblock, we encounter a call to a short, simple function, the superblock will now enter the function using `_PUSH_FRAME`, continue through it, and leave it using `_POP_FRAME`, and then continue through the original code. Multiple frame pushes and pops are even possible. It is also possible to stop appending to the superblock in the middle of a called function, when running out of space or encountering an unsupported bytecode.
2023-08-17 11:29:58 -07:00
Rodolfo M. PereiraGitHubblurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Gregory P. Smith
8291ae31dd GH-103805: Lib test f541 linting issue fix (#103812)
This PR makes some minor linting adjustments to the Lib/test module
caught by [ruff](https://github.com/charliermarsh/ruff). The adjustments
are all related to the `F541 f-string without any placeholders` issue.

Issue: https://github.com/python/cpython/issues/103805

<!-- gh-issue-number: gh-103805 -->
* Issue: gh-103805
<!-- /gh-issue-number -->

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <[email protected]>
2023-04-24 23:24:49 +00:00
Mark ShannonandGitHub 411b169281 GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython (GH-103083)
* The majority of the monitoring code is in instrumentation.c

* The new instrumentation bytecodes are in bytecodes.c

* legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
2023-04-12 12:04:55 +01:00
2a721258a1 gh-101865: Deprecate co_lnotab from code objects as per PEP 626 (#101866)
Co-authored-by: Oleg Iarygin <[email protected]>
2023-04-03 17:35:04 +02:00
Petr ViktorinandGitHub 6b2d7c0ddb gh-101101: Unstable C API tier (PEP 689) (GH-101102) 2023-02-28 09:31:01 +01:00
penguin_wwyandGitHub 753fc8a5d6 gh-101632: Add the new RETURN_CONST opcode (#101633) 2023-02-07 22:32:21 +00:00
Brandt BucherandGitHub f07daaf4f7 GH-100117: Make co_lines more efficient (GH-100447) 2023-01-10 10:56:53 +00:00
Dennis SweeneyandGitHub a98d9ea56e gh-94155: Reduce hash collisions for code objects (#100183)
* Uses a better hashing algorithm to get better dispersion and remove commutativity.

* Incorporates `co_firstlineno`, `Py_SIZE(co)`, and bytecode instructions.

* This is now the entire set of criteria used in `code_richcompare`, except for `_PyCode_ConstantKey` (which would incorporate the types of `co_consts` rather than just their values).
2022-12-23 13:15:47 -05:00
Irit KatrielandGitHub f3e97c90ed gh-100077: make test_code.test_invalid_bytecode more robust and maintainable (#100078) 2022-12-07 18:09:05 +00:00
Brandt BucherandGitHub 0ff8fd6583 GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845) 2022-10-04 17:30:03 -07:00
serge-sans-pailleandGitHub fc05107af9 gh-96711: Enhance SystemError message upon Invalid opcode (#96712)
Raise verbose SystemError instead of printing debug information
upon Invalid opcode.

Fix #96711
2022-09-20 12:00:34 +02:00
Brandt BucherandGitHub c7e5bbaee8 GH-95150: Use position and exception tables for code hashing and equality (GH-95509) 2022-08-01 11:02:56 -07:00
Michael DroettboomandGitHub 4b5360c7d5 Revert "gh-94816: Improve coverage of decode_linetable (GH-94853)" (GH-94982)
This reverts commit 20b9d2a658.
2022-07-18 13:08:31 -07:00
Michael DroettboomandGitHub 20b9d2a658 gh-94816: Improve coverage of decode_linetable (GH-94853)
This makes calls to co_lnotab to exercise this code, as well
as generating synthetically large code to exercise the corner
cases where line numbers need multiple bytes.

Automerge-Triggered-By: GH:brandtbucher
2022-07-14 14:34:50 -07:00
324d01944d gh-94485: Set line number of module's RESUME instruction to 0, as specified by PEP 626 (GH-94552)
Co-authored-by: Mark Shannon <[email protected]>
2022-07-05 14:38:44 +02:00
Christian HeimesandGitHub 8625802d85 gh-84461: Fix ctypes and test_ctypes on Emscripten (#94142)
- c_longlong and c_longdouble need experimental WASM bigint.
- Skip tests that need threading
- Define ``CTYPES_MAX_ARGCOUNT`` for Emscripten. libffi-emscripten 2022-06-23 supports up to 1000 args.
2022-06-24 12:40:43 +02:00
Mark ShannonandGitHub 2bf74753c1 GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673) 2022-06-14 11:08:12 +01:00
Mark ShannonandGitHub d44815cabc GH-88116: Document that PyCodeNew is dangerous, and make PyCode_NewEmpty less dangerous. (GH-91790) 2022-04-21 19:08:36 +01:00
Mark ShannonandGitHub 944fffee89 GH-88116: Use a compact format to represent end line and column offsets. (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
2022-04-21 16:10:37 +01:00
Brandt BucherandGitHub 0f41aac109 bpo-46841: Use *inline* caching for BINARY_OP (GH-31543) 2022-02-25 12:11:34 +00:00
Mark ShannonandGitHub e028ae99ec bpo-45923: Handle call events in bytecode (GH-30364)
* Add a RESUME instruction to handle "call" events.
2022-01-06 13:09:25 +00:00
Irit KatrielandGitHub a94461d718 bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE (GH-30302)
* bpo-46202: remove opcode POP_EXCEPT_AND_RERAISE

* do not assume that an exception group is truthy
2022-01-04 10:37:12 +00:00
Mark ShannonandGitHub 135cabd328 bpo-44525: Copy free variables in bytecode to allow calls to inner functions to be specialized (GH-29595)
* Make internal APIs that take PyFrameConstructor take a PyFunctionObject instead.

* Add reference to function to frame, borrow references to builtins and globals.

* Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
2021-11-23 09:53:24 +00:00
Serhiy StorchakaandGitHub a856364cc9 bpo-45229: Use doctest.DocTestSuite instead of run_doctest (GH-28468)
Alo use load_tests() for adding tests.
2021-09-20 11:36:57 +03:00
Serhiy StorchakaandGitHub 2a8127cafe bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005) 2021-08-29 14:04:40 +03:00
andrei kulakovandGitHub 27b761a11a bpo-44980: fix test_constructor to return None value (GH-27898) 2021-08-23 20:50:46 +02:00
Guido van RossumandGitHub 62bd97303e Fix a SystemError in code.replace() (#27771)
While the comment said 'We don't bother resizing localspluskinds',
this would cause .replace() to crash when it happened.
(Also types.CodeType(), but testing that is tedious, and this tests all
code paths.)
2021-08-16 11:34:23 -07:00
Ammar AskarandGitHub 052930f241 Remove __cleanenv from PEP-657 tests (GH-27060) 2021-07-07 22:47:50 +01:00
4823d9a512 bpo-43950: Add option to opt-out of PEP-657 (GH-27023)
Co-authored-by: Pablo Galindo <[email protected]>
Co-authored-by: Batuhan Taskaya <[email protected]>
Co-authored-by: Ammar Askar <[email protected]>
2021-07-07 20:07:12 +01:00
Gabriele N. TornettaandGitHub 2f180ce2cb bpo-44530: Add co_qualname field to PyCodeObject (GH-26941) 2021-07-07 12:21:51 +01:00
Batuhan TaskayaandGitHub 44f91fc802 bpo-43950: use 0-indexed column offsets for bytecode positions (GH-27011) 2021-07-04 11:02:16 -07:00
98eee94421 bpo-43950: Add code.co_positions (PEP 657) (GH-26955)
This PR is part of PEP 657 and augments the compiler to emit ending
line numbers as well as starting and ending columns from the AST
into compiled code objects. This allows bytecodes to be correlated
to the exact source code ranges that generated them.

This information is made available through the following public APIs:

* The `co_positions` method on code objects.
* The C API function `PyCode_Addr2Location`.

Co-authored-by: Batuhan Taskaya <[email protected]>
Co-authored-by: Ammar Askar <[email protected]>
2021-07-02 15:10:11 +01:00
Guido van RossumandGitHub 769d7d0c66 bpo-43693 Get rid of CO_NOFREE -- it's unused (GH-26839)
All uses of this flag are either setting it
or in doc or tests for it. So we should be
able to get rid of it completely.
2021-06-23 09:51:44 -07:00
Eric SnowandGitHub 6cc800d363 bpo-43693: Clean up the PyCodeObject fields. (GH-26364)
* Move up the comment about fields using in hashing/comparision.

* Group the fields more clearly.

* Add co_ncellvars and co_nfreevars.

* Raise ValueError if nlocals != len(varnames), rather than aborting.
2021-05-26 20:15:40 +01:00
Mark ShannonandGitHub adcd220556 bpo-40222: "Zero cost" exception handling (GH-25729)
"Zero cost" exception handling.

* Uses a lookup table to determine how to handle exceptions.
* Removes SETUP_FINALLY and POP_TOP block instructions, eliminating (most of) the runtime overhead of try statements.
* Reduces the size of the frame object by about 60%.
2021-05-07 15:19:19 +01:00
Mark ShannonandGitHub c76da79b37 bpo-42739: Don't use sentinels to mark end of line table. (GH-25657)
* Add length parameter to PyLineTable_InitAddressRange and doen't use sentinel values at end of table. Makes the line number table more robust.

* Update PyCodeAddressRange to match PEP 626.
2021-04-29 13:12:51 +01:00
Mark ShannonandGitHub 877df851c3 bpo-42246: Partial implementation of PEP 626. (GH-23113)
* Implement new line number table format, as defined in PEP 626.
2020-11-12 09:43:29 +00:00
Victor StinnerandGitHub b1e11c31c5 bpo-40443: Remove unused imports in tests (GH-19804) 2020-04-30 02:21:30 +02:00
Mark ShannonandGitHub e7c9f4aae1 Cleanup exit code for interpreter. (GH-17756) 2020-01-13 12:51:26 +00:00