162 Commits
Author SHA1 Message Date
22bc41d3c2 [3.15] gh-160962: Fix PyInitConfig_SetStr() with NULL value (GH-161258) (#161291)
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:35 +01:00
9f13436ef0 [3.15] gh-159739: Release replaced PyInitConfig strings (GH-159769) (#159809)
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:18:08 +00:00
4e62a8af56 [3.15] gh-86427: Use the console code page for the stdio encoding on Windows (GH-155415) (GH-156602)
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-10-10 12:34:51 +03:00
c5e73f8c91 [3.15] gh-153300: Set global configuration variables in PyConfig_Set() (GH-153301) (#153356)
gh-153300: Set global configuration variables in PyConfig_Set() (GH-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)

Co-authored-by: Victor Stinner <[email protected]>
2026-07-08 20:21:20 +02:00
ff6e973c3b [3.15] gh-151218: Replace sys.flags in PyConfig_Set() (GH-151402) (#151552)
gh-151218: Replace sys.flags in PyConfig_Set() (GH-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: Victor Stinner <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
2026-06-16 16:48:56 +00:00
Pablo Galindo SalgadoandGitHub 83e26a43a7 [3.15] gh-149321: Remove lazy_imports=none startup mode (GH-149389) (#150129) 2026-06-08 22:55:57 +00:00
Hugo van KemenadeandGitHub e7613f2735 gh-148766: Add colour to Python help (#148767) 2026-05-06 16:48:04 +03:00
Wulian233andGitHub 9343518c6f gh-146244: Fix initconfig.c SET_ITEM macro leaks dict on expression failure (GH-146246) 2026-03-25 19:09:56 +00:00
Gregory P. SmithandGitHub 83edae33a5 gh-145990: sort --help-env sections by environment variable name (GH-145997)
* sort --help-env alphabetically by name.
* add a sorting regression test in test_help_env.
2026-03-15 15:22:57 -07:00
Gregory P. SmithandGitHub b062f391cf gh-145990: Sort python --help-xoptions by option name (GH-145991)
* Sort --help-xoptions alphabetically by name.
* add a sorting regression test in test_help_xoptions
2026-03-15 22:02:14 +00:00
Filipe LaínsandGitHub eb611a8515 GH-145275: add -X pathconfig_warnings and PYTHON_PATHCONFIG_WARNINGS (#145277) 2026-03-02 19:19:05 +00:00
46d5106cfa gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <[email protected] >
Co-authored-by: Brittany Reynoso <[email protected]>
Co-authored-by: Dino Viehland <[email protected]>
2026-02-12 00:15:33 +00:00
Pablo Galindo SalgadoandGitHub 96e4cd698a gh-144319: Fix huge page safety in pymalloc arenas (#144331)
The pymalloc huge page support had two problems. First, on
architectures where the default huge page size exceeds the arena
size (e.g. 32 MiB on PPC, 512 MiB on ARM64 with 64 KB base
pages), mmap with MAP_HUGETLB silently allocates a full huge page
even when the requested size is smaller. The subsequent munmap
with the original arena size then fails with EINVAL, permanently
leaking the entire huge page. Second, huge pages were always
attempted when compiled in, with no way to disable them at
runtime. On Linux, if the huge page pool is exhausted, page
faults including copy-on-write faults after fork deliver SIGBUS
and kill the process.

The arena allocator now queries the system huge page size from
/proc/meminfo and skips MAP_HUGETLB when the arena size is not a
multiple of it. Huge pages also now require explicit opt-in at
runtime via the PYTHON_PYMALLOC_HUGEPAGES environment variable,
which is read through PyConfig and respects -E and -I flags.
The config field pymalloc_hugepages is propagated to the runtime
allocators struct so the low-level arena allocator can check it
without calling getenv directly.
2026-01-30 18:18:56 +00:00
Stan UlbrychandGitHub 3509fa5a12 gh-143135: Fix sys.flags.inspect when PYTHONINSPECT=0 (GH-143136) 2025-12-24 19:56:59 +02:00
Neil SchemenauerandGitHub c98c5b3449 gh-131253: free-threaded build support for pystats (gh-137189)
Allow the --enable-pystats build option to be used with free-threading.  The
stats are now stored on a per-interpreter basis, rather than process global.
For free-threaded builds, the stats structure is allocated per-thread and
then periodically merged into the per-interpreter stats structure (on thread
exit or when the reporting function is called). Most of the pystats related
code has be moved into the file Python/pystats.c.
2025-11-03 11:36:37 -08:00
1c984ba953 gh-136355: Deprecate -b and -bb CLI flags in 3.15 (#136363)
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
2025-09-14 20:00:03 +03:00
Victor StinnerandGitHub 3d521a62e7 gh-138756: Fix leak of inittab memory in PyInitConfig_Free() (GH-138792) 2025-09-12 11:46:02 +02:00
Victor StinnerandGitHub 96dee64c73 gh-138756: Fix memory leak in PyInitConfig_Free() (#138759)
Clear also memory of PyConfig members.
2025-09-11 10:46:19 +00:00
c89a66feb1 GH-133711: Enable UTF-8 mode by default (PEP 686) (#133712)
Co-authored-by: Victor Stinner <[email protected]>
2025-07-15 10:45:41 +01:00
Hugo van KemenadeandGitHub fbef0c1d6a gh-102567: Add missing newline to --help-all (GH-136391) 2025-07-08 07:59:00 +02:00
Serhiy StorchakaandGitHub bac3fcba5b gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)
Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
2025-05-28 20:11:09 +03:00
Bénédikt TranandGitHub dc191d2484 gh-133336: Remove comment about reserved -J in `initconfig.c` (#133821) 2025-05-10 22:31:45 +01: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