summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-113993: Allow interned strings to be mortal, and fix related ↵Petr Viktorin2024-06-241-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | issues (GH-120520) (GH-120945) * 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>
* [3.13] gh-74929: PEP 667 C API documentation (gh-119892)Miss Islington (bot)2024-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 (cherry picked from commit 3859e09e3d92d004978dd838f0511364e7edfb94) Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
* 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.
* gh-118473: Fix set_asyncgen_hooks not to be partially set when arguments are ↵Jeong, YunWon2024-05-071-8/+20
| | | | invalid (#118474)
* gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL ↵Petr Viktorin2024-05-061-1/+1
| | | | (GH-118645)
* gh-111201: A new Python REPL (GH-111567)Pablo Galindo Salgado2024-05-051-0/+16
| | | | | | | Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-118518: Allow perf to work without frame pointers (#112254)Pablo Galindo Salgado2024-05-051-0/+10
|
* gh-74929: Implement PEP 667 (GH-115153)Tian Gao2024-05-041-8/+0
|
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+3
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-117514: Add `sys._is_gil_enabled()` function (#118514)Sam Gross2024-05-031-0/+20
| | | | | The function returns `True` or `False` depending on whether the GIL is currently enabled. In the default build, it always returns `True` because the GIL is always enabled.
* Remove stray `__cplusplus` guard in sysmodule.c (#118511)Sam Gross2024-05-021-4/+0
|
* gh-118335: Configure Tier 2 interpreter at build time (#118339)Guido van Rossum2024-05-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | The code for Tier 2 is now only compiled when configured with `--enable-experimental-jit[=yes|interpreter]`. We drop support for `PYTHON_UOPS` and -`Xuops`, but you can disable the interpreter or JIT at runtime by setting `PYTHON_JIT=0`. You can also build it without enabling it by default using `--enable-experimental-jit=yes-off`; enable with `PYTHON_JIT=1`. On Windows, the `build.bat` script supports `--experimental-jit`, `--experimental-jit-off`, `--experimental-interpreter`. In the C code, `_Py_JIT` is defined as before when the JIT is enabled; the new variable `_Py_TIER2` is defined when the JIT *or* the interpreter is enabled. It is actually a bitmask: 1: JIT; 2: default-off; 4: interpreter.
* gh-117953: Cleanups For fix_up_extension() in import.c (gh-118192)Eric Snow2024-04-241-1/+1
| | | These are cleanups I've pulled out of gh-118116. Mostly, this change moves code around to align with some future changes and to improve clarity a little. There is one very small change in behavior: we now add the module to the per-interpreter caches after updating the global state, rather than before.
* gh-117987: Restore several functions removed in Python 3.13 alpha 1 (GH-117993)Victor Stinner2024-04-181-4/+2
| | | | | | | | | Restore these functions removed in Python 3.13 alpha 1: * Py_SetPythonHome() * Py_SetProgramName() * PySys_SetArgvEx() * PySys_SetArgv()
* gh-117764: Add signatures for some functions in the sys module (GH-117770)Serhiy Storchaka2024-04-121-30/+44
| | | Use Argument Clinic if possible.
* gh-116167: Allow disabling the GIL with `PYTHON_GIL=0` or `-X gil=0` (#116338)Brett Simmers2024-03-111-0/+11
| | | | | | | | | 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.
* gh-116326: Handler errors correctly in `getwindowsversion` in `sysmodule` ↵Nikita Sobolev2024-03-051-20/+32
| | | | (#116339)
* gh-115320: Refactor `get_hash_info` in `sysmodule.c` not to swallow errors ↵Nikita Sobolev2024-03-041-23/+25
| | | | (#115321)
* gh-115168: Add pystats counter for invalidated executors (GH-115169)Michael Droettboom2024-02-261-1/+1
|
* GH-114695: Add `sys._clear_internal_caches` (GH-115152)Brandt Bucher2024-02-121-0/+17
|
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build ↵Sam Gross2024-02-011-1/+9
| | | | | | | | | | | | | | | | | (#114564) * gh-112529: Remove PyGC_Head from object pre-header in free-threaded build This avoids allocating space for PyGC_Head in the free-threaded build. The GC implementation for free-threaded CPython does not use the PyGC_Head structure. * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev` in the free-threaded build. * The GDB libpython.py file now determines the offset of the managed dict field based on whether the running process is a free-threaded build. Those are identified by the `ob_ref_local` field in PyObject. * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the size of `PyGC_Head` in the size of static `PyTypeObject`.
* gh-114384: Align sys.set_asyncgen_hooks signature in docs to reflect ↵Nikita Sobolev2024-01-211-1/+1
| | | | implementation (#114385)
* gh-73427: deprecate `_enablelegacywindowsfsencoding` (#107729)Inada Naoki2023-12-281-0/+7
|
* gh-111924: Use PyMutex for Runtime-global Locks. (gh-112207)Sam Gross2023-12-071-9/+3
| | | | | This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize. This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
* bpo-34392: Add sys. _is_interned() (GH-8755)Serhiy Storchaka2023-12-041-0/+18
|
* gh-111262: Add PyDict_Pop() function (#112028)Victor Stinner2023-11-141-3/+1
| | | | | | | _PyDict_Pop_KnownHash(): remove the default value and the return type becomes an int. Co-authored-by: Stefan Behnel <stefan_ml@behnel.de> Co-authored-by: Antoine Pitrou <pitrou@free.fr>
* gh-106672: C API: Report indiscriminately ignored errors (GH-106674)Serhiy Storchaka2023-11-071-0/+3
| | | | | Functions which indiscriminately ignore all errors now report them as unraisable errors.
* gh-109587: Allow "precompiled" perf-trampolines to largely mitigate the cost ↵gsallam2023-10-271-1/+40
| | | | of enabling perf-trampolines (#109666)
* gh-109595: Add -Xcpu_count=<n> cmdline for container users (#109667)Donghee Na2023-10-101-0/+15
| | | | | | --------- Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* gh-85283: Add PySys_AuditTuple() function (#108965)Victor Stinner2023-10-051-3/+19
| | | | | | 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().
* gh-110014: Include explicitly <unistd.h> header (#110155)Victor Stinner2023-09-301-1/+3
| | | | | | | | | | | * Remove unused <locale.h> includes. * Remove unused <fcntl.h> include in traceback.h. * Remove redundant <assert.h> and <stddef.h> includes. They are already included by "Python.h". * Remove <object.h> include in faulthandler.c. Python.h already includes it. * Add missing <stdbool.h> in pycore_pythread.h if HAVE_PTHREAD_STUBS is defined. * Fix also warnings in pthread_stubs.h: don't redefine macros if they are already defined, like the __NEED_pthread_t macro.
* gh-110079: Remove extern "C" { ...} in C code (#110080)Victor Stinner2023-09-291-18/+0
|
* Fix error handling in _PySys_UpdateConfig() (GH-109524)Serhiy Storchaka2023-09-181-2/+9
|
* gh-108753: Enhance pystats (#108754)Victor Stinner2023-09-061-12/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <mdboom@gmail.com>
* gh-108765: Cleanup #include in Python/*.c files (#108977)Victor Stinner2023-09-061-7/+9
| | | Mention one symbol imported by each #include.
* gh-106320: Remove private _PySys functions (#108452)Victor Stinner2023-08-241-0/+1
| | | | | | | | | | Move private functions to the internal C API (pycore_sysmodule.h): * _PySys_GetAttr() * _PySys_GetSizeOf() No longer export most of these functions. Fix also a typo in Include/cpython/optimizer.h: add a missing space.
* gh-108308: Remove _PyDict_GetItemStringWithError() function (#108426)Victor Stinner2023-08-241-1/+6
| | | | | | | | Remove the internal _PyDict_GetItemStringWithError() function. It can now be replaced with the new public PyDict_ContainsString() and PyDict_GetItemStringRef() functions. getargs.c now now uses a strong reference for current_arg. find_keyword() returns a strong reference.
* gh-108014: Add Py_IsFinalizing() function (#108032)Victor Stinner2023-08-181-1/+1
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* GH-108035: Remove the `_PyCFrame` struct as it is no longer needed for ↵Mark Shannon2023-08-171-2/+2
| | | | performance. (GH-108036)
* gh-106320: Remove private _PyDict C API (#107145)Victor Stinner2023-07-241-0/+1
| | | | | | | | | | | | | Move private _PyDict functions to the internal C API (pycore_dict.h): * _PyDict_Contains_KnownHash() * _PyDict_DebugMallocStats() * _PyDict_DelItemIf() * _PyDict_GetItemWithError() * _PyDict_HasOnlyStringKeys() * _PyDict_MaybeUntrack() * _PyDict_MergeEx() No longer export these functions.
* gh-106320: Remove private _PyObject C API (#107147)Victor Stinner2023-07-231-1/+1
| | | | | | | | | | | | | | | | Move private debug _PyObject functions to the internal C API (pycore_object.h): * _PyDebugAllocatorStats() * _PyObject_CheckConsistency() * _PyObject_DebugTypeStats() * _PyObject_IsFreed() No longer export most of these functions, except of _PyObject_IsFreed(). Move test functions using _PyObject_IsFreed() from _testcapi to _testinternalcapi. check_pyobject_is_freed() test no longer catch _testcapi.error: the tested function cannot raise _testcapi.error.
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-2/+2
|
* gh-106320: Create pycore_modsupport.h header file (#106355)Victor Stinner2023-07-031-0/+1
| | | | | | | | | | Remove the following functions from the C API, move them to the internal C API: add a new pycore_modsupport.h internal header file: * PyModule_CreateInitialized() * _PyArg_NoKwnames() * _Py_VaBuildStack() No longer export these functions.
* gh-106023: Remove _PyObject_FastCallTstate() function (#106273)Victor Stinner2023-06-301-7/+5
|
* gh-106182: sys: Intern getfilesystemencoding() and ↵Inada Naoki2023-06-301-5/+25
| | | | | getfilesystemencodeerrors() (#106183) sys: Intern getfilesystemencoding() and getfilesystemencodeerrors()
* fix typos (#106247)Inada Naoki2023-06-301-1/+1
| | | Most typos are in comments, but two typos are in docstring.
* gh-106023: Update code using _PyObject_FastCall() (#106257)Victor Stinner2023-06-301-1/+1
| | | Replace _PyObject_FastCall() calls with PyObject_Vectorcall().
* gh-106118: Add O_CLOEXEC preprocessor guard (#106120)Erlend E. Aasland2023-06-281-1/+4
|
* gh-106084: Remove old PyObject call aliases (#106085)Victor Stinner2023-06-261-1/+1
| | | | | | | | | | | | | | Remove old aliases which were kept backwards compatibility with Python 3.8: * _PyObject_CallMethodNoArgs() * _PyObject_CallMethodOneArg() * _PyObject_CallOneArg() * _PyObject_FastCallDict() * _PyObject_Vectorcall() * _PyObject_VectorcallMethod() * _PyVectorcall_Function() Update code which used these aliases to use new names.