153 Commits
Author SHA1 Message Date
d16d33aa6e [3.14] gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258) (#161292)
gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258)

Previously, passing NULL to an optional string option crashed.

Document optional string options.

Add more tests on the PyInitConfig API.
(cherry picked from commit 6d69297b2b)

Co-authored-by: Victor Stinner <[email protected]>
2026-11-04 03:41:38 +01:00
a3fdda2a53 [3.14] gh-159739: Release replaced PyInitConfig strings (GH-159769) (#159810)
gh-159739: Release replaced PyInitConfig strings (GH-159769)

* gh-159739: Release replaced PyInitConfig strings

Backport to 3.15 and 3.14.

---------
(cherry picked from commit 395d766d4f)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
2026-10-20 00:32:57 +00:00
d4ae98b0ec [3.14] gh-86427: Use the console code page for the stdio encoding on Windows (GH-155415) (GH-156603)
In the legacy Windows stdio mode PyConfig.stdio_encoding is now initialized
with the console output code page instead of the ANSI code page.

Only one encoding can be specified, so sys.stdin.encoding is still wrong if
the input code page differs from the output one.
(cherry picked from commit 0bb312a4ea)

Co-authored-by: Serhiy Storchaka <[email protected]>
2026-08-29 19:45:46 +00:00
Victor StinnerandGitHub 6241d0d46b [3.14] gh-153300: Set global configuration variables in PyConfig_Set() (#153301) (#153359)
gh-153300: Set global configuration variables in PyConfig_Set() (#153301)

PyConfig_Set() now also set global configuration variables. For
example, PyConfig_Set("inspect", value) now also sets Py_InspectFlag.

Use PyConfig_Set() in main.c to set the inspect flag. Python code can
now see the updated sys.flags.inspect value.

(cherry picked from commit 9fb713f1b8)
2026-07-08 20:20:45 +02:00
60132db980 [3.14] gh-151218: Replace sys.flags in PyConfig_Set() (#151402) (#151553)
gh-151218: Replace sys.flags in PyConfig_Set() (#151402)

PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags (create a new object), instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.


(cherry picked from commit b16d23fc9f)

Co-authored-by: Bénédikt Tran <[email protected]>
2026-06-16 18:55:35 +02:00
4d61fd6b7a [3.14] gh-146244: Fix initconfig.c SET_ITEM macro leaks dict on expression failure (GH-146246) (GH-146432)
(cherry picked from commit 9343518c6f)

Co-authored-by: Wulian233 <[email protected]>
2026-03-27 02:37:53 +00:00
Gregory P. SmithandGitHub b8cb83703f [3.14] gh-145990: sort --help-env sections by environment variable name (GH-146001)
* sort --help-env alphabetically by name.
* add a sorting regression test in test_help_env.

manual backport of GH-145997
2026-03-15 22:55:08 +00:00
Gregory P. SmithandGitHub 36805f6e44 [3.14] gh-145990: Sort python --help-xoptions by option name (GH-145993)
* Sort --help-xoptions alphabetically by name.
* add a sorting regression test in test_help_xoptions

manual backport of GH-145991
2026-03-15 15:17:07 -07:00
73c40bb8ba [3.14] gh-143135: Fix sys.flags.inspect when PYTHONINSPECT=0 (GH-143136) (GH-143153)
(cherry picked from commit 3509fa5a12)

Co-authored-by: Stan Ulbrych <[email protected]>
2025-12-24 18:23:41 +00:00
9e091dbf02 [3.14] gh-138756: Fix leak of inittab memory in PyInitConfig_Free() (GH-138792) (#139703)
gh-138756: Fix leak of inittab memory in PyInitConfig_Free() (GH-138792)
(cherry picked from commit 3d521a62e7)

Co-authored-by: Victor Stinner <[email protected]>
2025-10-07 17:11:20 +00:00
0accda7468 [3.14] gh-138756: Fix memory leak in PyInitConfig_Free() (GH-138759) (#138785)
gh-138756: Fix memory leak in PyInitConfig_Free() (GH-138759)

Clear also memory of PyConfig members.
(cherry picked from commit 96dee64c73)

Co-authored-by: Victor Stinner <[email protected]>
2025-10-07 18:42:50 +02:00
cdeaa64214 [3.14] gh-102567: Add missing newline to --help-all (GH-136391) (GH-136403)
gh-102567: Add missing newline to `--help-all` (GH-136391)
(cherry picked from commit fbef0c1d6a)

Co-authored-by: Hugo van Kemenade <[email protected]>
2025-07-08 06:24:08 +00:00
Miss Islington (bot)andGitHub da1e5c434b [3.14] gh-133336: Remove comment about reserved -J in `initconfig.c` (GH-133821) (#133855) 2025-05-10 22:25:42 +00:00
c4bcc6a778 gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules (#118655)
Co-authored-by: Adam Turner <[email protected]>
2025-05-06 01:03:55 +01:00
Victor StinnerandGitHub ac5424d6a9 gh-107954: Add audit event to PyConfig_Set() (#132958) 2025-04-25 18:30:39 +02:00
Victor StinnerandGitHub 070d866567 gh-107954: Allow setting cpu_count in PyConfig_Set() (#132954)
* gh-107954: Allow setting cpu_count in PyConfig_Set()

* Update the doc
2025-04-25 18:29:55 +02:00
d687900f98 gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <[email protected]>
2025-04-09 16:18:54 -07:00
943cc1431e gh-131591: Implement PEP 768 (#131937)
Co-authored-by: Ivona Stojanovic <[email protected]>
Co-authored-by: Matt Wozniski <[email protected]>
2025-04-03 16:20:01 +01:00
HangandGitHub 8bd88e2827 gh-131818: Add imply -P in -I's help message (#131819) 2025-03-28 08:49:13 +01:00
Mark ShannonandGitHub a1aeec61c4 GH-131238: Core header refactor (GH-131250)
* Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h

* Removes many cross-header dependencies
2025-03-17 09:19:04 +00:00
Russell Keith-MageeandGitHub dd6d24e9d2 gh-130940: Modify default behavior of PyConfig.use_system_logger to enable on iOS (#131172)
Modify default behavior of use_system_log to enable on iOS.
2025-03-13 14:28:49 +08:00
Serhiy StorchakaandGitHub 0ef4ffeefd gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
2025-02-25 23:04:27 +02:00
Sam GrossandGitHub ca22147547 gh-111924: Fix data races when swapping allocators (gh-130287)
CPython current temporarily changes `PYMEM_DOMAIN_RAW` to the default
allocator during initialization and shutdown. The motivation is to
ensure that core runtime structures are allocated and freed using the
same allocator. However, modifying the current allocator changes global
state and is not thread-safe even with the GIL. Other threads may be
allocating or freeing objects use PYMEM_DOMAIN_RAW; they are not
required to hold the GIL to call PyMem_RawMalloc/PyMem_RawFree.

This adds new internal-only functions like `_PyMem_DefaultRawMalloc`
that aren't affected by calls to `PyMem_SetAllocator()`, so they're
appropriate for Python runtime initialization and finalization. Use
these calls in places where we previously swapped to the default raw
allocator.
2025-02-20 11:31:15 -05:00
e1b38ea82e Update manpage environment variables and command line arguments (#129623)
Co-authored-by: Hugo van Kemenade <[email protected]>
2025-02-12 13:00:35 +02:00
Victor StinnerandGitHub 01de4af3e1 gh-126925: Make PyConfig.use_system_logger read-only (#129124)
The variable is only used once during early Python initialization, it
doesn't make sense to modify it at runtime.
2025-01-21 12:02:38 +01:00
Russell Keith-MageeandGitHub 2041a95e68 gh-126925: Modify how iOS test results are gathered (#127592)
Adds a `use_system_log` config item to enable stdout/stderr redirection for
Apple platforms. This log streaming is then used by a new iOS test runner
script, allowing the display of test suite output at runtime. The iOS test
runner script can be used by any Python project, not just the CPython test
suite.
2024-12-09 13:28:57 +08:00
mpageandGitHub 2e95c5ba3b gh-115999: Implement thread-local bytecode and enable specialization for 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.
2024-11-04 11:13:32 -08:00
RUANG (Roy James)andGitHub 546dddca43 gh-125234: Make PyInitConfig_Free(NULL) a no-op (#125266) 2024-10-15 09:21:16 +00:00
Pablo Galindo SalgadoandGitHub 02b49c5150 gh-107954: Fix configuration type for the perf profiler (#124636) 2024-09-28 01:50:16 +02:00
Peter BiermaandGitHub 84ad264ce6 gh-123275: Support -Xgil=1 and PYTHON_GIL=1 on non-free-threaded builds (gh-123276) 2024-09-06 08:53:47 +09:00
Victor StinnerandGitHub 0d6b6e34a2 gh-107954, PEP 741: Add PyInitConfig_AddModule() function (#123668) 2024-09-04 11:41:57 +00:00
Victor StinnerandGitHub b423ae6b08 gh-107954, PEP 741: Adjust Python initialization config (#123663)
Setting dev_mode to 1 in an isolated configuration now enables also
faulthandler.

Moreover, setting "module_search_paths" option with
PyInitConfig_SetStrList() now sets "module_search_paths_set" to 1.
2024-09-04 10:58:32 +00:00
Victor StinnerandGitHub ef9d54703f gh-107954, PEP 741: Add PyInitConfig C API (#123502)
Add Doc/c-api/config.rst documentation.
2024-09-03 12:33:49 +00:00
33b790978d gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)
Add PyConfig_Get(), PyConfig_GetInt(), PyConfig_Set() and
PyConfig_Names() functions to get and set the current runtime Python
configuration.

Add visibility and "sys spec" to config and preconfig specifications.

_PyConfig_AsDict() now converts PyConfig.xoptions as a dictionary.

Co-authored-by: Bénédikt Tran <[email protected]>
2024-09-02 23:25:08 +02:00
devdanzinandGitHub c81a5e6b5b gh-119574: Add some missing environment variables to '--help-env'. (GH-120006) 2024-06-18 17:12:58 +00:00
Hugo van KemenadeandGitHub 04859228aa gh-118518: Rename PYTHONPERFJITSUPPORT and -X perfjit with underscores (#118693) 2024-05-07 11:47:21 +00:00
Pablo Galindo SalgadoandGitHub 09871c9223 gh-118518: Correct type of perf_profiling in config (#118646) 2024-05-06 15:30:30 +01:00
Pablo Galindo SalgadoandGitHub 1b22d801b8 gh-118518: Allow perf to work without frame pointers (#112254) 2024-05-05 03:07:29 +02:00
Eric SnowandGitHub f341d6017d gh-76785: Add PyInterpreterConfig Helpers (gh-117170)
These helpers make it easier to customize and inspect the config used to initialize interpreters.  This is especially valuable in our tests.  I found inspiration from the PyConfig API for the PyInterpreterConfig dict conversion stuff.  As part of this PR I've also added a bunch of tests.
2024-04-02 20:35:52 +00:00
Serhiy StorchakaandGitHub 2d17309cc7 gh-117041: Add "-X gil" in the Python CLI help (GH-117042) 2024-03-19 23:30:25 +02:00
b85572c47d gh-90300: Improve the Python CLI help output (GH-115853)
* document equivalent command-line options for all environment variables
* document equivalent environment variables for all command-line options
* reduce the size of variable and option descriptions to minimum
* remove the ending period in single-sentence descriptions

Co-authored-by: Éric <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
2024-03-19 19:26:32 +02:00
Serhiy StorchakaandGitHub 19ac28bd08 gh-90300: Fix undocumented envvars in the Python CLI help (GH-116765) 2024-03-14 12:09:19 +02:00
Serhiy StorchakaandGitHub 8c6db45ce3 gh-90300: Document equivalent -X options for envvars in the Python CLI help (GH-116756) 2024-03-13 22:59:16 +02:00
Serhiy StorchakaandGitHub e54bdeab9c gh-90300: Sort the -X options and some envvars in the Python CLI help (GH-116739) 2024-03-13 21:15:44 +02:00
Serhiy StorchakaandGitHub 33662d4e01 gh-90300: Fix cmdline.rst (GH-116721)
* Fix the description of the "-b" option.
* Add references to environment variables for "-s" and "-X dev" options.
2024-03-13 15:03:13 +02:00
Brett SimmersandGitHub 2731913dd5 gh-116167: Allow disabling the GIL with PYTHON_GIL=0 or -X gil=0 (#116338)
In free-threaded builds, running with `PYTHON_GIL=0` will now disable the
GIL. Follow-up issues track work to re-enable the GIL when loading an
incompatible extension, and to disable the GIL by default.

In order to support re-enabling the GIL at runtime, all GIL-related data
structures are initialized as usual, and disabling the GIL simply sets a flag
that causes `take_gil()` and `drop_gil()` to return early.
2024-03-11 11:02:58 -04:00
Victor StinnerandGitHub 2b379968e5 gh-107954: Add PyConfig_MEMBER_BOOL type to PyConfigSpec (#116359)
_PyConfig_AsDict() now returns bool objects for options using the new
PyConfig_MEMBER_BOOL type.

Update tests for these changes.
2024-03-06 09:29:27 +00:00
Serhiy StorchakaandGitHub 2e92ffd7fa gh-90300: Reformat the Python CLI help output (GH-93415) 2024-02-23 10:27:07 +01:00
e5d0316f35 gh-73965: Move PYTHON_HISTORY into the correct usage section (#113798)
Co-authored-by: Serhiy Storchaka <[email protected]>
2024-01-08 11:58:58 +02:00
f19b93fce0 gh-73965: New environment variable PYTHON_HISTORY (#13208)
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
2024-01-06 22:30:12 -08:00