summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-36710: Use tstate in pylifecycle.c (GH-14249)Victor Stinner2019-06-191-4/+3
| | | | In pylifecycle.c: pass tstate argument, rather than interp argument, to functions.
* bpo-36710: Add tstate parameter in import.c (GH-14218)Victor Stinner2019-06-191-18/+22
| | | | | | | | | | | | | * Add 'tstate' parameter to many internal import.c functions. * _PyImportZip_Init() now gets 'tstate' parameter rather than 'interp'. * Add 'interp' parameter to _PyState_ClearModules() and rename it to _PyInterpreterState_ClearModules(). * Move private _PyImport_FindBuiltin() to the internal C API; add 'tstate' parameter to it. * Remove private _PyImport_AddModuleObject() from the C API: use public PyImport_AddModuleObject() instead. * Remove private _PyImport_FindExtensionObjectEx() from the C API: use private _PyImport_FindExtensionObject() instead.
* Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)Victor Stinner2019-06-041-41/+48
| | | This reverts commit 396e0a8d9dc65453cb9d53500d0a620602656cfe.
* Revert "bpo-33608: Factor out a private, per-interpreter ↵Victor Stinner2019-06-031-38/+30
| | | | | _Py_AddPendingCall(). (gh-13714)" (GH-13780) This reverts commit 6a150bcaeb190d1731b38ab9c7a5d1a352847ddc.
* bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). ↵Eric Snow2019-06-011-30/+38
| | | | (gh-13714)
* bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)Eric Snow2019-06-011-48/+41
| | | https://bugs.python.org/issue36818
* bpo-36933: Remove sys.set_coroutine_wrapper (marked for removal in 3.8) ↵Matthias Bussonnier2019-05-281-4/+0
| | | | | | | | | | (GH-13577) It has been documented as deprecated and to be removed in 3.8; From a comment on another thread – which I can't find ; leave get_coro_wrapper() for now, but always return `None`. https://bugs.python.org/issue36933
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-22/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
* bpo-36842: Implement PEP 578 (GH-12613)Steve Dower2019-05-231-0/+28
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-36763: Add _PyPreConfig._config_init (GH-13481)Victor Stinner2019-05-221-2/+8
| | | | | | | | | | | | | | | | | | | * _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig() now do nothing if the configuration was not initialized with _PyPreConfig_InitCompatConfig() and _PyCoreConfig_InitCompatConfig() * Remove utf8_mode=-2 special case: use utf8_mode=-1 instead. * Fix _PyPreConfig_InitPythonConfig(): * isolated = 0 instead of -1 * use_environment = 1 instead of -1 * Rename _PyConfig_INIT to _PyConfig_INIT_COMPAT * Rename _PyPreConfig_Init() to _PyPreConfig_InitCompatConfig() * Rename _PyCoreConfig_Init() to _PyCoreConfig_InitCompatConfig() * PyInterpreterState_New() now uses _PyCoreConfig_InitPythonConfig() as default configuration, but it's very quickly overriden anyway. * _freeze_importlib.c uses _PyCoreConfig_SetString() to set program_name. * Cleanup preconfig_init_utf8_mode(): cmdline is always non-NULL.
* bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)Victor Stinner2019-05-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add new functions to get the Python interpreter behavior: * _PyPreConfig_InitPythonConfig() * _PyCoreConfig_InitPythonConfig() Add new functions to get an isolated configuration: * _PyPreConfig_InitIsolatedConfig() * _PyCoreConfig_InitIsolatedConfig() Replace _PyPreConfig_INIT and _PyCoreConfig_INIT with new functions _PyPreConfig_Init() and _PyCoreConfig_Init(). _PyCoreConfig: set configure_c_stdio and parse_argv to 0 by default to behave as Python 3.6 in the default configuration. _PyCoreConfig_Read() no longer sets coerce_c_locale_warn to 1 if it's equal to 0. coerce_c_locale_warn must now be set to -1 (ex: using _PyCoreConfig_InitPythonConfig()) to enable C locale coercion warning. Add unit tests for _PyCoreConfig_InitPythonConfig() and _PyCoreConfig_InitIsolatedConfig(). Changes: * Rename _PyCoreConfig_GetCoreConfig() to _PyPreConfig_GetCoreConfig() * Fix core_read_precmdline(): handle parse_argv=0 * Fix _Py_PreInitializeFromCoreConfig(): pass coreconfig.argv to _Py_PreInitializeFromPyArgv(), except if parse_argv=0
* bpo-36763: Add PyMemAllocatorName (GH-13387)Victor Stinner2019-05-171-2/+0
| | | | | | | | | | | | | | * Add PyMemAllocatorName enum * _PyPreConfig.allocator type becomes PyMemAllocatorName, instead of char* * Remove _PyPreConfig_Clear() * Add _PyMem_GetAllocatorName() * Rename _PyMem_GetAllocatorsName() to _PyMem_GetCurrentAllocatorName() * Remove _PyPreConfig_SetAllocator(): just call _PyMem_SetupAllocators() directly, we don't have do reallocate the configuration with the new allocator anymore! * _PyPreConfig_Write() parameter becomes const, as it should be in the first place!
* bpo-36710: Add 'ceval' local variable to ceval.c (GH-12934)Victor Stinner2019-05-101-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Add "struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;" local variables to function to better highlight the dependency on the global variable _PyRuntime and to point directly to _PyRuntime.ceval field rather than on the larger _PyRuntime. Changes: * Add _PyRuntimeState_GetThreadState(runtime) macro. * Add _PyEval_AddPendingCall(ceval, ...) and _PyThreadState_Swap(gilstate, ...) functions. * _PyThreadState_GET() macro now calls _PyRuntimeState_GetThreadState() using &_PyRuntime. * Add 'ceval' parameter to COMPUTE_EVAL_BREAKER(), SIGNAL_PENDING_SIGNALS(), _PyEval_SignalAsyncExc(), _PyEval_SignalReceived() and _PyEval_FiniThreads() macros and functions. * Add 'tstate' parameter to call_function(), do_call_core() and do_raise(). * Add 'runtime' parameter to _Py_CURRENTLY_FINALIZING(), _Py_FinishPendingCalls() and _PyThreadState_DeleteExcept() macros and functions. * Declare 'runtime', 'tstate', 'ceval' and 'eval_breaker' variables as constant.
* bpo-36737: Use the module state C-API for warnings. (gh-13159)Eric Snow2019-05-101-0/+4
|
* bpo-36710: Fix compiler warning on PyThreadState_Delete() (GH-12962)Victor Stinner2019-04-261-1/+1
| | | _PyThreadState_Delete() has no return value.
* bpo-36710: Add runtime variable in pystate.c (GH-12956)Victor Stinner2019-04-251-142/+219
| | | | Add 'gilstate', 'runtime' or 'xidregistry' parameter to many functions on pystate.c to avoid lying on _PyRuntime global.
* bpo-36710: Add runtime variable to Py_InitializeEx() (GH-12939)Victor Stinner2019-04-241-2/+2
| | | | | | | | Py_InitializeEx() now uses a runtime variable passed to subfunctions, rather than working directly on the global variable _PyRuntime. Add 'runtime' parameter to _PyCoreConfig_Write(), _PySys_Create(), _PySys_InitMain(), _PyGILState_Init(), emit_stderr_warning_for_legacy_locale() and other subfunctions.
* bpo-36710: Add runtime variable to Py_FinalizeEx() (GH-12937)Victor Stinner2019-04-241-3/+4
| | | | | | * Add a 'runtime' variable to Py_FinalizeEx() rather than working directly on the global variable _PyRuntime * Add a 'runtime' parameter to _PyGC_Fini(), _PyGILState_Fini() and call_ll_exitfuncs()
* bpo-36710: PyOS_AfterFork_Child() pass runtime parameter (GH-12936)Victor Stinner2019-04-241-33/+32
| | | | | | | | | The PyOS_AfterFork_Child() function now pass a 'runtime' parameter to subfunctions. * Fix _PyRuntimeState_ReInitThreads(): use the correct memory allocator * Add runtime parameter to _PyRuntimeState_ReInitThreads(), _PyGILState_Reinit() and _PyInterpreterState_DeleteExceptMain() * Move _PyGILState_Reinit() to the internal C API.
* bpo-36710: Add runtime parameter to _PyThreadState_Init() (GH-12935)Victor Stinner2019-04-241-64/+74
| | | | | | * Add 'runtime' parameter to _PyThreadState_Init() * Add 'gilstate' parameter to _PyGILState_NoteThreadState() * Move _PyThreadState_Init() and _PyThreadState_DeleteExcept() to the internal C API.
* bpo-33608: Revert "Factor out a private, per-interpreter ↵Eric Snow2019-04-121-32/+28
| | | | | _Py_AddPendingCall()." (gh-12806) This reverts commit f13c5c8b9401a9dc19e95d8b420ee100ac022208 (gh-12360).
* bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). ↵Eric Snow2019-04-121-28/+32
| | | | | (gh-12360) This is effectively an un-revert of #11617 and #12024 (reverted in #12159). Portions of those were merged in other PRs (with lower risk) and this represents the remainder. Note that I found 3 different bugs in the original PRs and have fixed them here.
* bpo-36444: Remove _PyMainInterpreterConfig (GH-12571)Victor Stinner2019-03-271-8/+0
|
* bpo-36301: Add _PyRuntimeState.preconfig (GH-12506)Victor Stinner2019-03-231-0/+3
| | | | _PyPreConfig_Write() now writes the applied pre-configuration into _PyRuntimeState.preconfig.
* bpo-36333: Fix leak _PyRuntimeState_Fini (GH-12400)Stéphane Wirtel2019-03-191-0/+5
|
* bpo-36124: Add PyInterpreterState.dict. (gh-12132)Eric Snow2019-03-151-0/+14
|
* bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as ↵Eric Snow2019-03-151-2/+24
| | | | necessary). (gh-12359)
* bpo-33608: Make sure locks in the runtime are properly re-created. (gh-12245)Eric Snow2019-03-091-1/+28
|
* bpo-33608: Minor cleanup related to pending calls. (gh-12247)Eric Snow2019-03-091-35/+28
|
* Revert: bpo-33608: Factor out a private, per-interpreter ↵Victor Stinner2019-03-041-85/+65
| | | | | | | | | | | | | | | | | | | _Py_AddPendingCall(). (GH-11617) (GH-12159) * Revert "bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as necessary). (#12003)" This reverts commit bcfa450f210074e16feb761ae5b3e966a2532fcf. * Revert "bpo-33608: Simplify ceval's DISPATCH by hoisting eval_breaker ahead of time. (gh-12062)" This reverts commit bda918bf65a88560ec453aaba0758a9c0d49b449. * Revert "bpo-33608: Use _Py_AddPendingCall() in _PyCrossInterpreterData_Release(). (gh-12024)" This reverts commit b05b711a2cef6c6c381e01069dedac372e0b9fb2. * Revert "bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (GH-11617)" This reverts commit ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.
* bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as ↵Eric Snow2019-03-011-2/+24
| | | | necessary). (#12003)
* bpo-33608: Use _Py_AddPendingCall() in _PyCrossInterpreterData_Release(). ↵Eric Snow2019-03-011-39/+42
| | | | | | (gh-12024)
* bpo-36142: Exclude coreconfig.h from Py_LIMITED_API (GH-12111)Victor Stinner2019-03-011-0/+1
| | | | | | | | | The whole coreconfig.h header is now excluded from Py_LIMITED_API. Move functions definitions into a new internal pycore_coreconfig.h header. * Move Include/coreconfig.h to Include/cpython/coreconfig.h * coreconfig.h header is now excluded from Py_LIMITED_API * Move functions to pycore_coreconfig.h
* bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). ↵Eric Snow2019-02-241-25/+20
| | | | | | | (GH-11617) This involves moving the global "pending calls" state to PyInterpreterState. https://bugs.python.org/issue33608
* bpo-35886: Make PyInterpreterState an opaque type in the public API. (GH-11731)Eric Snow2019-02-231-0/+11
| | | Move PyInterpreterState into the "internal" header files.
* bpo-35993: Fix _PyInterpreterState_DeleteExceptMain() (GH-11852)Stéphane Wirtel2019-02-201-2/+5
| | | Fix a crash on fork when using subinterpreters.
* bpo-35972: _xxsubinterpreters: Fix potential integer truncation on 32-bit in ↵Alexey Izbyshev2019-02-121-2/+6
| | | | channel_send() (gh-11822)
* bpo-34569: Fix subinterpreter 32-bit ABI, pystate.c/_new_long_object() ↵Michael Felt2019-01-111-1/+1
| | | | | | (gh-9127) This fixes ShareableTypeTests.test_int() in Lib/test/test__xxsubinterpreters.py.
* bpo-35414: Add a missing Py_INCREF(Py_None) in PyState_RemoveModule(). ↵Zackery Spytz2018-12-051-0/+1
| | | | (GH-10914)
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-2/+2
| | | | | | | | | | | | | | Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
* bpo-35081: Add _PyThreadState_GET() internal macro (GH-10266)Victor Stinner2018-11-011-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access _PyRuntime which comes from the internal pycore_state.h header. Public headers must not require internal headers. Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from Include/pystate.h to Include/internal/pycore_state.h, and rename PyThreadState_GET() to _PyThreadState_GET() there. The PyThreadState_GET() macro of pystate.h is now redefined when pycore_state.h is included, to use the fast _PyThreadState_GET(). Changes: * Add _PyThreadState_GET() macro * Replace "PyThreadState_GET()->interp" with _PyInterpreterState_GET_UNSAFE() * Replace PyThreadState_GET() with _PyThreadState_GET() in internal C files (compiled with Py_BUILD_CORE defined), but keep PyThreadState_GET() in the public header files. * _testcapimodule.c: replace PyThreadState_GET() with PyThreadState_Get(); the module is not compiled with Py_BUILD_CORE defined. * pycore_state.h now requires Py_BUILD_CORE to be defined.
* bpo-35081: Add pycore_ prefix to internal header files (GH-10263)Victor Stinner2018-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | * Rename Include/internal/ header files: * pyatomic.h -> pycore_atomic.h * ceval.h -> pycore_ceval.h * condvar.h -> pycore_condvar.h * context.h -> pycore_context.h * pygetopt.h -> pycore_getopt.h * gil.h -> pycore_gil.h * hamt.h -> pycore_hamt.h * hash.h -> pycore_hash.h * mem.h -> pycore_mem.h * pystate.h -> pycore_state.h * warnings.h -> pycore_warnings.h * PCbuild project, Makefile.pre.in, Modules/Setup: add the Include/internal/ directory to the search paths of header files. * Update includes. For example, replace #include "internal/mem.h" with #include "pycore_mem.h".
* bpo-35081: Move Py_BUILD_CORE code to internal/mem.h (GH-10249)Victor Stinner2018-10-311-0/+1
| | | | | * Add #include "internal/mem.h" to C files using _PyMem_SetDefaultAllocator(). * Include/internal/mem.h now requires Py_BUILD_CORE to be defined.
* bpo-35081: Cleanup pystate.c and pystate.h (GH-10240)Victor Stinner2018-10-301-23/+20
| | | | | | | | | | | | * Remove _PyThreadState_Current * Replace GET_TSTATE() with PyThreadState_GET() * Replace GET_INTERP_STATE() with _PyInterpreterState_GET_UNSAFE() * Replace direct access to _PyThreadState_Current with PyThreadState_GET() * Replace _PyThreadState_Current with _PyRuntime.gilstate.tstate_current * Rename SET_TSTATE() to _PyThreadState_SET(), name more consistent with _PyThreadState_GET() * Update outdated comments
* bpo-34651: Only allow the main interpreter to fork. (gh-9279)Eric Snow2018-09-141-0/+38
| | | | | When os.fork() is called (on platforms that support it) all threads but the current one are destroyed in the child process. Consequently we must ensure that all but the associated interpreter are likewise destroyed. The main interpreter is critical for runtime operation, so we must ensure that fork only happens in the main interpreter. https://bugs.python.org/issue34651
* bpo-34408: Prevent a null pointer dereference and resource leakage in ↵Pablo Galindo2018-08-311-6/+10
| | | | | | | `PyInterpreterState_New()` (GH-8767) * A pointer in `PyInterpreterState_New()` could have been `NULL` when being dereferenced. * Memory was leaked in `PyInterpreterState_New()` when taking some error-handling code path.
* bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)Victor Stinner2018-08-031-4/+18
| | | | sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
* bpo-34170: Add _PyCoreConfig.bytes_warning (GH-8447)Victor Stinner2018-07-241-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add more fields to _PyCoreConfig: * _check_hash_pycs_mode * bytes_warning * debug * inspect * interactive * legacy_windows_fs_encoding * legacy_windows_stdio * optimization_level * quiet * unbuffered_stdio * user_site_directory * verbose * write_bytecode Changes: * Remove pymain_get_global_config() and pymain_set_global_config() which became useless. These functions have been replaced by _PyCoreConfig_GetGlobalConfig() and _PyCoreConfig_SetGlobalConfig(). * sys.flags.dont_write_bytecode value is now restricted to 1 even if -B option is specified multiple times on the command line. * PyThreadState_Clear() now uses the config from the current interpreter rather than using global Py_VerboseFlag
* bpo-33615: Re-enable a subinterpreter test. (gh-7251)Eric Snow2018-06-021-18/+37
| | | For bpo-32604 I added extra subinterpreter-related tests (see #6914), which caused a few buildbots to crash. This patch fixes the crash by ensuring that refcounts in channels are handled properly.
* bpo-33612: Remove PyThreadState_Clear() assertion (#7069)Victor Stinner2018-05-231-1/+0
| | | | | bpo-25612, bpo-33612: Remove an assertion from PyThreadState_Clear() which failed at Python shutdown or on fork if a thread was running a generator.