summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-38644: Pass tstate to _Py_FinishPendingCalls() (GH-17990)Victor Stinner2020-01-131-1/+1
| | | | _Py_FinishPendingCalls() now expects a tstate argument, instead of a runtime argument.
* closes bpo-39261: Remove dead assignment from pyinit_config. (GH-17907)Alex Henrie2020-01-091-1/+0
|
* bpo-13601: always use line-buffering for sys.stderr (GH-17646)Jendrik Seipp2020-01-011-1/+1
|
* bpo-38858: Small integer per interpreter (GH-17315)Victor Stinner2019-12-171-4/+9
| | | | | | | | | | | | Each Python subinterpreter now has its own "small integer singletons": numbers in [-5; 257] range. It is no longer possible to change the number of small integers at build time by overriding NSMALLNEGINTS and NSMALLPOSINTS macros: macros should now be modified manually in pycore_pystate.h header file. For now, continue to share _PyLong_Zero and _PyLong_One singletons between all subinterpreters.
* bpo-38858: Fix ref leak in pycore_interp_init() (GH-17512)Victor Stinner2019-12-081-5/+10
| | | | | bpo-38858, bpo-38997: _PySys_Create() returns a strong reference to the sys module: Py_DECREF() is needed when we are done with the module.
* bpo-38858: Add pycore_interp_init() code to factorize code (GH-17483)Victor Stinner2019-12-061-32/+24
| | | | Add a new pycore_interp_init() function called by new_interpreter() and pyinit_config().
* bpo-38858: new_interpreter() reuses _PySys_Create() (GH-17481)Victor Stinner2019-12-061-49/+32
| | | | | | | new_interpreter() now calls _PySys_Create() to create a new sys module isolated from the main interpreter. It now calls _PySys_InitCore() and _PyImport_FixupBuiltin(). init_interp_main() now calls _PySys_InitMain().
* Remove unused variable in Python/pylifecycle.c (GH-17475)Pablo Galindo2019-12-051-2/+0
|
* bpo-38962: Fix reference leak in the per-subinterpreter gc (GH-17457)Pablo Galindo2019-12-041-6/+5
| | | | | | | https://bugs.python.org/issue38962 Automerge-Triggered-By: @pablogsal
* bpo-38962: Fix reference leak in new_interpreter() (GH-17453)Pablo Galindo2019-12-041-0/+2
| | | | | | | https://bugs.python.org/issue38962 Automerge-Triggered-By: @pablogsal
* bpo-38858: new_interpreter() uses pycore_init_import_warnings() (GH-17353)Victor Stinner2019-11-221-14/+11
|
* bpo-38858: new_interpreter() reuses pycore_init_builtins() (GH-17351)Victor Stinner2019-11-221-29/+24
| | | | | | | | | new_interpreter() now calls _PyBuiltin_Init() to create the builtins module and calls _PyImport_FixupBuiltin(), rather than using _PyImport_FindBuiltin(tstate, "builtins"). pycore_init_builtins() is now responsible to initialize intepr->builtins_copy: inline _PyImport_Init() and remove this function.
* bpo-38858: Add init_interp_main() subfunction (GH-17347)Victor Stinner2019-11-221-103/+109
| | | | Fix new_interpreter() error handling: undo it all if status is an exception.
* bpo-38858: Add init_set_builtins_open() subfunction (GH-17346)Victor Stinner2019-11-221-18/+50
|
* bpo-38858: Call _PyUnicode_Fini() in Py_EndInterpreter() (GH-17330)Victor Stinner2019-11-221-5/+5
| | | Py_EndInterpreter() now clears the filesystem codec.
* bpo-36854: Fix refleak in subinterpreter (GH-17331)Victor Stinner2019-11-221-0/+8
| | | | finalize_interp_clear() now explicitly clears the codec registry and then trigger a GC collection to clear all references.
* bpo-38858: Fix Py_Finalize() when called from a subinterpreter (GH-17297)Victor Stinner2019-11-201-11/+18
| | | | Use _Py_IsMainInterpreter() in Py_Initialize() and Py_Finalize() to detect if the current interpreter is the main interpreter or not.
* bpo-37340: Remove PyMethod_ClearFreeList() and PyCFunction_ClearFreeList() ↵Victor Stinner2019-11-201-2/+0
| | | | | | | | (GH-17284) Remove PyMethod_ClearFreeList() and PyCFunction_ClearFreeList() functions: the free lists of bound method objects have been removed. Remove also _PyMethod_Fini() and _PyCFunction_Fini() functions.
* bpo-36854: Move _PyRuntimeState.gc to PyInterpreterState (GH-17287)Victor Stinner2019-11-201-1/+2
| | | | | * Rename _PyGC_InitializeRuntime() to _PyGC_InitState() * finalize_interp_clear() now also calls _PyGC_Fini() in subinterpreters (clear the GC state).
* bpo-38858: Fix reference leak in pycore_init_types() (GH-17286)Victor Stinner2019-11-201-20/+26
| | | | Only call _PyGC_Init(), _PyExc_Init() and _PyErr_Init() in new_interpreter().
* bpo-36854: Clear the current thread later (GH-17279)Victor Stinner2019-11-201-4/+1
| | | | | | | | | | Clear the current thread later in the Python finalization. * The PyInterpreterState_Delete() function is now responsible to call PyThreadState_Swap(NULL). * The tstate_delete_common() function is now responsible to clear the "autoTSSKey" thread local storage and it only clears it once the thread state is fully cleared. It allows to still get the current thread from TSS in tstate_delete_common().
* bpo-38858: Factorize Py_EndInterpreter() code (GH-17273)Victor Stinner2019-11-201-52/+76
| | | | | | * Factorize code in common between Py_FinalizeEx() and Py_EndInterpreter(). * Py_EndInterpreter() now also calls _PyWarnings_Fini(). * Call _PyExc_Fini() and _PyGC_Fini() later in the finalization.
* bpo-36710: Add PyInterpreterState.runtime field (GH-17270)Victor Stinner2019-11-201-11/+12
| | | | | | | | | | | Add PyInterpreterState.runtime field: reference to the _PyRuntime global variable. This field exists to not have to pass runtime in addition to tstate to a function. Get runtime from tstate: tstate->interp->runtime. Remove "_PyRuntimeState *runtime" parameter from functions already taking a "PyThreadState *tstate" parameter. _PyGC_Init() first parameter becomes "PyThreadState *tstate".
* bpo-38631: Avoid Py_FatalError() in handle_legacy_finalizers() (GH-17266)Victor Stinner2019-11-201-4/+11
| | | | | * Rename _PyGC_Initialize() to _PyGC_InitializeRuntime() * Add _PyGC_Init(): initialize _PyRuntime.gc.garbage list * Call _PyGC_Init() before _PyTypes_Init()
* bpo-38858: Reorganize pycore_init_types() (GH-17265)Victor Stinner2019-11-191-20/+11
| | | | * Call _PyLong_Init() and _PyExc_Init() earlier * new_interpreter() reuses pycore_init_types()
* bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (GH-16509)Victor Stinner2019-10-011-10/+2
| | | | PyConfig_InitPythonConfig() and PyConfig_InitIsolatedConfig() no longer return PyStatus: they cannot fail anymore.
* bpo-38304: Remove PyConfig.struct_size (GH-16500) (GH-16508)Victor Stinner2019-10-011-8/+1
| | | | | | | For now, we'll rely on the fact that the config structures aren't covered by the stable ABI. We may revisit this in the future if we further explore the idea of offering a stable embedding API. (cherry picked from commit bdace21b769998396d0ccc8da99a8ca9b507bfdf)
* bpo-38304: Add PyConfig.struct_size (GH-16451)Victor Stinner2019-09-281-4/+25
| | | | | | | | | | | | | | | | | Add a new struct_size field to PyPreConfig and PyConfig structures to allow to modify these structures in the future without breaking the backward compatibility. * Replace private _config_version field with public struct_size field in PyPreConfig and PyConfig. * Public PyPreConfig_InitIsolatedConfig() and PyPreConfig_InitPythonConfig() return type becomes PyStatus, instead of void. * Internal _PyConfig_InitCompatConfig(), _PyPreConfig_InitCompatConfig(), _PyPreConfig_InitFromConfig(), _PyPreConfig_InitFromPreConfig() return type becomes PyStatus, instead of void. * Remove _Py_CONFIG_VERSION * Update the Initialization Configuration documentation.
* bpo-38234: Py_Initialize() sets global path configuration (GH-16421)Victor Stinner2019-09-261-2/+2
| | | | | | * Py_InitializeFromConfig() now writes PyConfig path configuration to the global path configuration (_Py_path_config). * Add test_embed.test_get_pathconfig(). * Fix typo in _PyWideStringList_Join().
* bpo-38234: Remove _PyPathConfig.dll_path (GH-16307)Victor Stinner2019-09-201-2/+2
| | | | | | | | | The DLL path is not computed from any user configuration and cannot be configured by PyConfig. Instead, add a new _Py_dll_path global variable. Remove _PyConfig_SetPathConfig(): replaced with _PyPathConfig_Init(). Py_Initialize() now longer sets the "global path configuration", but only initialize _Py_dll_path.
* bpo-38070: Py_FatalError() logs runtime state (GH-16246)Victor Stinner2019-09-171-26/+59
|
* bpo-38070: Add _PyRuntimeState.preinitializing (GH-16245)Victor Stinner2019-09-171-3/+8
| | | | | | Add _PyRuntimeState.preinitializing field: set to 1 while Py_PreInitialize() is running. _PyRuntimeState: rename also pre_initialized field to preinitialized.
* bpo-15999: Clean up of handling boolean arguments. (GH-15610)Serhiy Storchaka2019-09-011-2/+2
| | | | | | * Use the 'p' format unit instead of manually called PyObject_IsTrue(). * Pass boolean value instead 0/1 integers to functions that needs boolean. * Convert some arguments to boolean only once.
* Make PyXXX_Fini() functions private (GH-15531)Victor Stinner2019-08-261-12/+12
| | | | | For example, rename PyTuple_Fini() to _PyTuple_Fini(). These functions are only declared in the internal C API.
* bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer2019-07-081-5/+5
|
* bpo-36710: Use tstate in pylifecycle.c (GH-14249)Victor Stinner2019-06-191-88/+99
| | | | In pylifecycle.c: pass tstate argument, rather than interp argument, to functions.
* bpo-36710: Remove PyImport_Cleanup() function (GH-14221)Victor Stinner2019-06-191-2/+2
| | | | | | | * Rename PyImport_Cleanup() to _PyImport_Cleanup() and move it to the internal C API. Add 'tstate' parameters. * Remove documentation of _PyImport_Init(), PyImport_Cleanup(), _PyImport_Fini(). All three were documented as "For internal use only.".
* bpo-36710: Add tstate parameter in import.c (GH-14218)Victor Stinner2019-06-191-7/+8
| | | | | | | | | | | | | * 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.
* bpo-36710: Pass explicitly tstate in sysmodule.c (GH-14060)Victor Stinner2019-06-131-2/+3
| | | | | | | | * Replace global var Py_VerboseFlag with interp->config.verbose. * Add _PyErr_NoMemory(tstate) function. * Add tstate parameter to _PyEval_SetCoroutineOriginTrackingDepth() and move the function to the internal API. * Replace _PySys_InitMain(runtime, interp) with _PySys_InitMain(runtime, tstate).
* Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" (GH-13795)Victor Stinner2019-06-041-8/+7
| | | This reverts commit 396e0a8d9dc65453cb9d53500d0a620602656cfe.
* Revert "bpo-33608: Factor out a private, per-interpreter ↵Victor Stinner2019-06-031-24/+5
| | | | | _Py_AddPendingCall(). (gh-13714)" (GH-13780) This reverts commit 6a150bcaeb190d1731b38ab9c7a5d1a352847ddc.
* bpo-26219: per opcode cache for LOAD_GLOBAL (GH-12884)Inada Naoki2019-06-031-0/+3
| | | | | | This patch implements per opcode cache mechanism, and use it in only LOAD_GLOBAL opcode. Based on Yury's opcache3.patch in bpo-26219.
* bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). ↵Eric Snow2019-06-011-5/+24
| | | | (gh-13714)
* bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)Eric Snow2019-06-011-7/+8
| | | https://bugs.python.org/issue36818
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-362/+327
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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/+7
| | | Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
* bpo-36763: Rename private Python initialization functions (GH-13511)Victor Stinner2019-05-221-58/+50
| | | | | | | | | | | * Rename private C functions: * _Py_Initialize_ReconfigureCore => pyinit_core_reconfigure * _Py_InitializeCore_impl => pyinit_core_config * _Py_InitializeCore = > pyinit_core * _Py_InitializeMainInterpreter => pyinit_main * init_python => pyinit_python * Rename _testembed.c commands: add "test_" prefix.
* bpo-36763: Add _PyPreConfig._config_init (GH-13481)Victor Stinner2019-05-221-2/+2
| | | | | | | | | | | | | | | | | | | * _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-36829: Add sys.unraisablehook() (GH-13187)Victor Stinner2019-05-221-0/+12
| | | | | | | | | | | | | | | | | | | Add new sys.unraisablehook() function which can be overridden to control how "unraisable exceptions" are handled. It is called when an exception has occurred but there is no way for Python to handle it. For example, when a destructor raises an exception or during garbage collection (gc.collect()). Changes: * Add an internal UnraisableHookArgs type used to pass arguments to sys.unraisablehook. * Add _PyErr_WriteUnraisableDefaultHook(). * The default hook now ignores exception on writing the traceback. * test_sys now uses unittest.main() to automatically discover tests: remove test_main(). * Add _PyErr_Init(). * Fix PyErr_WriteUnraisable(): hold a strong reference to sys.stderr while using it
* bpo-36763: Fix _PyRuntime.preconfig.coerce_c_locale (GH-13444)Victor Stinner2019-05-201-7/+19
| | | | | | | | | | | _PyRuntime.preconfig.coerce_c_locale can now be used to check if the C locale has been coerced. * Fix _Py_LegacyLocaleDetected(): don't attempt to coerce the C locale if LC_ALL environment variable is set. Add 'warn' parameter: emit_stderr_warning_for_legacy_locale() must not the LC_ALL env var. * _PyPreConfig_Write() sets coerce_c_locale to 0 if _Py_CoerceLegacyLocale() fails.