summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)Victor Stinner2021-10-121-0/+1
| | | | | | | * Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
* bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)Victor Stinner2021-10-111-1/+1
| | | | | Fix typo in the private _PyObject_CallNoArg() function name: rename it to _PyObject_CallNoArgs() to be consistent with the public function PyObject_CallNoArgs().
* Typo in comment (GH-24199)borispopoff2021-01-251-1/+1
| | | Automerge-Triggered-By: GH:Mariatta
* bpo-32381: pymain_run_command() uses PyCF_IGNORE_COOKIE (GH-23724)Victor Stinner2020-12-231-19/+23
| | | | | | | | | | The coding cookie (ex: "# coding: latin1") is now ignored in the command passed to the -c command line option. Since pymain_run_command() uses UTF-8, pass PyCF_IGNORE_COOKIE compiler flag to the parser. pymain_run_python() no longer propages compiler flags between function calls.
* bpo-32381: pymain_run_file() uses PySys_FormatStderr() (GH-23778)Victor Stinner2020-12-151-17/+34
| | | | | If config->run_filename doesn't exist, log the error into sys.stderr using "%R" format, to escape properly unencodable characters (usually with backslashreplace).
* bpo-32381: Add _PyRun_AnyFileObject() (GH-23723)Victor Stinner2020-12-091-27/+8
| | | | | | | | | | pymain_run_file() no longer encodes the filename: pass the filename as an object to the new _PyRun_AnyFileObject() function. Add new private functions: * _PyRun_AnyFileObject() * _PyRun_InteractiveLoopObject() * _Py_FdIsInteractive()
* bpo-32381: Add _PyRun_SimpleFileObject() (GH-23709)Victor Stinner2020-12-081-27/+14
| | | | pymain_run_startup() now pass the filename as a Python object to _PyRun_SimpleFileObject().
* bpo-41602: raise SIGINT exit code on KeyboardInterrupt from ↵Thomas Grainger2020-09-221-0/+4
| | | | | pymain_run_module (#21956) Closes bpo issue 41602
* bpo-41094: Additional fix for PYTHONSTARTUP. (GH-21119)Serhiy Storchaka2020-06-241-9/+43
|
* bpo-41094: Fix decoding errors with audit when open files. (GH-21095)Serhiy Storchaka2020-06-241-1/+8
|
* bpo-40268: Remove unused imports in pylifecycle.c (GH-19533)Victor Stinner2020-04-151-9/+9
| | | | | | | | | | Remove unused imports in files: * initconfig.c * main.c * preconfig.h * pylifecycle.c * python.c * pythonrun.c
* bpo-40268: Remove unused pycore_pymem.h includes (GH-19531)Victor Stinner2020-04-151-1/+0
|
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+1
|
* bpo-40268: Rename _PyInterpreterState_GET_UNSAFE() (GH-19509)Victor Stinner2020-04-141-1/+1
| | | | | | | Rename _PyInterpreterState_GET_UNSAFE() to _PyInterpreterState_GET() for consistency with _PyThreadState_GET() and to have a shorter name (help to fit into 80 columns). Add also "assert(tstate != NULL);" to the function.
* bpo-40268: Include explicitly pycore_interp.h (GH-19505)Victor Stinner2020-04-141-0/+1
| | | | pycore_pystate.h no longer includes pycore_interp.h: it's now included explicitly in files accessing PyInterpreterState.
* bpo-40268: Add _PyInterpreterState_GetConfig() (GH-19492)Victor Stinner2020-04-131-2/+2
| | | | | | | | Don't access PyInterpreterState.config member directly anymore, but use new functions: * _PyInterpreterState_GetConfig() * _PyInterpreterState_SetConfig() * _Py_GetConfig()
* bpo-38353: Cleanup includes in the internal C API (GH-16548)Victor Stinner2019-10-021-0/+1
| | | | Use forward declaration of types to avoid includes in the internal C API. Add also comment to justify other includes.
* bpo-37474: Don't call fedisableexcept() on FreeBSD (GH-16515)Victor Stinner2019-10-011-13/+0
| | | | | On FreeBSD, Python no longer calls fedisableexcept() at startup to control the floating point control mode. The call became useless since FreeBSD 6: it became the default mode.
* bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (GH-16509)Victor Stinner2019-10-011-5/+1
| | | | 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-7/+2
| | | | | | | 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-1/+8
| | | | | | | | | | | | | | | | | 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-15999: Clean up of handling boolean arguments. (GH-15610)Serhiy Storchaka2019-09-011-1/+1
| | | | | | * 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.
* bpo-37363: Add audit events on startup for the run commands (GH-14524)Steve Dower2019-07-011-0/+21
|
* bpo-36763: Use PyConfig_Clear() (GH-14445)Victor Stinner2019-07-011-4/+8
| | | | | Stop using "static PyConfig", PyConfig must now always use dynamically allocated strings: use PyConfig_SetString(), PyConfig_SetArgv() and PyConfig_Clear().
* bpo-37253: Add _PyCompilerFlags_INIT macro (GH-14018)Victor Stinner2019-06-131-1/+1
| | | | | Add a new _PyCompilerFlags_INIT macro to initialize PyCompilerFlags variables, rather than initializing cf_flags and cf_feature_version explicitly in each variable.
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-45/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-36965: Fix includes in main.c on Windows with non-MSC compilers (GH-13421)Erik Janssens2019-05-211-2/+2
| | | | Include windows.h rather than crtdbg.h to get STATUS_CONTROL_C_EXIT constant. Moreover, include windows.h on Windows, not only when MSC is used.
* bpo-36763: _Py_RunMain() doesn't call Py_Exit() anymore (GH-13390)Victor Stinner2019-05-171-46/+75
| | | | | | | | | Py_Main() and _Py_RunMain() now return the exitcode rather than calling Py_Exit(exitcode) when calling PyErr_Print() if the current exception type is SystemExit. * Add _Py_HandleSystemExit(). * Add pymain_exit_err_print(). * Add pymain_exit_print().
* bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)Victor Stinner2019-05-171-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Remove _PyCoreConfig.program (GH-13373)Victor Stinner2019-05-171-2/+2
| | | Use _PyCoreConfig.program_name instead.
* bpo-36763: Add _PyCoreConfig.parse_argv (GH-13361)Victor Stinner2019-05-161-1/+1
| | | | | | | * _PyCoreConfig_Read() doesn't parse nor update argv if parse_argv is 0. * Move path configuration fields in _PyCoreConfig. * Add an unit test for parse_argv=0. * Remove unused "done": label in _Py_RunMain().
* bpo-36763: _PyInitError always use int for exitcode (GH-13360)Victor Stinner2019-05-161-26/+22
| | | | | | | | | | | | | | | | | We cannot use "unsigned int" for exitcode on Windows, since Py_Main() and _Py_RunMain() always return an "int". Changes: * _PyPathConfig_ComputeSysPath0() now returns -1 if an exception is raised. * pymain_run_python() no longer uses _PyInitError but display the exception and set exitcode to 1 in case of error. * Fix _Py_RunMain(): return an exitcode rather than calling exit() on pymain_run_python() failure. * _Py_ExitInitError() no longer uses ExitProcess() on Windows, use exit() on all platforms. * _Py_ExitInitError() now fails with a fatal error if 'err' is not an error not an exit.
* bpo-36900: Replace global conf vars with config (GH-13299)Victor Stinner2019-05-141-5/+5
| | | | | | Replace global configuration variables with core_config read from the current interpreter. Cleanup dynload_hpux.c.
* bpo-36763: _PyCoreConfig_SetPyArgv() preinitializes Python (GH-13037)Victor Stinner2019-05-021-8/+1
| | | | | | | | _PyCoreConfig_SetPyArgv() and _PyCoreConfig_SetWideString() now pre-initialize Python if needed to ensure that the locale encoding is properly configured. * Add _Py_PreInitializeFromPyArgv() internal function. * Add 'args' parameter to _Py_PreInitializeFromCoreConfig()
* bpo-36763: Rework _PyInitError API (GH-13031)Victor Stinner2019-05-011-1/+1
| | | | | | | | | * Remove _PyInitError.user_err field and _Py_INIT_USER_ERR() macro: use _Py_INIT_ERR() instead. _Py_ExitInitError() now longer calls abort() on error: exit with exit code 1 instead. * Add _PyInitError._type private field. * exitcode field type is now unsigned int on Windows. * Rename prefix field to _func. * Rename msg field to err_msg.
* Revert "bpo-36356: Destroy the GIL at exit (GH-12453)" (GH613006)Victor Stinner2019-04-291-6/+5
| | | This reverts commit b36e5d627d4232a01850707eb78a5067f3fd77f4.
* bpo-36356: Destroy the GIL at exit (GH-12453)Victor Stinner2019-04-291-5/+6
| | | | | | * Add _PyEval_FiniThreads2(). _PyEval_FiniThreads() now only clears the pending lock, whereas _PyEval_FiniThreads2() destroys the GIL. * pymain_free() now calls _PyEval_FiniThreads2(). * Py_FinalizeEx() now calls _PyEval_FiniThreads().
* bpo-36356: pymain_exit_error() only call pymain_free() for exit (GH-12968)Victor Stinner2019-04-261-1/+6
| | | Add _Py_INIT_HAS_EXITCODE() macro.
* bpo-20844: open script file with "rb" mode (GH-12616)Inada Naoki2019-04-011-1/+1
|
* bpo-36471: Add _Py_RunMain() (GH-12618)Victor Stinner2019-03-291-12/+22
| | | | | * Add config_read_cmdline() subfunction. Remove _PyCmdline structure. * _PyCoreConfig_Read() now also parses config->argv command line arguments
* bpo-36443: Disable C locale coercion and UTF-8 Mode by default (GH-12589)Victor Stinner2019-03-271-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | bpo-36443, bpo-36202: Since Python 3.7.0, calling Py_DecodeLocale() before Py_Initialize() produces mojibake if the LC_CTYPE locale is coerced and/or if the UTF-8 Mode is enabled by the user configuration. This change fix the issue by disabling LC_CTYPE coercion and UTF-8 Mode by default. They must now be enabled explicitly (opt-in) using the new _Py_PreInitialize() API with _PyPreConfig. When embedding Python, set coerce_c_locale and utf8_mode attributes of _PyPreConfig to -1 to enable automatically these parameters depending on the LC_CTYPE locale, environment variables and command line arguments Alternative: Setting Py_UTF8Mode to 1 always explicitly enables the UTF-8 Mode. Changes: * _PyPreConfig_INIT now sets coerce_c_locale and utf8_mode to 0 by default. * _Py_InitializeFromArgs() and _Py_InitializeFromWideArgs() can now be called with config=NULL.
* bpo-36444: Rework _Py_InitializeFromConfig() API (GH-12576)Victor Stinner2019-03-271-41/+19
|
* bpo-36444: Add _PyCoreConfig._init_main (GH-12572)Victor Stinner2019-03-271-19/+10
| | | | | | | | * Add _PyCoreConfig._init_main: if equals to zero, _Py_InitializeFromConfig() doesn't call _Py_InitializeMainInterpreter(). * Add interp_p parameter to _Py_InitializeFromConfig(). * pymain_init() now calls _Py_InitializeFromConfig(). * Make _Py_InitializeCore() private.
* bpo-36444: Remove _PyMainInterpreterConfig (GH-12571)Victor Stinner2019-03-271-269/+1
|
* bpo-36301: Cleanup preconfig.c and coreconfig.c (GH-12563)Victor Stinner2019-03-261-11/+7
| | | | | | | | | | | | | | | * _PyCoreConfig_Write() now updates _PyRuntime.preconfig * Remove _PyPreCmdline_Copy() * _PyPreCmdline_Read() now accepts _PyPreConfig and _PyCoreConfig optional configurations. * Rename _PyPreConfig_ReadFromArgv() to _PyPreConfig_Read(). Simplify the code. * Calling _PyCoreConfig_Read() no longer adds the warning options twice: don't add a warning option if it's already in the list. * Rename _PyCoreConfig_ReadFromArgv() to _PyCoreConfig_Read(). * Rename config_from_cmdline() to _PyCoreConfig_ReadFromArgv(). * Add more assertions on _PyCoreConfig in _PyCoreConfig_Read(). * Move some functions. * Make some config functions private.
* bpo-36301: Remove _PyCoreConfig.preconfig (GH-12546)Victor Stinner2019-03-261-10/+5
| | | | | | * Replace _PyCoreConfig.preconfig with 3 new fields in _PyCoreConfig: isolated, use_environment, dev_mode. * Add _PyPreCmdline.dev_mode. * Add _Py_PreInitializeFromPreConfigInPlace().
* bpo-36301: Add _Py_GetEnv() function (GH-12542)Victor Stinner2019-03-251-2/+2
| | | | | * Make _PyPreConfig_GetEnv(), _PyCoreConfig_GetEnv() and _PyCoreConfig_GetEnvDup() private * _Py_get_env_flag() first parameter becomes "int use_environment"
* bpo-36301: Cleanup preconfig code (GH-12535)Victor Stinner2019-03-251-18/+23
| | | | | | | | | | | | | | | Prepare code to move some _PyPreConfig parameters into _PyPreCmdline. Changes: * _PyCoreConfig_ReadFromArgv(): remove preconfig parameter, use _PyRuntime.preconfig. * Add _PyPreCmdline_GetPreConfig() (called by _PyPreConfig_Read()). * Rename _PyPreCmdline_Init() to _PyPreCmdline_SetArgv() * Factorize _Py_PreInitializeFromPreConfig() code: add pyinit_preinit(). * _PyPreConfig_Read() now sets coerce_c_locale to 2 if it must be coerced. * Remove _PyCoreConfig_ReadPreConfig(). * _PyCoreConfig_Write() now copies updated preconfig into _PyRuntime.
* bpo-36301: Add _PyRuntime.pre_initialized (GH-12457)Victor Stinner2019-03-201-19/+10
| | | | | | | | | * Add _PyRuntime.pre_initialized: set to 1 when Python is pre-initialized * Add _Py_PreInitialize() and _Py_PreInitializeFromPreConfig(). * _PyCoreConfig_Read() now calls _Py_PreInitialize(). * Move _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig() calls from main.c to preconfig.c and coreconfig.c.
* bpo-36236: Handle removed cwd at Python init (GH-12424)Victor Stinner2019-03-191-9/+11
| | | | | | | | At Python initialization, the current directory is no longer prepended to sys.path if it has been removed. Rename _PyPathConfig_ComputeArgv0() to _PyPathConfig_ComputeSysPath0() to avoid confusion between argv[0] and sys.path[0].