Commit Graph
237 Commits
Author SHA1 Message Date
2b0cccec39 [3.13] gh-139927: Fix test_embed on OpenIndiana (GH-142514) (#142521)
gh-139927: Fix test_embed on OpenIndiana (GH-142514)

Avoid swprintf() function in Programs/_testembed.c since it doesn't
work as expected on OpenIndiana.
(cherry picked from commit c76cfe8d89)

Co-authored-by: Victor Stinner <[email protected]>
2025-12-10 15:54:13 +00:00
Itamar OrenandGitHub 385688d4b4 [3.13] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) (#141987)
gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605)

(cherry picked from commit 27f62eb711)
2025-11-28 23:31:11 -08:00
050b9dda04 [3.13] gh-137093: Fix race condition in test_embed.test_bpo20891 (GH-137094) (GH-140524) (#140527)
[3.14] gh-137093: Fix race condition in `test_embed.test_bpo20891` (GH-137094) (GH-140524)

Use a `PyEvent` instead of a lock to fix a race on the free-threaded build.
(cherry picked from commit 9b451fb457)
(cherry picked from commit 6efd78d7ab)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>
2025-10-24 13:47:26 +05:30
6260b6ae24 [3.13] gh-139146: Check calloc() results in _testembed.c::test_pre_initialization_sys_options (GH-139147) (#139414)
gh-139146: Check `calloc()` results in `_testembed.c::test_pre_initialization_sys_options` (GH-139147)
(cherry picked from commit 9c6a1f847b)


Reported by: Dmitrii Chuprov <[email protected]>

Signed-off-by: Denis Sergeev <[email protected]>
Co-authored-by: Denis Sergeev <[email protected]>
2025-09-29 11:03:01 +00:00
64391363ed [3.13] bpo-34206: Improve docs and test coverage for pre-init functions (GH-8023) (#125092)
- move the Py_Main documentation from the very high level API section
  to the initialization and finalization section
- make it clear that it encapsulates a full Py_Initialize/Finalize
  cycle of its own
- point out that exactly which settings will be read and applied
  correctly when Py_Main is called after a separate runtime
  initialization call is version dependent
- be explicit that Py_IsInitialized can be called prior to
  initialization
- actually test that Py_IsInitialized can be called prior to
  initialization
- flush stdout in the embedding tests that run code so it appears
  in the expected order when running with "-vv"
- make "-vv" on the subinterpreter embedding tests less spammy

---------

(cherry picked from commit 7c4b6a68f2)

Co-authored-by: Carol Willing <[email protected]>
2024-10-08 09:30:06 +00:00
8b9bd43d40 [3.13] gh-123919: Fix null handling in _freeze_module.c (GH-123920) (#123948)
gh-123919: Fix null handling in `_freeze_module.c` (GH-123920)
(cherry picked from commit c8d1dbef5b)

Co-authored-by: sobolevn <[email protected]>
2024-09-29 18:22:15 -07:00
9bae6815a3 [3.13] gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164) (#124250)
gh-124160: Pass main_tstate to update_global_state_for_extension() (GH-124164)
(cherry picked from commit 7331d0f70b)

Co-authored-by: luk1337 <[email protected]>
2024-09-23 16:16:41 -07:00
ff58c3cb48 [3.13] gh-123022: Fix crash with Py_Initialize in background thread (GH-123052) (#123114)
Check that the current default heap is initialized in
`_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`.

The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an
initialized default heap. This is true for our main thread, but not for
background threads. The problematic code path is usually called during
initialization (i.e., `Py_Initialize`), but it may also be called if the
program allocates large amounts of memory in total.

The crash only affected the free-threaded build.
(cherry picked from commit d061ffea7b)

Co-authored-by: Sam Gross <[email protected]>
2024-08-17 20:38:02 +00:00
Eric SnowandGitHub 10cf7d6d00 [3.13] gh-117482: Fix the Slot Wrapper Inheritance Tests (gh-122249)
The tests were only checking cases where the slot wrapper was present in the initial case.  They were missing when the slot wrapper was added in the additional initializations.  This fixes that.

(cherry-picked from commit 490e0ad83a, AKA gh-122248)
2024-07-29 10:25:02 -06:00
39825a7533 [3.13] gh-93691: fix too broad source locations of for statement iterators (GH-120330) (#120399)
gh-93691: fix too broad source locations of for statement iterators (GH-120330)
(cherry picked from commit 97b69db167)

Co-authored-by: Irit Katriel <[email protected]>
2024-06-12 12:18:43 +00:00
Sam GrossandGitHub 2ba2c142a6 gh-118527: Intern code name and filename on default build (#118576)
Interned and non-interned strings are treated differently by `marshal`,
so be consistent between the default and free-threaded build.
2024-05-06 17:24:14 -04:00
Guido van RossumandGitHub 4c7bfdff90 Remove more remnants of deepfreeze (#118159) 2024-04-22 12:17:57 -07:00
Victor StinnerandGitHub 340a02b590 gh-117987: Restore several functions removed in Python 3.13 alpha 1 (GH-117993)
Restore these functions removed in Python 3.13 alpha 1:

* Py_SetPythonHome()
* Py_SetProgramName()
* PySys_SetArgvEx()
* PySys_SetArgv()
2024-04-18 15:20:38 +02:00
Mark ShannonandGitHub 981d172f7f GH-112354: END_FOR instruction to only pop one value. (GH-114247)
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
2024-01-24 15:10:17 +00:00
Sam GrossandGitHub fdee7b7b3e gh-112532: Require mimalloc in --disable-gil builds (gh-112883) 2023-12-12 09:04:48 +09:00
Irit KatrielandGitHub d49aba5a7a gh-111354: Simplify _PyGen_yf by moving some of its work to the compiler and frame state (#111648) 2023-11-03 10:01:36 +00:00
Irit KatrielandGitHub 52cc4af6ae gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 (#111459) 2023-11-02 10:18:43 +00:00
Donghee NaGitHubVictor StinnerGregory P. Smith [Google LLC] <[email protected]>
0362cbf908 gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)
---------

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Gregory P. Smith [Google LLC] <[email protected]>
2023-10-10 19:00:09 +09:00
Victor StinnerandGitHub bb057b3370 gh-85283: Add PySys_AuditTuple() function (#108965)
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().
2023-10-05 21:59:35 +00:00
Brandt BucherandGitHub 22e65eecaa GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300) 2023-09-13 10:25:45 -07:00
Irit KatrielandGitHub 8b55adfa8f gh-109256: allocate opcode IDs for internal opcodes in their own range (#109269) 2023-09-12 10:36:17 +00:00
Mark ShannonandGitHub 15d4c9fabc GH-108716: Turn off deep-freezing of code objects. (GH-108722) 2023-09-08 10:34:40 +01:00
Mark ShannonandGitHub 0858328ca2 GH-108614: Add RESUME_CHECK instruction (GH-108630) 2023-09-07 14:39:03 +01:00
a0773b89df gh-108753: Enhance pystats (#108754)
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 <[email protected]>
2023-09-06 15:54:59 +00:00
Victor StinnerandGitHub 594b00057e gh-108765: Python.h no longer includes <unistd.h> (#108783) 2023-09-02 16:50:18 +02:00
Irit KatrielandGitHub 665a4391e1 gh-105481: generate op IDs from bytecode.c instead of hard coding them in opcode.py (#107971) 2023-08-16 22:25:18 +00:00
Victor StinnerandGitHub e35c722d22 gh-106659: Fix test_embed.test_forced_io_encoding() on Windows (#108010)
Use config.legacy_windows_stdio=1 to avoid _io._WindowsConsoleIO.
2023-08-16 11:56:56 +00:00
Brandt BucherandGitHub a9caf9cf90 GH-105848: Simplify the arrangement of CALL's stack (GH-107788) 2023-08-09 18:19:39 +00:00
Mark ShannonandGitHub 1d857da7f0 GH-77273: Better bytecodes for f-strings (GH-6132) 2023-06-14 16:15:08 +01:00
Mark ShannonandGitHub 4bfa01b9d9 GH-104584: Plugin optimizer API (GH-105100) 2023-06-02 11:46:18 +01:00
Victor StinnerandGitHub 424049cc11 gh-105145: Remove old functions to config Python init (#105154)
Remove the following old functions to configure the Python
initialization, deprecated in Python 3.11:

* PySys_AddWarnOptionUnicode()
* PySys_AddWarnOption()
* PySys_AddXOption()
* PySys_HasWarnOptions()
* PySys_SetArgvEx()
* PySys_SetArgv()
* PySys_SetPath()
* Py_SetPath()
* Py_SetProgramName()
* Py_SetPythonHome()
* Py_SetStandardStreamEncoding()
* _Py_SetProgramFullPath()

Most of these functions are kept in the stable ABI, except:

* Py_SetStandardStreamEncoding()
* _Py_SetProgramFullPath()

Update Doc/extending/embedding.rst and Doc/extending/extending.rst to
use the new PyConfig API.

_testembed.c:

* check_stdio_details() now sets stdio_encoding and stdio_errors
  of PyConfig.
* Add definitions of functions removed from the API but kept in the
  stable ABI.
* test_init_from_config() and test_init_read_set() now use
  PyConfig_SetString() instead of PyConfig_SetBytesString().

Remove _Py_ClearStandardStreamEncoding() internal function.
2023-06-01 09:14:02 +02:00
Eddie ElizondoandGitHub ea2c001650 gh-84436: Implement Immortal Objects (gh-19474)
This is the implementation of PEP683

Motivation:

The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime.

Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
2023-04-22 13:39:37 -06:00
1ef61cf71a gh-102856: Initial implementation of PEP 701 (#102855)
Co-authored-by: Lysandros Nikolaou <[email protected]>
Co-authored-by: Batuhan Taskaya <[email protected]>
Co-authored-by: Marta Gómez Macías <[email protected]>
Co-authored-by: sunmy2019 <[email protected]>
2023-04-19 11:18:16 -05:00
7f3c106503 gh-103326: Remove Python/importlib.h (GH-103331)
Co-authored-by: Brett Cannon <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
2023-04-12 11:27:14 -07:00
Brandt BucherandGitHub b4978ff872 GH-88691: Shrink the CALL caches (GH-103230) 2023-04-05 14:15:49 -07:00
Brandt BucherandGitHub 121057aa36 GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
chgnrdvandGitHub 85ba8a3e03 gh-102650: Remove duplicate include directives from multiple source files (#102651)
Remove duplicate include directives from multiple source files
2023-03-13 13:25:17 -06:00
penguin_wwyandGitHub 753fc8a5d6 gh-101632: Add the new RETURN_CONST opcode (#101633) 2023-02-07 22:32:21 +00:00
Brandt BucherandGitHub 3c033a2e6f GH-99554: Pack location tables more effectively (GH-99556) 2022-12-21 16:41:18 -08:00
228c92eb5c gh-99582: freeze zipimport into _bootstrap_python (#99583)
Co-authored-by: Kumar Aditya <[email protected]>
2022-12-10 15:05:56 +05:30
Mark ShannonandGitHub fb713b2183 GH-98522: Add version number to code objects. (GH-98525)
* Add version number to code object for better versioning of functions.

* Improves specialization for closures and list comprehensions.
2022-12-09 12:18:45 +00:00
SQLPATCHandGitHub 4e5f2db6f2 gh-98872: Fix a possible resource leak in Python 3.11.0 (GH-99047)
Issue: #98872

Automerge-Triggered-By: GH:kumaraditya303
2022-11-24 01:04:19 -08:00
Kumar AdityaandGitHub 6e3cc72afe GH-90699: disallow _Py_IDENTIFIER in core code (GH-99210) 2022-11-09 08:53:21 -08:00
Nick CoghlanandGitHub 05e48865be gh-96853: Restore test coverage for Py_Initialize(Ex) (GH-98212)
* As most of `test_embed` now uses `Py_InitializeFromConfig`, add
  a specific test case to cover `Py_Initialize` (and `Py_InitializeEx`)
* Rename `_testembed` init helper to clarify the API used
* Add a `PyConfig_Clear` call in `Py_InitializeEx` to make
  the code more obviously correct (it already didn't leak as
  none of the dynamically allocated config fields were being
  populated, but it's clearer if the wrappers follow the
  documented API usage guidelines)
2022-10-30 22:01:30 +10:00
Mark ShannonandGitHub 22863df7ca GH-96793: Change FOR_ITER to not pop the iterator on exhaustion. (GH-96801)
Change FOR_ITER to have the same stack effect regardless of whether it branches or not.
Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
2022-10-27 11:55:03 +01:00
Eric SnowandGitHub f32369480d gh-98608: Change _Py_NewInterpreter() to _Py_NewInterpreterFromConfig() (gh-98609)
(see https://github.com/python/cpython/issues/98608)

This change does the following:

1. change the argument to a new `_PyInterpreterConfig` struct
2. rename the function to `_Py_NewInterpreterFromConfig()`, inspired by `Py_InitializeFromConfig()` (takes a `_PyInterpreterConfig`  instead of `isolated_subinterpreter`)
3. split up the boolean `isolated_subinterpreter` into the corresponding multiple granular settings
   * allow_fork
   * allow_subprocess
   * allow_threads
4. add `PyInterpreterState.feature_flags` to store those settings
5. add a function for checking if a feature is enabled on an opaque `PyInterpreterState *`
6. drop `PyConfig._isolated_interpreter`

The existing default (see `Py_NewInterpeter()` and `Py_Initialize*()`) allows fork, subprocess, and threads and the optional "isolated" interpreter (see the `_xxsubinterpreters` module) disables all three.  None of that changes here; the defaults are preserved.

Note that the given `_PyInterpreterConfig` will not be used outside `_Py_NewInterpreterFromConfig()`, nor preserved.  This contrasts with how `PyConfig` is currently preserved, used, and even modified outside `Py_InitializeFromConfig()`.  I'd rather just avoid that mess from the start for `_PyInterpreterConfig`.  We can preserve it later if we find an actual need.

This change allows us to follow up with a number of improvements (e.g. stop disallowing subprocess and support disallowing exec instead).

(Note that this PR adds "private" symbols.  We'll probably make them public, and add docs, in a separate change.)
2022-10-26 11:16:30 -06:00
Victor StinnerandGitHub 1863302d61 gh-97669: Create Tools/build/ directory (#97963)
Create Tools/build/ directory. Move the following scripts from
Tools/scripts/ to Tools/build/:

* check_extension_modules.py
* deepfreeze.py
* freeze_modules.py
* generate_global_objects.py
* generate_levenshtein_examples.py
* generate_opcode_h.py
* generate_re_casefix.py
* generate_sre_constants.py
* generate_stdlib_module_names.py
* generate_token.py
* parse_html5_entities.py
* smelly.py
* stable_abi.py
* umarshal.py
* update_file.py
* verify_ensurepip_wheels.py

Update references to these scripts.
2022-10-17 12:01:00 +02:00
Gregory P. SmithandGitHub b0f89cb431 gh-96512: Move int_max_str_digits setting to PyConfig (#96944)
It had to live as a global outside of PyConfig for stable ABI reasons in
the pre-3.12 backports.

This removes the `_Py_global_config_int_max_str_digits` and gets rid of
the equivalent field in the internal `struct _is PyInterpreterState` as
code can just use the existing nested config struct within that.

Adds tests to verify unique settings and configs in subinterpreters.
2022-10-03 13:55:45 -07:00
Brandt BucherandGitHub 8fd2c3b75b GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97003) 2022-09-22 09:16:52 -07:00
Matthias GörgensandGitHub 6ba686d97f gh-96678: Avoid undefined behaviour in test (#96672) 2022-09-13 13:15:11 +01:00