summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-142571: Check for errors before calling each syscall in ↵AZero132025-12-111-6/+17
| | | | | | | | `PyUnstable_CopyPerfMapFile()` (#142460) Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-141579: Fix perf_jit backend in sys.activate_stack_trampoline() (#141580)Pablo Galindo Salgado2025-11-151-8/+8
|
* gh-111389: replace deprecated occurrences of `_PyHASH_*` macros (#141236)Bénédikt Tran2025-11-091-3/+3
|
* gh-131253: free-threaded build support for pystats (gh-137189)Neil Schemenauer2025-11-031-1/+3
| | | | | | | | 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.
* gh-138886: Remove deprecated `PySys_ResetWarnOptions` C-API function (#138887)sobolevn2025-09-151-1/+1
|
* gh-133143: Use _Py_ID for the other literals in sys (GH-138698)Petr Viktorin2025-09-091-5/+5
| | | | | Follow-up refactoring after GH-133143, where we use `_Py_ID` for "big" and "little" in `abi_info.byteorder`. This uses `_Py_ID` for `sys.byteorder`, but also `float_repr_style` and a module name.
* gh-133143: Condense the implementation for ``sys.abi_info`` (#138672)Adam Turner2025-09-081-23/+16
|
* gh-133143: Add sys.abi_info (GH-137476)Klaus Zimmermann2025-09-081-0/+70
| | | | | | | This makes information about the interpreter ABI more accessible. Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
* GH-137623: Use an AC decorator for docstring line length enforcement (#137690)Adam Turner2025-08-181-7/+14
|
* gh-135228: Create __dict__ and __weakref__ descriptors for object (GH-136966)Petr Viktorin2025-08-181-41/+0
| | | | | | | | | | | | | | | | | | | | | | | This partially reverts #137047, keeping the tests for GC collectability of the original class that dataclass adds `__slots__` to. The reference leaks solved there are instead solved by having the `__dict__` & `__weakref__` descriptors not tied to (and referencing) their class. Instead, they're shared between all classes that need them (within an interpreter). The `__objclass__` ol the descriptors is set to `object`, since these descriptors work with *any* object. (The appropriate checks were already made in the get/set code, so the `__objclass__` check was redundant.) The repr of these descriptors (and any others whose `__objclass__` is `object`) now doesn't mention the objclass. This change required adjustment of introspection code that checks `__objclass__` to determine an object's “own” (i.e. not inherited) `__dict__`. Third-party code that does similar introspection of the internals will also need adjusting. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-137400: Fix thread-safety issues when profiling all threads (gh-137518)Sam Gross2025-08-131-5/+8
| | | | | | | | | | There were a few thread-safety issues when profiling or tracing all threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads: * The loop over thread states could crash if a thread exits concurrently (in both the free threading and default build) * The modification of `c_profilefunc` and `c_tracefunc` wasn't thread-safe on the free threading build.
* gh-135228: When @dataclass(slots=True) replaces a dataclass, make the ↵Jelle Zijlstra2025-08-121-0/+42
| | | | | | | | | | | | | | | | original class collectible (take 2) (GH-137047) Remove the `__dict__` and `__weakref__` descriptors from the original class when creating a dataclass from it. An interesting hack, but more localized in scope than gh-135230. This may be a breaking change if people intentionally keep the original class around when using `@dataclass(slots=True)`, and then use `__dict__` or `__weakref__` on the original class. Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-135645: Added `supports_isolated_interpreters` to `sys.implementation` ↵sobolevn2025-06-211-0/+12
| | | | | (#135667) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* gh-135543: Emit sys.remote_exec audit event when sys.remote_exec is called ↵Nadeshiko Manju2025-06-191-0/+5
| | | | (GH-135544)
* gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)Serhiy Storchaka2025-05-281-18/+18
| | | | | Add functions PySys_GetAttr(), PySys_GetAttrString(), PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
* gh-134064: Fix sys.remote_exec() error checking (#134067)Victor Stinner2025-05-171-1/+1
|
* gh-133580: Add missing exception to _sys_getwindowsversion_from_kernel32 ↵Max Bachmann2025-05-141-0/+1
| | | | (GH-133574)
* gh-133886: Fix sys.remote_exec() for non-UTF-8 paths (GH-133887)Serhiy Storchaka2025-05-131-54/+52
| | | | | It now supports non-ASCII paths in non-UTF-8 locales and non-UTF-8 paths in UTF-8 locales.
* gh-133597: Fix memory leak if error occurred in ↵Sergey Miryanov2025-05-081-0/+3
| | | | _sys_getwindowsversion_from_kernel32 (GH-133598)
* GH-133231: Add JIT utilities in sys._jit (GH-133233)Brandt Bucher2025-05-051-0/+75
|
* gh-132950: Check for Py_SUPPORTS_REMOTE_DEBUG in sys.is_remote_debug_enabled ↵Pablo Galindo Salgado2025-04-251-1/+1
| | | | (#132959)
* gh-129027: Raise DeprecationWarning for sys._clear_type_cache (#129043)Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి)2025-04-251-0/+8
| | | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
* gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)Neil Schemenauer2025-04-091-0/+4
| | | | | | | | | | | | | | | | | | | | 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 <kumaraditya@python.org>
* gh-131591: Implement PEP 768 (#131937)Pablo Galindo Salgado2025-04-031-0/+116
| | | | Co-authored-by: Ivona Stojanovic <stojanovic.i@hotmail.com> Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
* GH-131296: fix clang-cl warnings in sysmodule.c (#131304)Chris Eibl2025-03-201-1/+1
|
* gh-131238: Remove includes from pycore_interp.h (#131495)Victor Stinner2025-03-201-2/+1
| | | Remove also now unused includes in C files.
* Fix Windows build warnings (#131487)Victor Stinner2025-03-201-0/+2
| | | | | | | | | | | | | | | | Fix the following warnings: * Modules\_io\fileio.c(1296,13): unused variable 'self' * Modules\_io\winconsoleio.c(334,9): unused variable 'fd_is_own' * Modules\faulthandler.c(409,11): unused variable 'flags' * Modules\posixmodule.c(5699,9): unused variable 'pathError' * PC\winreg.c(2077,5): suggest braces around initialization of subobject * PC\winreg.c(34,13): unused variable 'errNotAHandle' * Python\fileutils.c(132,12): result of comparison of constant 1114111 with expression of type 'wchar_t' (aka 'unsigned short') is always false * Python\fileutils.c(58,21): unused variable 'INCOMPLETE_CHARACTER' * Python\sysmodule.c(2534,21): unused variable 'perf_map_state'
* gh-131238: Remove more includes from pycore_interp.h (#131480)Victor Stinner2025-03-191-0/+3
|
* gh-131082: Add missing guards for WIN32_LEAN_AND_MEAN (#131044)Max Bachmann2025-03-111-1/+3
| | | | | * Add missing guards for WIN32_LEAN_AND_MEAN * add missing whitespaces
* gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)Serhiy Storchaka2025-02-251-45/+126
| | | | | | | | 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().
* gh-111924: Fix data races when swapping allocators (gh-130287)Sam Gross2025-02-201-15/+7
| | | | | | | | | | | | | | | 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.
* gh-128509: Add `sys._is_immortal` for identifying immortal objects (#128510)Peter Bierma2025-01-311-0/+18
| | | Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-126108: Fix potential null pointer dereference in ↵Valery Fedorenko2025-01-311-3/+4
| | | | `PySys_AddWarnOptionUnicode` (#126118)
* GH-126599: Remove the PyOptimizer API (GH-129194)Brandt Bucher2025-01-291-3/+1
|
* gh-127350: Add Py_fopen() and Py_fclose() functions (#127821)Victor Stinner2025-01-061-1/+1
|
* GH-126833: Dumps graphviz representation of executor graph. (GH-126880)Mark Shannon2024-12-131-0/+25
|
* gh-127238: adjust error message for sys.set_int_max_str_digits() (#127241)Sergey B Kirpichev2024-11-251-1/+1
| | | Now it's correct and closer to Python/initconfig.c
* gh-126579: Adapt sys.audit() to Argument Clinic (GH-126580)Serhiy Storchaka2024-11-081-41/+13
|
* gh-115999: Implement thread-local bytecode and enable specialization for ↵mpage2024-11-041-0/+5
| | | | | | | | | `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.
* gh-126255: Ignore warning about JIT being deactivated when perf support is ↵mpage2024-11-011-0/+1
| | | | | | | | | | | active in `test_embed.InitConfigTests.test_initconfig_api` (#126302) Temporarily ignore warnings about JIT deactivation when perf support is active. This will be reverted as soon as a way is found to determine at run time whether the interpreter was built with JIT. Currently, this is not possible on Windows. Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-124855: Don't allow the JIT and perf support to be active at the same ↵Pablo Galindo Salgado2024-10-301-0/+8
| | | | time (#124856)
* gh-126018: Avoid aborting due to unnecessary assert in `sys.audit` (#126020)devdanzin2024-10-271-1/+0
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-125604: Move _Py_AuditHookEntry, etc. Out of pycore_runtime.h (gh-125605)Eric Snow2024-10-181-0/+1
| | | | | | | | | | | | This is essentially a cleanup, moving a handful of API declarations to the header files where they fit best, creating new ones when needed. We do the following: * add pycore_debug_offsets.h and move _Py_DebugOffsets, etc. there * inline struct _getargs_runtime_state and struct _gilstate_runtime_state in _PyRuntimeState * move struct _reftracer_runtime_state to the existing pycore_object_state.h * add pycore_audit.h and move to it _Py_AuditHookEntry , _PySys_Audit(), and _PySys_ClearAuditHooks * add audit.h and cpython/audit.h and move the existing audit-related API there *move the perfmap/trampoline API from cpython/sysmodule.h to cpython/ceval.h, and remove the now-empty cpython/sysmodule.h
* gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (#124026)Sam Gross2024-09-241-2/+3
| | | | | | Use a `_PyStackRef` and defer the reference to `f_funcobj` when possible. This avoids some reference count contention in the common case of executing the same code object from multiple threads concurrently in the free-threaded build.
* gh-107954, PEP 741: Add PyConfig_Get()/Set() functions (#123472)Victor Stinner2024-09-021-69/+75
| | | | | | | | | | | 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 <10796600+picnixz@users.noreply.github.com>
* gh-113993: Allow interned strings to be mortal, and fix related issues ↵Petr Viktorin2024-06-211-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-120520) * Add an InternalDocs file describing how interning should work and how to use it. * Add internal functions to *explicitly* request what kind of interning is done: - `_PyUnicode_InternMortal` - `_PyUnicode_InternImmortal` - `_PyUnicode_InternStatic` * Switch uses of `PyUnicode_InternInPlace` to those. * Disallow using `_Py_SetImmortal` on strings directly. You should use `_PyUnicode_InternImmortal` instead: - Strings should be interned before immortalization, otherwise you're possibly interning a immortalizing copy. - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in backports, as they are now part of public API and version-specific ABI. * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery. * Make sure the statically allocated string singletons are unique. This means these sets are now disjoint: - `_Py_ID` - `_Py_STR` (including the empty string) - one-character latin-1 singletons Now, when you intern a singleton, that exact singleton will be interned. * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic). * Intern `_Py_STR` singletons at startup. * For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup. * Beef up the tests. Cover internal details (marked with `@cpython_only`). * Add lots of assertions Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
* gh-120568: fix file leak in PyUnstable_CopyPerfMapFile (#120569)Carson Radtke2024-06-161-4/+4
|
* gh-74929: PEP 667 C API documentation (gh-119379)Alyssa Coghlan2024-06-011-1/+0
| | | | | | | | * Add docs for new APIs * Add soft-deprecation notices * Add What's New porting entries * Update comments referencing `PyFrame_LocalsToFast()` to mention the proxy instead * Other related cleanups found when looking for refs to the deprecated APIs
* gh-118518: Rename `PYTHONPERFJITSUPPORT` and `-X perfjit` with underscores ↵Hugo van Kemenade2024-05-071-1/+1
| | | | (#118693)
* gh-116322: Enable the GIL while loading C extension modules (#118560)Brett Simmers2024-05-071-2/+1
| | | | | | | | | | Add the ability to enable/disable the GIL at runtime, and use that in the C module loading code. We can't know before running a module init function if it supports free-threading, so the GIL is temporarily enabled before doing so. If the module declares support for running without the GIL, the GIL is later disabled. Otherwise, the GIL is permanently enabled, and will never be disabled again for the life of the current interpreter.