You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2343 lines
63 KiB

bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-1054041: Exit properly after an uncaught ^C. (#11862) * bpo-1054041: Exit properly by a signal after a ^C. An uncaught KeyboardInterrupt exception means the user pressed ^C and our code did not handle it. Programs that install SIGINT handlers are supposed to reraise the SIGINT signal to the SIG_DFL handler in order to exit in a manner that their calling process can detect that they died due to a Ctrl-C. https://www.cons.org/cracauer/sigint.html After this change on POSIX systems while true; do python -c 'import time; time.sleep(23)'; done can be stopped via a simple Ctrl-C instead of the shell infinitely restarting a new python process. What to do on Windows, or if anything needs to be done there has not yet been determined. That belongs in its own PR. TODO(gpshead): A unittest for this behavior is still needed. * Do the unhandled ^C check after pymain_free. * Return STATUS_CONTROL_C_EXIT on Windows. * Fix ifdef around unistd.h include. * 📜🤖 Added by blurb_it. * Add STATUS_CTRL_C_EXIT to the os module on Windows * Add unittests. * Don't send CTRL_C_EVENT in the Windows test. It was causing CI systems to bail out of the entire test suite. See https://dev.azure.com/Python/cpython/_build/results?buildId=37980 for example. * Correct posix test (fail on macOS?) check. * STATUS_CONTROL_C_EXIT must be unsigned. * Improve the error message. * test typo :) * Skip if the bash version is too old. ...and rename the windows test to reflect what it does. * min bash version is 4.4, detect no bash. * restore a blank line i didn't mean to delete. * PyErr_Occurred() before the Py_DECREF(co); * Don't add os.STATUS_CONTROL_C_EXIT as a constant. * Update the Windows test comment. * Refactor common logic into a run_eval_code_obj fn.
7 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
bpo-32030: Split Py_Main() into subfunctions (#4399) * Don't use "Python runtime" anymore to parse command line options or to get environment variables: pymain_init() is now a strict separation. * Use an error message rather than "crashing" directly with Py_FatalError(). Limit the number of calls to Py_FatalError(). It prepares the code to handle errors more nicely later. * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now only added to the sys module once Python core is properly initialized. * _PyMain is now the well identified owner of some important strings like: warnings options, XOptions, and the "program name". The program name string is now properly freed at exit. pymain_free() is now responsible to free the "command" string. * Rename most methods in Modules/main.c to use a "pymain_" prefix to avoid conflits and ease debug. * Replace _Py_CommandLineDetails_INIT with memset(0) * Reorder a lot of code to fix the initialization ordering. For example, initializing standard streams now comes before parsing PYTHONWARNINGS. * Py_Main() now handles errors when adding warnings options and XOptions. * Add _PyMem_GetDefaultRawAllocator() private function. * Cleanup _PyMem_Initialize(): remove useless global constants: move them into _PyMem_Initialize(). * Call _PyRuntime_Initialize() as soon as possible: _PyRuntime_Initialize() now returns an error message on failure. * Add _PyInitError structure and following macros: * _Py_INIT_OK() * _Py_INIT_ERR(msg) * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case * _Py_INIT_FAILED(err)
8 years ago
  1. /* Python interpreter top-level routines, including init/exit */
  2. #include "Python.h"
  3. #include "Python-ast.h"
  4. #undef Yield /* undefine macro conflicting with <winbase.h> */
  5. #include "pycore_coreconfig.h"
  6. #include "pycore_context.h"
  7. #include "pycore_fileutils.h"
  8. #include "pycore_hamt.h"
  9. #include "pycore_pathconfig.h"
  10. #include "pycore_pylifecycle.h"
  11. #include "pycore_pymem.h"
  12. #include "pycore_pystate.h"
  13. #include "grammar.h"
  14. #include "node.h"
  15. #include "token.h"
  16. #include "parsetok.h"
  17. #include "errcode.h"
  18. #include "code.h"
  19. #include "symtable.h"
  20. #include "ast.h"
  21. #include "marshal.h"
  22. #include "osdefs.h"
  23. #include <locale.h>
  24. #ifdef HAVE_SIGNAL_H
  25. #include <signal.h>
  26. #endif
  27. #ifdef MS_WINDOWS
  28. #include "malloc.h" /* for alloca */
  29. #endif
  30. #ifdef HAVE_LANGINFO_H
  31. #include <langinfo.h>
  32. #endif
  33. #ifdef MS_WINDOWS
  34. #undef BYTE
  35. #include "windows.h"
  36. extern PyTypeObject PyWindowsConsoleIO_Type;
  37. #define PyWindowsConsoleIO_Check(op) (PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
  38. #endif
  39. _Py_IDENTIFIER(flush);
  40. _Py_IDENTIFIER(name);
  41. _Py_IDENTIFIER(stdin);
  42. _Py_IDENTIFIER(stdout);
  43. _Py_IDENTIFIER(stderr);
  44. _Py_IDENTIFIER(threading);
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. extern grammar _PyParser_Grammar; /* From graminit.c */
  49. /* Forward */
  50. static _PyInitError add_main_module(PyInterpreterState *interp);
  51. static _PyInitError initfsencoding(PyInterpreterState *interp);
  52. static _PyInitError initsite(void);
  53. static _PyInitError init_sys_streams(PyInterpreterState *interp);
  54. static _PyInitError initsigs(void);
  55. static void call_py_exitfuncs(PyInterpreterState *);
  56. static void wait_for_thread_shutdown(void);
  57. static void call_ll_exitfuncs(void);
  58. int _Py_UnhandledKeyboardInterrupt = 0;
  59. _PyRuntimeState _PyRuntime = _PyRuntimeState_INIT;
  60. static int runtime_initialized = 0;
  61. _PyInitError
  62. _PyRuntime_Initialize(void)
  63. {
  64. /* XXX We only initialize once in the process, which aligns with
  65. the static initialization of the former globals now found in
  66. _PyRuntime. However, _PyRuntime *should* be initialized with
  67. every Py_Initialize() call, but doing so breaks the runtime.
  68. This is because the runtime state is not properly finalized
  69. currently. */
  70. if (runtime_initialized) {
  71. return _Py_INIT_OK();
  72. }
  73. runtime_initialized = 1;
  74. return _PyRuntimeState_Init(&_PyRuntime);
  75. }
  76. void
  77. _PyRuntime_Finalize(void)
  78. {
  79. _PyRuntimeState_Fini(&_PyRuntime);
  80. runtime_initialized = 0;
  81. }
  82. int
  83. _Py_IsFinalizing(void)
  84. {
  85. return _PyRuntime.finalizing != NULL;
  86. }
  87. /* Hack to force loading of object files */
  88. int (*_PyOS_mystrnicmp_hack)(const char *, const char *, Py_ssize_t) = \
  89. PyOS_mystrnicmp; /* Python/pystrcmp.o */
  90. /* PyModule_GetWarningsModule is no longer necessary as of 2.6
  91. since _warnings is builtin. This API should not be used. */
  92. PyObject *
  93. PyModule_GetWarningsModule(void)
  94. {
  95. return PyImport_ImportModule("warnings");
  96. }
  97. /* APIs to access the initialization flags
  98. *
  99. * Can be called prior to Py_Initialize.
  100. */
  101. int
  102. _Py_IsCoreInitialized(void)
  103. {
  104. return _PyRuntime.core_initialized;
  105. }
  106. int
  107. Py_IsInitialized(void)
  108. {
  109. return _PyRuntime.initialized;
  110. }
  111. /* Global initializations. Can be undone by Py_FinalizeEx(). Don't
  112. call this twice without an intervening Py_FinalizeEx() call. When
  113. initializations fail, a fatal error is issued and the function does
  114. not return. On return, the first thread and interpreter state have
  115. been created.
  116. Locking: you must hold the interpreter lock while calling this.
  117. (If the lock has not yet been initialized, that's equivalent to
  118. having the lock, but you cannot use multiple threads.)
  119. */
  120. static char*
  121. get_codec_name(const char *encoding)
  122. {
  123. const char *name_utf8;
  124. char *name_str;
  125. PyObject *codec, *name = NULL;
  126. codec = _PyCodec_Lookup(encoding);
  127. if (!codec)
  128. goto error;
  129. name = _PyObject_GetAttrId(codec, &PyId_name);
  130. Py_CLEAR(codec);
  131. if (!name)
  132. goto error;
  133. name_utf8 = PyUnicode_AsUTF8(name);
  134. if (name_utf8 == NULL)
  135. goto error;
  136. name_str = _PyMem_RawStrdup(name_utf8);
  137. Py_DECREF(name);
  138. if (name_str == NULL) {
  139. PyErr_NoMemory();
  140. return NULL;
  141. }
  142. return name_str;
  143. error:
  144. Py_XDECREF(codec);
  145. Py_XDECREF(name);
  146. return NULL;
  147. }
  148. static _PyInitError
  149. initimport(PyInterpreterState *interp, PyObject *sysmod)
  150. {
  151. PyObject *importlib;
  152. PyObject *impmod;
  153. PyObject *value;
  154. /* Import _importlib through its frozen version, _frozen_importlib. */
  155. if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
  156. return _Py_INIT_ERR("can't import _frozen_importlib");
  157. }
  158. else if (Py_VerboseFlag) {
  159. PySys_FormatStderr("import _frozen_importlib # frozen\n");
  160. }
  161. importlib = PyImport_AddModule("_frozen_importlib");
  162. if (importlib == NULL) {
  163. return _Py_INIT_ERR("couldn't get _frozen_importlib from sys.modules");
  164. }
  165. interp->importlib = importlib;
  166. Py_INCREF(interp->importlib);
  167. interp->import_func = PyDict_GetItemString(interp->builtins, "__import__");
  168. if (interp->import_func == NULL)
  169. return _Py_INIT_ERR("__import__ not found");
  170. Py_INCREF(interp->import_func);
  171. /* Import the _imp module */
  172. impmod = PyInit__imp();
  173. if (impmod == NULL) {
  174. return _Py_INIT_ERR("can't import _imp");
  175. }
  176. else if (Py_VerboseFlag) {
  177. PySys_FormatStderr("import _imp # builtin\n");
  178. }
  179. if (_PyImport_SetModuleString("_imp", impmod) < 0) {
  180. return _Py_INIT_ERR("can't save _imp to sys.modules");
  181. }
  182. /* Install importlib as the implementation of import */
  183. value = PyObject_CallMethod(importlib, "_install", "OO", sysmod, impmod);
  184. if (value == NULL) {
  185. PyErr_Print();
  186. return _Py_INIT_ERR("importlib install failed");
  187. }
  188. Py_DECREF(value);
  189. Py_DECREF(impmod);
  190. return _Py_INIT_OK();
  191. }
  192. static _PyInitError
  193. initexternalimport(PyInterpreterState *interp)
  194. {
  195. PyObject *value;
  196. value = PyObject_CallMethod(interp->importlib,
  197. "_install_external_importers", "");
  198. if (value == NULL) {
  199. PyErr_Print();
  200. return _Py_INIT_ERR("external importer setup failed");
  201. }
  202. Py_DECREF(value);
  203. return _PyImportZip_Init();
  204. }
  205. /* Helper functions to better handle the legacy C locale
  206. *
  207. * The legacy C locale assumes ASCII as the default text encoding, which
  208. * causes problems not only for the CPython runtime, but also other
  209. * components like GNU readline.
  210. *
  211. * Accordingly, when the CLI detects it, it attempts to coerce it to a
  212. * more capable UTF-8 based alternative as follows:
  213. *
  214. * if (_Py_LegacyLocaleDetected()) {
  215. * _Py_CoerceLegacyLocale();
  216. * }
  217. *
  218. * See the documentation of the PYTHONCOERCECLOCALE setting for more details.
  219. *
  220. * Locale coercion also impacts the default error handler for the standard
  221. * streams: while the usual default is "strict", the default for the legacy
  222. * C locale and for any of the coercion target locales is "surrogateescape".
  223. */
  224. int
  225. _Py_LegacyLocaleDetected(void)
  226. {
  227. #ifndef MS_WINDOWS
  228. /* On non-Windows systems, the C locale is considered a legacy locale */
  229. /* XXX (ncoghlan): some platforms (notably Mac OS X) don't appear to treat
  230. * the POSIX locale as a simple alias for the C locale, so
  231. * we may also want to check for that explicitly.
  232. */
  233. const char *ctype_loc = setlocale(LC_CTYPE, NULL);
  234. return ctype_loc != NULL && strcmp(ctype_loc, "C") == 0;
  235. #else
  236. /* Windows uses code pages instead of locales, so no locale is legacy */
  237. return 0;
  238. #endif
  239. }
  240. static const char *_C_LOCALE_WARNING =
  241. "Python runtime initialized with LC_CTYPE=C (a locale with default ASCII "
  242. "encoding), which may cause Unicode compatibility problems. Using C.UTF-8, "
  243. "C.utf8, or UTF-8 (if available) as alternative Unicode-compatible "
  244. "locales is recommended.\n";
  245. static void
  246. _emit_stderr_warning_for_legacy_locale(void)
  247. {
  248. const _PyPreConfig *preconfig = &_PyRuntime.preconfig;
  249. if (preconfig->coerce_c_locale_warn && _Py_LegacyLocaleDetected()) {
  250. PySys_FormatStderr("%s", _C_LOCALE_WARNING);
  251. }
  252. }
  253. typedef struct _CandidateLocale {
  254. const char *locale_name; /* The locale to try as a coercion target */
  255. } _LocaleCoercionTarget;
  256. static _LocaleCoercionTarget _TARGET_LOCALES[] = {
  257. {"C.UTF-8"},
  258. {"C.utf8"},
  259. {"UTF-8"},
  260. {NULL}
  261. };
  262. int
  263. _Py_IsLocaleCoercionTarget(const char *ctype_loc)
  264. {
  265. const _LocaleCoercionTarget *target = NULL;
  266. for (target = _TARGET_LOCALES; target->locale_name; target++) {
  267. if (strcmp(ctype_loc, target->locale_name) == 0) {
  268. return 1;
  269. }
  270. }
  271. return 0;
  272. }
  273. #ifdef PY_COERCE_C_LOCALE
  274. static const char C_LOCALE_COERCION_WARNING[] =
  275. "Python detected LC_CTYPE=C: LC_CTYPE coerced to %.20s (set another locale "
  276. "or PYTHONCOERCECLOCALE=0 to disable this locale coercion behavior).\n";
  277. static void
  278. _coerce_default_locale_settings(int warn, const _LocaleCoercionTarget *target)
  279. {
  280. const char *newloc = target->locale_name;
  281. /* Reset locale back to currently configured defaults */
  282. _Py_SetLocaleFromEnv(LC_ALL);
  283. /* Set the relevant locale environment variable */
  284. if (setenv("LC_CTYPE", newloc, 1)) {
  285. fprintf(stderr,
  286. "Error setting LC_CTYPE, skipping C locale coercion\n");
  287. return;
  288. }
  289. if (warn) {
  290. fprintf(stderr, C_LOCALE_COERCION_WARNING, newloc);
  291. }
  292. /* Reconfigure with the overridden environment variables */
  293. _Py_SetLocaleFromEnv(LC_ALL);
  294. }
  295. #endif
  296. void
  297. _Py_CoerceLegacyLocale(int warn)
  298. {
  299. #ifdef PY_COERCE_C_LOCALE
  300. char *oldloc = NULL;
  301. oldloc = _PyMem_RawStrdup(setlocale(LC_CTYPE, NULL));
  302. if (oldloc == NULL) {
  303. return;
  304. }
  305. const char *locale_override = getenv("LC_ALL");
  306. if (locale_override == NULL || *locale_override == '\0') {
  307. /* LC_ALL is also not set (or is set to an empty string) */
  308. const _LocaleCoercionTarget *target = NULL;
  309. for (target = _TARGET_LOCALES; target->locale_name; target++) {
  310. const char *new_locale = setlocale(LC_CTYPE,
  311. target->locale_name);
  312. if (new_locale != NULL) {
  313. #if !defined(__APPLE__) && !defined(__ANDROID__) && \
  314. defined(HAVE_LANGINFO_H) && defined(CODESET)
  315. /* Also ensure that nl_langinfo works in this locale */
  316. char *codeset = nl_langinfo(CODESET);
  317. if (!codeset || *codeset == '\0') {
  318. /* CODESET is not set or empty, so skip coercion */
  319. new_locale = NULL;
  320. _Py_SetLocaleFromEnv(LC_CTYPE);
  321. continue;
  322. }
  323. #endif
  324. /* Successfully configured locale, so make it the default */
  325. _coerce_default_locale_settings(warn, target);
  326. goto done;
  327. }
  328. }
  329. }
  330. /* No C locale warning here, as Py_Initialize will emit one later */
  331. setlocale(LC_CTYPE, oldloc);
  332. done:
  333. PyMem_RawFree(oldloc);
  334. #endif
  335. }
  336. /* _Py_SetLocaleFromEnv() is a wrapper around setlocale(category, "") to
  337. * isolate the idiosyncrasies of different libc implementations. It reads the
  338. * appropriate environment variable and uses its value to select the locale for
  339. * 'category'. */
  340. char *
  341. _Py_SetLocaleFromEnv(int category)
  342. {
  343. char *res;
  344. #ifdef __ANDROID__
  345. const char *locale;
  346. const char **pvar;
  347. #ifdef PY_COERCE_C_LOCALE
  348. const char *coerce_c_locale;
  349. #endif
  350. const char *utf8_locale = "C.UTF-8";
  351. const char *env_var_set[] = {
  352. "LC_ALL",
  353. "LC_CTYPE",
  354. "LANG",
  355. NULL,
  356. };
  357. /* Android setlocale(category, "") doesn't check the environment variables
  358. * and incorrectly sets the "C" locale at API 24 and older APIs. We only
  359. * check the environment variables listed in env_var_set. */
  360. for (pvar=env_var_set; *pvar; pvar++) {
  361. locale = getenv(*pvar);
  362. if (locale != NULL && *locale != '\0') {
  363. if (strcmp(locale, utf8_locale) == 0 ||
  364. strcmp(locale, "en_US.UTF-8") == 0) {
  365. return setlocale(category, utf8_locale);
  366. }
  367. return setlocale(category, "C");
  368. }
  369. }
  370. /* Android uses UTF-8, so explicitly set the locale to C.UTF-8 if none of
  371. * LC_ALL, LC_CTYPE, or LANG is set to a non-empty string.
  372. * Quote from POSIX section "8.2 Internationalization Variables":
  373. * "4. If the LANG environment variable is not set or is set to the empty
  374. * string, the implementation-defined default locale shall be used." */
  375. #ifdef PY_COERCE_C_LOCALE
  376. coerce_c_locale = getenv("PYTHONCOERCECLOCALE");
  377. if (coerce_c_locale == NULL || strcmp(coerce_c_locale, "0") != 0) {
  378. /* Some other ported code may check the environment variables (e.g. in
  379. * extension modules), so we make sure that they match the locale
  380. * configuration */
  381. if (setenv("LC_CTYPE", utf8_locale, 1)) {
  382. fprintf(stderr, "Warning: failed setting the LC_CTYPE "
  383. "environment variable to %s\n", utf8_locale);
  384. }
  385. }
  386. #endif
  387. res = setlocale(category, utf8_locale);
  388. #else /* !defined(__ANDROID__) */
  389. res = setlocale(category, "");
  390. #endif
  391. _Py_ResetForceASCII();
  392. return res;
  393. }
  394. /* Global initializations. Can be undone by Py_Finalize(). Don't
  395. call this twice without an intervening Py_Finalize() call.
  396. Every call to _Py_InitializeCore, Py_Initialize or Py_InitializeEx
  397. must have a corresponding call to Py_Finalize.
  398. Locking: you must hold the interpreter lock while calling these APIs.
  399. (If the lock has not yet been initialized, that's equivalent to
  400. having the lock, but you cannot use multiple threads.)
  401. */
  402. static _PyInitError
  403. _Py_Initialize_ReconfigureCore(PyInterpreterState **interp_p,
  404. const _PyCoreConfig *core_config)
  405. {
  406. PyThreadState *tstate = _PyThreadState_GET();
  407. if (!tstate) {
  408. return _Py_INIT_ERR("failed to read thread state");
  409. }
  410. PyInterpreterState *interp = tstate->interp;
  411. if (interp == NULL) {
  412. return _Py_INIT_ERR("can't make main interpreter");
  413. }
  414. *interp_p = interp;
  415. _PyCoreConfig_SetGlobalConfig(core_config);
  416. if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) {
  417. return _Py_INIT_ERR("failed to copy core config");
  418. }
  419. core_config = &interp->core_config;
  420. if (core_config->_install_importlib) {
  421. _PyInitError err = _PyCoreConfig_SetPathConfig(core_config);
  422. if (_Py_INIT_FAILED(err)) {
  423. return err;
  424. }
  425. }
  426. return _Py_INIT_OK();
  427. }
  428. static _PyInitError
  429. pycore_init_runtime(const _PyCoreConfig *core_config)
  430. {
  431. if (_PyRuntime.initialized) {
  432. return _Py_INIT_ERR("main interpreter already initialized");
  433. }
  434. _PyCoreConfig_SetGlobalConfig(core_config);
  435. _PyInitError err = _PyRuntime_Initialize();
  436. if (_Py_INIT_FAILED(err)) {
  437. return err;
  438. }
  439. /* Py_Finalize leaves _Py_Finalizing set in order to help daemon
  440. * threads behave a little more gracefully at interpreter shutdown.
  441. * We clobber it here so the new interpreter can start with a clean
  442. * slate.
  443. *
  444. * However, this may still lead to misbehaviour if there are daemon
  445. * threads still hanging around from a previous Py_Initialize/Finalize
  446. * pair :(
  447. */
  448. _PyRuntime.finalizing = NULL;
  449. err = _Py_HashRandomization_Init(core_config);
  450. if (_Py_INIT_FAILED(err)) {
  451. return err;
  452. }
  453. err = _PyInterpreterState_Enable(&_PyRuntime);
  454. if (_Py_INIT_FAILED(err)) {
  455. return err;
  456. }
  457. return _Py_INIT_OK();
  458. }
  459. static _PyInitError
  460. pycore_create_interpreter(const _PyCoreConfig *core_config,
  461. PyInterpreterState **interp_p)
  462. {
  463. PyInterpreterState *interp = PyInterpreterState_New();
  464. if (interp == NULL) {
  465. return _Py_INIT_ERR("can't make main interpreter");
  466. }
  467. *interp_p = interp;
  468. if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) {
  469. return _Py_INIT_ERR("failed to copy core config");
  470. }
  471. core_config = &interp->core_config;
  472. PyThreadState *tstate = PyThreadState_New(interp);
  473. if (tstate == NULL)
  474. return _Py_INIT_ERR("can't make first thread");
  475. (void) PyThreadState_Swap(tstate);
  476. /* We can't call _PyEval_FiniThreads() in Py_FinalizeEx because
  477. destroying the GIL might fail when it is being referenced from
  478. another running thread (see issue #9901).
  479. Instead we destroy the previously created GIL here, which ensures
  480. that we can call Py_Initialize / Py_FinalizeEx multiple times. */
  481. _PyEval_FiniThreads();
  482. /* Auto-thread-state API */
  483. _PyGILState_Init(interp, tstate);
  484. /* Create the GIL */
  485. PyEval_InitThreads();
  486. return _Py_INIT_OK();
  487. }
  488. static _PyInitError
  489. pycore_init_types(void)
  490. {
  491. _PyInitError err = _PyTypes_Init();
  492. if (_Py_INIT_FAILED(err)) {
  493. return err;
  494. }
  495. err = _PyUnicode_Init();
  496. if (_Py_INIT_FAILED(err)) {
  497. return err;
  498. }
  499. if (_PyStructSequence_Init() < 0) {
  500. return _Py_INIT_ERR("can't initialize structseq");
  501. }
  502. if (!_PyLong_Init()) {
  503. return _Py_INIT_ERR("can't init longs");
  504. }
  505. err = _PyExc_Init();
  506. if (_Py_INIT_FAILED(err)) {
  507. return err;
  508. }
  509. if (!_PyFloat_Init()) {
  510. return _Py_INIT_ERR("can't init float");
  511. }
  512. if (!_PyContext_Init()) {
  513. return _Py_INIT_ERR("can't init context");
  514. }
  515. return _Py_INIT_OK();
  516. }
  517. static _PyInitError
  518. pycore_init_builtins(PyInterpreterState *interp)
  519. {
  520. PyObject *bimod = _PyBuiltin_Init();
  521. if (bimod == NULL) {
  522. return _Py_INIT_ERR("can't initialize builtins modules");
  523. }
  524. _PyImport_FixupBuiltin(bimod, "builtins", interp->modules);
  525. interp->builtins = PyModule_GetDict(bimod);
  526. if (interp->builtins == NULL) {
  527. return _Py_INIT_ERR("can't initialize builtins dict");
  528. }
  529. Py_INCREF(interp->builtins);
  530. _PyInitError err = _PyBuiltins_AddExceptions(bimod);
  531. if (_Py_INIT_FAILED(err)) {
  532. return err;
  533. }
  534. return _Py_INIT_OK();
  535. }
  536. static _PyInitError
  537. pycore_init_import_warnings(PyInterpreterState *interp, PyObject *sysmod)
  538. {
  539. _PyInitError err = _PyImport_Init(interp);
  540. if (_Py_INIT_FAILED(err)) {
  541. return err;
  542. }
  543. err = _PyImportHooks_Init();
  544. if (_Py_INIT_FAILED(err)) {
  545. return err;
  546. }
  547. /* Initialize _warnings. */
  548. if (_PyWarnings_Init() == NULL) {
  549. return _Py_INIT_ERR("can't initialize warnings");
  550. }
  551. if (interp->core_config._install_importlib) {
  552. err = _PyCoreConfig_SetPathConfig(&interp->core_config);
  553. if (_Py_INIT_FAILED(err)) {
  554. return err;
  555. }
  556. }
  557. /* This call sets up builtin and frozen import support */
  558. if (interp->core_config._install_importlib) {
  559. err = initimport(interp, sysmod);
  560. if (_Py_INIT_FAILED(err)) {
  561. return err;
  562. }
  563. }
  564. return _Py_INIT_OK();
  565. }
  566. static _PyInitError
  567. _Py_InitializeCore_impl(PyInterpreterState **interp_p,
  568. const _PyCoreConfig *core_config)
  569. {
  570. PyInterpreterState *interp;
  571. _PyCoreConfig_Write(core_config);
  572. _PyInitError err = pycore_init_runtime(core_config);
  573. if (_Py_INIT_FAILED(err)) {
  574. return err;
  575. }
  576. err = pycore_create_interpreter(core_config, &interp);
  577. if (_Py_INIT_FAILED(err)) {
  578. return err;
  579. }
  580. core_config = &interp->core_config;
  581. *interp_p = interp;
  582. err = pycore_init_types();
  583. if (_Py_INIT_FAILED(err)) {
  584. return err;
  585. }
  586. PyObject *sysmod;
  587. err = _PySys_Create(interp, &sysmod);
  588. if (_Py_INIT_FAILED(err)) {
  589. return err;
  590. }
  591. err = pycore_init_builtins(interp);
  592. if (_Py_INIT_FAILED(err)) {
  593. return err;
  594. }
  595. err = pycore_init_import_warnings(interp, sysmod);
  596. if (_Py_INIT_FAILED(err)) {
  597. return err;
  598. }
  599. /* Only when we get here is the runtime core fully initialized */
  600. _PyRuntime.core_initialized = 1;
  601. return _Py_INIT_OK();
  602. }
  603. static _PyInitError
  604. pyinit_preinit(_PyPreConfig *config,
  605. const _PyPreConfig *src_config,
  606. const _PyCoreConfig *coreconfig)
  607. {
  608. _PyInitError err;
  609. _PyPreConfig local_config = _PyPreConfig_INIT;
  610. if (!config) {
  611. config = &local_config;
  612. }
  613. err = _PyRuntime_Initialize();
  614. if (_Py_INIT_FAILED(err)) {
  615. goto done;
  616. }
  617. if (_PyRuntime.pre_initialized) {
  618. /* If it's already configured: ignored the new configuration */
  619. err = _Py_INIT_OK();
  620. goto done;
  621. }
  622. if (src_config) {
  623. if (_PyPreConfig_Copy(config, src_config) < 0) {
  624. err = _Py_INIT_ERR("failed to copy pre config");
  625. goto done;
  626. }
  627. }
  628. err = _PyPreConfig_Read(config, NULL, coreconfig);
  629. if (_Py_INIT_FAILED(err)) {
  630. goto done;
  631. }
  632. err = _PyPreConfig_Write(config);
  633. if (_Py_INIT_FAILED(err)) {
  634. goto done;
  635. }
  636. _PyRuntime.pre_initialized = 1;
  637. err = _Py_INIT_OK();
  638. done:
  639. _PyPreConfig_Clear(&local_config);
  640. return err;
  641. }
  642. _PyInitError
  643. _Py_PreInitialize(void)
  644. {
  645. return pyinit_preinit(NULL, NULL, NULL);
  646. }
  647. _PyInitError
  648. _Py_PreInitializeFromPreConfig(const _PyPreConfig *src_config)
  649. {
  650. return pyinit_preinit(NULL, src_config, NULL);
  651. }
  652. _PyInitError
  653. _Py_PreInitializeInPlace(_PyPreConfig *config)
  654. {
  655. return pyinit_preinit(config, NULL, NULL);
  656. }
  657. _PyInitError
  658. _Py_PreInitializeFromConfig(const _PyCoreConfig *coreconfig)
  659. {
  660. return pyinit_preinit(NULL, NULL, coreconfig);
  661. }
  662. static _PyInitError
  663. pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config,
  664. PyInterpreterState **interp_p)
  665. {
  666. if (_PyCoreConfig_Copy(config, src_config) < 0) {
  667. return _Py_INIT_ERR("failed to copy core config");
  668. }
  669. _PyInitError err = _PyCoreConfig_Read(config);
  670. if (_Py_INIT_FAILED(err)) {
  671. return err;
  672. }
  673. if (!_PyRuntime.core_initialized) {
  674. return _Py_InitializeCore_impl(interp_p, config);
  675. }
  676. else {
  677. return _Py_Initialize_ReconfigureCore(interp_p, config);
  678. }
  679. }
  680. /* Begin interpreter initialization
  681. *
  682. * On return, the first thread and interpreter state have been created,
  683. * but the compiler, signal handling, multithreading and
  684. * multiple interpreter support, and codec infrastructure are not yet
  685. * available.
  686. *
  687. * The import system will support builtin and frozen modules only.
  688. * The only supported io is writing to sys.stderr
  689. *
  690. * If any operation invoked by this function fails, a fatal error is
  691. * issued and the function does not return.
  692. *
  693. * Any code invoked from this function should *not* assume it has access
  694. * to the Python C API (unless the API is explicitly listed as being
  695. * safe to call without calling Py_Initialize first)
  696. */
  697. _PyInitError
  698. _Py_InitializeCore(PyInterpreterState **interp_p,
  699. const _PyCoreConfig *src_config)
  700. {
  701. _PyInitError err;
  702. assert(src_config != NULL);
  703. err = _Py_PreInitializeFromConfig(src_config);
  704. if (_Py_INIT_FAILED(err)) {
  705. return err;
  706. }
  707. _PyCoreConfig local_config = _PyCoreConfig_INIT;
  708. err = pyinit_coreconfig(&local_config, src_config, interp_p);
  709. _PyCoreConfig_Clear(&local_config);
  710. return err;
  711. }
  712. /* Py_Initialize() has already been called: update the main interpreter
  713. configuration. Example of bpo-34008: Py_Main() called after
  714. Py_Initialize(). */
  715. static _PyInitError
  716. _Py_ReconfigureMainInterpreter(PyInterpreterState *interp,
  717. const _PyMainInterpreterConfig *config)
  718. {
  719. if (config->argv != NULL) {
  720. int res = PyDict_SetItemString(interp->sysdict, "argv", config->argv);
  721. if (res < 0) {
  722. return _Py_INIT_ERR("fail to set sys.argv");
  723. }
  724. }
  725. return _Py_INIT_OK();
  726. }
  727. /* Update interpreter state based on supplied configuration settings
  728. *
  729. * After calling this function, most of the restrictions on the interpreter
  730. * are lifted. The only remaining incomplete settings are those related
  731. * to the main module (sys.argv[0], __main__ metadata)
  732. *
  733. * Calling this when the interpreter is not initializing, is already
  734. * initialized or without a valid current thread state is a fatal error.
  735. * Other errors should be reported as normal Python exceptions with a
  736. * non-zero return code.
  737. */
  738. _PyInitError
  739. _Py_InitializeMainInterpreter(PyInterpreterState *interp,
  740. const _PyMainInterpreterConfig *config)
  741. {
  742. if (!_PyRuntime.core_initialized) {
  743. return _Py_INIT_ERR("runtime core not initialized");
  744. }
  745. /* Configure the main interpreter */
  746. if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) {
  747. return _Py_INIT_ERR("failed to copy main interpreter config");
  748. }
  749. config = &interp->config;
  750. _PyCoreConfig *core_config = &interp->core_config;
  751. if (_PyRuntime.initialized) {
  752. return _Py_ReconfigureMainInterpreter(interp, config);
  753. }
  754. if (!core_config->_install_importlib) {
  755. /* Special mode for freeze_importlib: run with no import system
  756. *
  757. * This means anything which needs support from extension modules
  758. * or pure Python code in the standard library won't work.
  759. */
  760. _PyRuntime.initialized = 1;
  761. return _Py_INIT_OK();
  762. }
  763. if (_PyTime_Init() < 0) {
  764. return _Py_INIT_ERR("can't initialize time");
  765. }
  766. if (_PySys_InitMain(interp) < 0) {
  767. return _Py_INIT_ERR("can't finish initializing sys");
  768. }
  769. _PyInitError err = initexternalimport(interp);
  770. if (_Py_INIT_FAILED(err)) {
  771. return err;
  772. }
  773. /* initialize the faulthandler module */
  774. err = _PyFaulthandler_Init(core_config->faulthandler);
  775. if (_Py_INIT_FAILED(err)) {
  776. return err;
  777. }
  778. err = initfsencoding(interp);
  779. if (_Py_INIT_FAILED(err)) {
  780. return err;
  781. }
  782. if (interp->config.install_signal_handlers) {
  783. err = initsigs(); /* Signal handling stuff, including initintr() */
  784. if (_Py_INIT_FAILED(err)) {
  785. return err;
  786. }
  787. }
  788. if (_PyTraceMalloc_Init(core_config->tracemalloc) < 0) {
  789. return _Py_INIT_ERR("can't initialize tracemalloc");
  790. }
  791. err = add_main_module(interp);
  792. if (_Py_INIT_FAILED(err)) {
  793. return err;
  794. }
  795. err = init_sys_streams(interp);
  796. if (_Py_INIT_FAILED(err)) {
  797. return err;
  798. }
  799. /* Initialize warnings. */
  800. PyObject *warnoptions = PySys_GetObject("warnoptions");
  801. if (warnoptions != NULL && PyList_Size(warnoptions) > 0)
  802. {
  803. PyObject *warnings_module = PyImport_ImportModule("warnings");
  804. if (warnings_module == NULL) {
  805. fprintf(stderr, "'import warnings' failed; traceback:\n");
  806. PyErr_Print();
  807. }
  808. Py_XDECREF(warnings_module);
  809. }
  810. _PyRuntime.initialized = 1;
  811. if (core_config->site_import) {
  812. err = initsite(); /* Module site */
  813. if (_Py_INIT_FAILED(err)) {
  814. return err;
  815. }
  816. }
  817. #ifndef MS_WINDOWS
  818. _emit_stderr_warning_for_legacy_locale();
  819. #endif
  820. return _Py_INIT_OK();
  821. }
  822. #undef _INIT_DEBUG_PRINT
  823. _PyInitError
  824. _Py_InitializeFromConfig(const _PyCoreConfig *config)
  825. {
  826. PyInterpreterState *interp = NULL;
  827. _PyInitError err;
  828. err = _Py_InitializeCore(&interp, config);
  829. if (_Py_INIT_FAILED(err)) {
  830. return err;
  831. }
  832. config = &interp->core_config;
  833. _PyMainInterpreterConfig main_config = _PyMainInterpreterConfig_INIT;
  834. err = _PyMainInterpreterConfig_Read(&main_config, config);
  835. if (!_Py_INIT_FAILED(err)) {
  836. err = _Py_InitializeMainInterpreter(interp, &main_config);
  837. }
  838. _PyMainInterpreterConfig_Clear(&main_config);
  839. if (_Py_INIT_FAILED(err)) {
  840. return err;
  841. }
  842. return _Py_INIT_OK();
  843. }
  844. void
  845. Py_InitializeEx(int install_sigs)
  846. {
  847. if (_PyRuntime.initialized) {
  848. /* bpo-33932: Calling Py_Initialize() twice does nothing. */
  849. return;
  850. }
  851. _PyInitError err;
  852. _PyCoreConfig config = _PyCoreConfig_INIT;
  853. config.install_signal_handlers = install_sigs;
  854. err = _Py_InitializeFromConfig(&config);
  855. _PyCoreConfig_Clear(&config);
  856. if (_Py_INIT_FAILED(err)) {
  857. _Py_ExitInitError(err);
  858. }
  859. }
  860. void
  861. Py_Initialize(void)
  862. {
  863. Py_InitializeEx(1);
  864. }
  865. #ifdef COUNT_ALLOCS
  866. extern void _Py_dump_counts(FILE*);
  867. #endif
  868. /* Flush stdout and stderr */
  869. static int
  870. file_is_closed(PyObject *fobj)
  871. {
  872. int r;
  873. PyObject *tmp = PyObject_GetAttrString(fobj, "closed");
  874. if (tmp == NULL) {
  875. PyErr_Clear();
  876. return 0;
  877. }
  878. r = PyObject_IsTrue(tmp);
  879. Py_DECREF(tmp);
  880. if (r < 0)
  881. PyErr_Clear();
  882. return r > 0;
  883. }
  884. static int
  885. flush_std_files(void)
  886. {
  887. PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
  888. PyObject *ferr = _PySys_GetObjectId(&PyId_stderr);
  889. PyObject *tmp;
  890. int status = 0;
  891. if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
  892. tmp = _PyObject_CallMethodId(fout, &PyId_flush, NULL);
  893. if (tmp == NULL) {
  894. PyErr_WriteUnraisable(fout);
  895. status = -1;
  896. }
  897. else
  898. Py_DECREF(tmp);
  899. }
  900. if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
  901. tmp = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
  902. if (tmp == NULL) {
  903. PyErr_Clear();
  904. status = -1;
  905. }
  906. else
  907. Py_DECREF(tmp);
  908. }
  909. return status;
  910. }
  911. /* Undo the effect of Py_Initialize().
  912. Beware: if multiple interpreter and/or thread states exist, these
  913. are not wiped out; only the current thread and interpreter state
  914. are deleted. But since everything else is deleted, those other
  915. interpreter and thread states should no longer be used.
  916. (XXX We should do better, e.g. wipe out all interpreters and
  917. threads.)
  918. Locking: as above.
  919. */
  920. int
  921. Py_FinalizeEx(void)
  922. {
  923. PyInterpreterState *interp;
  924. PyThreadState *tstate;
  925. int status = 0;
  926. if (!_PyRuntime.initialized)
  927. return status;
  928. // Wrap up existing "threading"-module-created, non-daemon threads.
  929. wait_for_thread_shutdown();
  930. /* Get current thread state and interpreter pointer */
  931. tstate = _PyThreadState_GET();
  932. interp = tstate->interp;
  933. // Make any remaining pending calls.
  934. _Py_FinishPendingCalls();
  935. /* The interpreter is still entirely intact at this point, and the
  936. * exit funcs may be relying on that. In particular, if some thread
  937. * or exit func is still waiting to do an import, the import machinery
  938. * expects Py_IsInitialized() to return true. So don't say the
  939. * runtime is uninitialized until after the exit funcs have run.
  940. * Note that Threading.py uses an exit func to do a join on all the
  941. * threads created thru it, so this also protects pending imports in
  942. * the threads created via Threading.
  943. */
  944. call_py_exitfuncs(interp);
  945. /* Copy the core config, PyInterpreterState_Delete() free
  946. the core config memory */
  947. #ifdef Py_REF_DEBUG
  948. int show_ref_count = interp->core_config.show_ref_count;
  949. #endif
  950. #ifdef Py_TRACE_REFS
  951. int dump_refs = interp->core_config.dump_refs;
  952. #endif
  953. #ifdef WITH_PYMALLOC
  954. int malloc_stats = interp->core_config.malloc_stats;
  955. #endif
  956. /* Remaining threads (e.g. daemon threads) will automatically exit
  957. after taking the GIL (in PyEval_RestoreThread()). */
  958. _PyRuntime.finalizing = tstate;
  959. _PyRuntime.initialized = 0;
  960. _PyRuntime.core_initialized = 0;
  961. /* Flush sys.stdout and sys.stderr */
  962. if (flush_std_files() < 0) {
  963. status = -1;
  964. }
  965. /* Disable signal handling */
  966. PyOS_FiniInterrupts();
  967. /* Collect garbage. This may call finalizers; it's nice to call these
  968. * before all modules are destroyed.
  969. * XXX If a __del__ or weakref callback is triggered here, and tries to
  970. * XXX import a module, bad things can happen, because Python no
  971. * XXX longer believes it's initialized.
  972. * XXX Fatal Python error: Interpreter not initialized (version mismatch?)
  973. * XXX is easy to provoke that way. I've also seen, e.g.,
  974. * XXX Exception exceptions.ImportError: 'No module named sha'
  975. * XXX in <function callback at 0x008F5718> ignored
  976. * XXX but I'm unclear on exactly how that one happens. In any case,
  977. * XXX I haven't seen a real-life report of either of these.
  978. */
  979. _PyGC_CollectIfEnabled();
  980. #ifdef COUNT_ALLOCS
  981. /* With COUNT_ALLOCS, it helps to run GC multiple times:
  982. each collection might release some types from the type
  983. list, so they become garbage. */
  984. while (_PyGC_CollectIfEnabled() > 0)
  985. /* nothing */;
  986. #endif
  987. /* Destroy all modules */
  988. PyImport_Cleanup();
  989. /* Flush sys.stdout and sys.stderr (again, in case more was printed) */
  990. if (flush_std_files() < 0) {
  991. status = -1;
  992. }
  993. /* Collect final garbage. This disposes of cycles created by
  994. * class definitions, for example.
  995. * XXX This is disabled because it caused too many problems. If
  996. * XXX a __del__ or weakref callback triggers here, Python code has
  997. * XXX a hard time running, because even the sys module has been
  998. * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
  999. * XXX One symptom is a sequence of information-free messages
  1000. * XXX coming from threads (if a __del__ or callback is invoked,
  1001. * XXX other threads can execute too, and any exception they encounter
  1002. * XXX triggers a comedy of errors as subsystem after subsystem
  1003. * XXX fails to find what it *expects* to find in sys to help report
  1004. * XXX the exception and consequent unexpected failures). I've also
  1005. * XXX seen segfaults then, after adding print statements to the
  1006. * XXX Python code getting called.
  1007. */
  1008. #if 0
  1009. _PyGC_CollectIfEnabled();
  1010. #endif
  1011. /* Disable tracemalloc after all Python objects have been destroyed,
  1012. so it is possible to use tracemalloc in objects destructor. */
  1013. _PyTraceMalloc_Fini();
  1014. /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
  1015. _PyImport_Fini();
  1016. /* Cleanup typeobject.c's internal caches. */
  1017. _PyType_Fini();
  1018. /* unload faulthandler module */
  1019. _PyFaulthandler_Fini();
  1020. /* Debugging stuff */
  1021. #ifdef COUNT_ALLOCS
  1022. _Py_dump_counts(stderr);
  1023. #endif
  1024. /* dump hash stats */
  1025. _PyHash_Fini();
  1026. #ifdef Py_REF_DEBUG
  1027. if (show_ref_count) {
  1028. _PyDebug_PrintTotalRefs();
  1029. }
  1030. #endif
  1031. #ifdef Py_TRACE_REFS
  1032. /* Display all objects still alive -- this can invoke arbitrary
  1033. * __repr__ overrides, so requires a mostly-intact interpreter.
  1034. * Alas, a lot of stuff may still be alive now that will be cleaned
  1035. * up later.
  1036. */
  1037. if (dump_refs) {
  1038. _Py_PrintReferences(stderr);
  1039. }
  1040. #endif /* Py_TRACE_REFS */
  1041. /* Clear interpreter state and all thread states. */
  1042. PyInterpreterState_Clear(interp);
  1043. /* Now we decref the exception classes. After this point nothing
  1044. can raise an exception. That's okay, because each Fini() method
  1045. below has been checked to make sure no exceptions are ever
  1046. raised.
  1047. */
  1048. _PyExc_Fini();
  1049. /* Sundry finalizers */
  1050. PyMethod_Fini();
  1051. PyFrame_Fini();
  1052. PyCFunction_Fini();
  1053. PyTuple_Fini();
  1054. PyList_Fini();
  1055. PySet_Fini();
  1056. PyBytes_Fini();
  1057. PyLong_Fini();
  1058. PyFloat_Fini();
  1059. PyDict_Fini();
  1060. PySlice_Fini();
  1061. _PyGC_Fini();
  1062. _Py_HashRandomization_Fini();
  1063. _PyArg_Fini();
  1064. PyAsyncGen_Fini();
  1065. _PyContext_Fini();
  1066. /* Cleanup Unicode implementation */
  1067. _PyUnicode_Fini();
  1068. _Py_ClearFileSystemEncoding();
  1069. /* XXX Still allocated:
  1070. - various static ad-hoc pointers to interned strings
  1071. - int and float free list blocks
  1072. - whatever various modules and libraries allocate
  1073. */
  1074. PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
  1075. /* Cleanup auto-thread-state */
  1076. _PyGILState_Fini();
  1077. /* Delete current thread. After this, many C API calls become crashy. */
  1078. PyThreadState_Swap(NULL);
  1079. PyInterpreterState_Delete(interp);
  1080. #ifdef Py_TRACE_REFS
  1081. /* Display addresses (& refcnts) of all objects still alive.
  1082. * An address can be used to find the repr of the object, printed
  1083. * above by _Py_PrintReferences.
  1084. */
  1085. if (dump_refs) {
  1086. _Py_PrintReferenceAddresses(stderr);
  1087. }
  1088. #endif /* Py_TRACE_REFS */
  1089. #ifdef WITH_PYMALLOC
  1090. if (malloc_stats) {
  1091. _PyObject_DebugMallocStats(stderr);
  1092. }
  1093. #endif
  1094. call_ll_exitfuncs();
  1095. _PyRuntime_Finalize();
  1096. return status;
  1097. }
  1098. void
  1099. Py_Finalize(void)
  1100. {
  1101. Py_FinalizeEx();
  1102. }
  1103. /* Create and initialize a new interpreter and thread, and return the
  1104. new thread. This requires that Py_Initialize() has been called
  1105. first.
  1106. Unsuccessful initialization yields a NULL pointer. Note that *no*
  1107. exception information is available even in this case -- the
  1108. exception information is held in the thread, and there is no
  1109. thread.
  1110. Locking: as above.
  1111. */
  1112. static _PyInitError
  1113. new_interpreter(PyThreadState **tstate_p)
  1114. {
  1115. PyInterpreterState *interp;
  1116. PyThreadState *tstate, *save_tstate;
  1117. PyObject *bimod, *sysmod;
  1118. _PyInitError err;
  1119. if (!_PyRuntime.initialized) {
  1120. return _Py_INIT_ERR("Py_Initialize must be called first");
  1121. }
  1122. /* Issue #10915, #15751: The GIL API doesn't work with multiple
  1123. interpreters: disable PyGILState_Check(). */
  1124. _PyGILState_check_enabled = 0;
  1125. interp = PyInterpreterState_New();
  1126. if (interp == NULL) {
  1127. *tstate_p = NULL;
  1128. return _Py_INIT_OK();
  1129. }
  1130. tstate = PyThreadState_New(interp);
  1131. if (tstate == NULL) {
  1132. PyInterpreterState_Delete(interp);
  1133. *tstate_p = NULL;
  1134. return _Py_INIT_OK();
  1135. }
  1136. save_tstate = PyThreadState_Swap(tstate);
  1137. /* Copy the current interpreter config into the new interpreter */
  1138. _PyCoreConfig *core_config;
  1139. _PyMainInterpreterConfig *config;
  1140. if (save_tstate != NULL) {
  1141. core_config = &save_tstate->interp->core_config;
  1142. config = &save_tstate->interp->config;
  1143. } else {
  1144. /* No current thread state, copy from the main interpreter */
  1145. PyInterpreterState *main_interp = PyInterpreterState_Main();
  1146. core_config = &main_interp->core_config;
  1147. config = &main_interp->config;
  1148. }
  1149. if (_PyCoreConfig_Copy(&interp->core_config, core_config) < 0) {
  1150. return _Py_INIT_ERR("failed to copy core config");
  1151. }
  1152. core_config = &interp->core_config;
  1153. if (_PyMainInterpreterConfig_Copy(&interp->config, config) < 0) {
  1154. return _Py_INIT_ERR("failed to copy main interpreter config");
  1155. }
  1156. err = _PyExc_Init();
  1157. if (_Py_INIT_FAILED(err)) {
  1158. return err;
  1159. }
  1160. /* XXX The following is lax in error checking */
  1161. PyObject *modules = PyDict_New();
  1162. if (modules == NULL) {
  1163. return _Py_INIT_ERR("can't make modules dictionary");
  1164. }
  1165. interp->modules = modules;
  1166. sysmod = _PyImport_FindBuiltin("sys", modules);
  1167. if (sysmod != NULL) {
  1168. interp->sysdict = PyModule_GetDict(sysmod);
  1169. if (interp->sysdict == NULL)
  1170. goto handle_error;
  1171. Py_INCREF(interp->sysdict);
  1172. PyDict_SetItemString(interp->sysdict, "modules", modules);
  1173. if (_PySys_InitMain(interp) < 0) {
  1174. return _Py_INIT_ERR("can't finish initializing sys");
  1175. }
  1176. }
  1177. else if (PyErr_Occurred()) {
  1178. goto handle_error;
  1179. }
  1180. bimod = _PyImport_FindBuiltin("builtins", modules);
  1181. if (bimod != NULL) {
  1182. interp->builtins = PyModule_GetDict(bimod);
  1183. if (interp->builtins == NULL)
  1184. goto handle_error;
  1185. Py_INCREF(interp->builtins);
  1186. }
  1187. else if (PyErr_Occurred()) {
  1188. goto handle_error;
  1189. }
  1190. if (bimod != NULL && sysmod != NULL) {
  1191. err = _PyBuiltins_AddExceptions(bimod);
  1192. if (_Py_INIT_FAILED(err)) {
  1193. return err;
  1194. }
  1195. err = _PySys_SetPreliminaryStderr(interp->sysdict);
  1196. if (_Py_INIT_FAILED(err)) {
  1197. return err;
  1198. }
  1199. err = _PyImportHooks_Init();
  1200. if (_Py_INIT_FAILED(err)) {
  1201. return err;
  1202. }
  1203. err = initimport(interp, sysmod);
  1204. if (_Py_INIT_FAILED(err)) {
  1205. return err;
  1206. }
  1207. err = initexternalimport(interp);
  1208. if (_Py_INIT_FAILED(err)) {
  1209. return err;
  1210. }
  1211. err = initfsencoding(interp);
  1212. if (_Py_INIT_FAILED(err)) {
  1213. return err;
  1214. }
  1215. err = init_sys_streams(interp);
  1216. if (_Py_INIT_FAILED(err)) {
  1217. return err;
  1218. }
  1219. err = add_main_module(interp);
  1220. if (_Py_INIT_FAILED(err)) {
  1221. return err;
  1222. }
  1223. if (core_config->site_import) {
  1224. err = initsite();
  1225. if (_Py_INIT_FAILED(err)) {
  1226. return err;
  1227. }
  1228. }
  1229. }
  1230. if (PyErr_Occurred()) {
  1231. goto handle_error;
  1232. }
  1233. *tstate_p = tstate;
  1234. return _Py_INIT_OK();
  1235. handle_error:
  1236. /* Oops, it didn't work. Undo it all. */
  1237. PyErr_PrintEx(0);
  1238. PyThreadState_Clear(tstate);
  1239. PyThreadState_Swap(save_tstate);
  1240. PyThreadState_Delete(tstate);
  1241. PyInterpreterState_Delete(interp);
  1242. *tstate_p = NULL;
  1243. return _Py_INIT_OK();
  1244. }
  1245. PyThreadState *
  1246. Py_NewInterpreter(void)
  1247. {
  1248. PyThreadState *tstate = NULL;
  1249. _PyInitError err = new_interpreter(&tstate);
  1250. if (_Py_INIT_FAILED(err)) {
  1251. _Py_ExitInitError(err);
  1252. }
  1253. return tstate;
  1254. }
  1255. /* Delete an interpreter and its last thread. This requires that the
  1256. given thread state is current, that the thread has no remaining
  1257. frames, and that it is its interpreter's only remaining thread.
  1258. It is a fatal error to violate these constraints.
  1259. (Py_FinalizeEx() doesn't have these constraints -- it zaps
  1260. everything, regardless.)
  1261. Locking: as above.
  1262. */
  1263. void
  1264. Py_EndInterpreter(PyThreadState *tstate)
  1265. {
  1266. PyInterpreterState *interp = tstate->interp;
  1267. if (tstate != _PyThreadState_GET())
  1268. Py_FatalError("Py_EndInterpreter: thread is not current");
  1269. if (tstate->frame != NULL)
  1270. Py_FatalError("Py_EndInterpreter: thread still has a frame");
  1271. interp->finalizing = 1;
  1272. // Wrap up existing "threading"-module-created, non-daemon threads.
  1273. wait_for_thread_shutdown();
  1274. call_py_exitfuncs(interp);
  1275. if (tstate != interp->tstate_head || tstate->next != NULL)
  1276. Py_FatalError("Py_EndInterpreter: not the last thread");
  1277. PyImport_Cleanup();
  1278. PyInterpreterState_Clear(interp);
  1279. PyThreadState_Swap(NULL);
  1280. PyInterpreterState_Delete(interp);
  1281. }
  1282. /* Add the __main__ module */
  1283. static _PyInitError
  1284. add_main_module(PyInterpreterState *interp)
  1285. {
  1286. PyObject *m, *d, *loader, *ann_dict;
  1287. m = PyImport_AddModule("__main__");
  1288. if (m == NULL)
  1289. return _Py_INIT_ERR("can't create __main__ module");
  1290. d = PyModule_GetDict(m);
  1291. ann_dict = PyDict_New();
  1292. if ((ann_dict == NULL) ||
  1293. (PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) {
  1294. return _Py_INIT_ERR("Failed to initialize __main__.__annotations__");
  1295. }
  1296. Py_DECREF(ann_dict);
  1297. if (PyDict_GetItemString(d, "__builtins__") == NULL) {
  1298. PyObject *bimod = PyImport_ImportModule("builtins");
  1299. if (bimod == NULL) {
  1300. return _Py_INIT_ERR("Failed to retrieve builtins module");
  1301. }
  1302. if (PyDict_SetItemString(d, "__builtins__", bimod) < 0) {
  1303. return _Py_INIT_ERR("Failed to initialize __main__.__builtins__");
  1304. }
  1305. Py_DECREF(bimod);
  1306. }
  1307. /* Main is a little special - imp.is_builtin("__main__") will return
  1308. * False, but BuiltinImporter is still the most appropriate initial
  1309. * setting for its __loader__ attribute. A more suitable value will
  1310. * be set if __main__ gets further initialized later in the startup
  1311. * process.
  1312. */
  1313. loader = PyDict_GetItemString(d, "__loader__");
  1314. if (loader == NULL || loader == Py_None) {
  1315. PyObject *loader = PyObject_GetAttrString(interp->importlib,
  1316. "BuiltinImporter");
  1317. if (loader == NULL) {
  1318. return _Py_INIT_ERR("Failed to retrieve BuiltinImporter");
  1319. }
  1320. if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
  1321. return _Py_INIT_ERR("Failed to initialize __main__.__loader__");
  1322. }
  1323. Py_DECREF(loader);
  1324. }
  1325. return _Py_INIT_OK();
  1326. }
  1327. static _PyInitError
  1328. initfsencoding(PyInterpreterState *interp)
  1329. {
  1330. _PyCoreConfig *config = &interp->core_config;
  1331. char *encoding = get_codec_name(config->filesystem_encoding);
  1332. if (encoding == NULL) {
  1333. /* Such error can only occurs in critical situations: no more
  1334. memory, import a module of the standard library failed, etc. */
  1335. return _Py_INIT_ERR("failed to get the Python codec "
  1336. "of the filesystem encoding");
  1337. }
  1338. /* Update the filesystem encoding to the normalized Python codec name.
  1339. For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii"
  1340. (Python codec name). */
  1341. PyMem_RawFree(config->filesystem_encoding);
  1342. config->filesystem_encoding = encoding;
  1343. /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
  1344. global configuration variables. */
  1345. if (_Py_SetFileSystemEncoding(config->filesystem_encoding,
  1346. config->filesystem_errors) < 0) {
  1347. return _Py_INIT_NO_MEMORY();
  1348. }
  1349. /* PyUnicode can now use the Python codec rather than C implementation
  1350. for the filesystem encoding */
  1351. interp->fscodec_initialized = 1;
  1352. return _Py_INIT_OK();
  1353. }
  1354. /* Import the site module (not into __main__ though) */
  1355. static _PyInitError
  1356. initsite(void)
  1357. {
  1358. PyObject *m;
  1359. m = PyImport_ImportModule("site");
  1360. if (m == NULL) {
  1361. return _Py_INIT_USER_ERR("Failed to import the site module");
  1362. }
  1363. Py_DECREF(m);
  1364. return _Py_INIT_OK();
  1365. }
  1366. /* Check if a file descriptor is valid or not.
  1367. Return 0 if the file descriptor is invalid, return non-zero otherwise. */
  1368. static int
  1369. is_valid_fd(int fd)
  1370. {
  1371. #ifdef __APPLE__
  1372. /* bpo-30225: On macOS Tiger, when stdout is redirected to a pipe
  1373. and the other side of the pipe is closed, dup(1) succeed, whereas
  1374. fstat(1, &st) fails with EBADF. Prefer fstat() over dup() to detect
  1375. such error. */
  1376. struct stat st;
  1377. return (fstat(fd, &st) == 0);
  1378. #else
  1379. int fd2;
  1380. if (fd < 0)
  1381. return 0;
  1382. _Py_BEGIN_SUPPRESS_IPH
  1383. /* Prefer dup() over fstat(). fstat() can require input/output whereas
  1384. dup() doesn't, there is a low risk of EMFILE/ENFILE at Python
  1385. startup. */
  1386. fd2 = dup(fd);
  1387. if (fd2 >= 0)
  1388. close(fd2);
  1389. _Py_END_SUPPRESS_IPH
  1390. return fd2 >= 0;
  1391. #endif
  1392. }
  1393. /* returns Py_None if the fd is not valid */
  1394. static PyObject*
  1395. create_stdio(const _PyCoreConfig *config, PyObject* io,
  1396. int fd, int write_mode, const char* name,
  1397. const char* encoding, const char* errors)
  1398. {
  1399. PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
  1400. const char* mode;
  1401. const char* newline;
  1402. PyObject *line_buffering, *write_through;
  1403. int buffering, isatty;
  1404. _Py_IDENTIFIER(open);
  1405. _Py_IDENTIFIER(isatty);
  1406. _Py_IDENTIFIER(TextIOWrapper);
  1407. _Py_IDENTIFIER(mode);
  1408. const int buffered_stdio = config->buffered_stdio;
  1409. if (!is_valid_fd(fd))
  1410. Py_RETURN_NONE;
  1411. /* stdin is always opened in buffered mode, first because it shouldn't
  1412. make a difference in common use cases, second because TextIOWrapper
  1413. depends on the presence of a read1() method which only exists on
  1414. buffered streams.
  1415. */
  1416. if (!buffered_stdio && write_mode)
  1417. buffering = 0;
  1418. else
  1419. buffering = -1;
  1420. if (write_mode)
  1421. mode = "wb";
  1422. else
  1423. mode = "rb";
  1424. buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOi",
  1425. fd, mode, buffering,
  1426. Py_None, Py_None, /* encoding, errors */
  1427. Py_None, 0); /* newline, closefd */
  1428. if (buf == NULL)
  1429. goto error;
  1430. if (buffering) {
  1431. _Py_IDENTIFIER(raw);
  1432. raw = _PyObject_GetAttrId(buf, &PyId_raw);
  1433. if (raw == NULL)
  1434. goto error;
  1435. }
  1436. else {
  1437. raw = buf;
  1438. Py_INCREF(raw);
  1439. }
  1440. #ifdef MS_WINDOWS
  1441. /* Windows console IO is always UTF-8 encoded */
  1442. if (PyWindowsConsoleIO_Check(raw))
  1443. encoding = "utf-8";
  1444. #endif
  1445. text = PyUnicode_FromString(name);
  1446. if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0)
  1447. goto error;
  1448. res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
  1449. if (res == NULL)
  1450. goto error;
  1451. isatty = PyObject_IsTrue(res);
  1452. Py_DECREF(res);
  1453. if (isatty == -1)
  1454. goto error;
  1455. if (!buffered_stdio)
  1456. write_through = Py_True;
  1457. else
  1458. write_through = Py_False;
  1459. if (isatty && buffered_stdio)
  1460. line_buffering = Py_True;
  1461. else
  1462. line_buffering = Py_False;
  1463. Py_CLEAR(raw);
  1464. Py_CLEAR(text);
  1465. #ifdef MS_WINDOWS
  1466. /* sys.stdin: enable universal newline mode, translate "\r\n" and "\r"
  1467. newlines to "\n".
  1468. sys.stdout and sys.stderr: translate "\n" to "\r\n". */
  1469. newline = NULL;
  1470. #else
  1471. /* sys.stdin: split lines at "\n".
  1472. sys.stdout and sys.stderr: don't translate newlines (use "\n"). */
  1473. newline = "\n";
  1474. #endif
  1475. stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OsssOO",
  1476. buf, encoding, errors,
  1477. newline, line_buffering, write_through);
  1478. Py_CLEAR(buf);
  1479. if (stream == NULL)
  1480. goto error;
  1481. if (write_mode)
  1482. mode = "w";
  1483. else
  1484. mode = "r";
  1485. text = PyUnicode_FromString(mode);
  1486. if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0)
  1487. goto error;
  1488. Py_CLEAR(text);
  1489. return stream;
  1490. error:
  1491. Py_XDECREF(buf);
  1492. Py_XDECREF(stream);
  1493. Py_XDECREF(text);
  1494. Py_XDECREF(raw);
  1495. if (PyErr_ExceptionMatches(PyExc_OSError) && !is_valid_fd(fd)) {
  1496. /* Issue #24891: the file descriptor was closed after the first
  1497. is_valid_fd() check was called. Ignore the OSError and set the
  1498. stream to None. */
  1499. PyErr_Clear();
  1500. Py_RETURN_NONE;
  1501. }
  1502. return NULL;
  1503. }
  1504. /* Initialize sys.stdin, stdout, stderr and builtins.open */
  1505. static _PyInitError
  1506. init_sys_streams(PyInterpreterState *interp)
  1507. {
  1508. PyObject *iomod = NULL, *wrapper;
  1509. PyObject *bimod = NULL;
  1510. PyObject *m;
  1511. PyObject *std = NULL;
  1512. int fd;
  1513. PyObject * encoding_attr;
  1514. _PyInitError res = _Py_INIT_OK();
  1515. _PyCoreConfig *config = &interp->core_config;
  1516. /* Check that stdin is not a directory
  1517. Using shell redirection, you can redirect stdin to a directory,
  1518. crashing the Python interpreter. Catch this common mistake here
  1519. and output a useful error message. Note that under MS Windows,
  1520. the shell already prevents that. */
  1521. #ifndef MS_WINDOWS
  1522. struct _Py_stat_struct sb;
  1523. if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 &&
  1524. S_ISDIR(sb.st_mode)) {
  1525. return _Py_INIT_USER_ERR("<stdin> is a directory, "
  1526. "cannot continue");
  1527. }
  1528. #endif
  1529. char *codec_name = get_codec_name(config->stdio_encoding);
  1530. if (codec_name == NULL) {
  1531. return _Py_INIT_ERR("failed to get the Python codec name "
  1532. "of the stdio encoding");
  1533. }
  1534. PyMem_RawFree(config->stdio_encoding);
  1535. config->stdio_encoding = codec_name;
  1536. /* Hack to avoid a nasty recursion issue when Python is invoked
  1537. in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
  1538. if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
  1539. goto error;
  1540. }
  1541. Py_DECREF(m);
  1542. if (!(m = PyImport_ImportModule("encodings.latin_1"))) {
  1543. goto error;
  1544. }
  1545. Py_DECREF(m);
  1546. if (!(bimod = PyImport_ImportModule("builtins"))) {
  1547. goto error;
  1548. }
  1549. if (!(iomod = PyImport_ImportModule("io"))) {
  1550. goto error;
  1551. }
  1552. if (!(wrapper = PyObject_GetAttrString(iomod, "OpenWrapper"))) {
  1553. goto error;
  1554. }
  1555. /* Set builtins.open */
  1556. if (PyObject_SetAttrString(bimod, "open", wrapper) == -1) {
  1557. Py_DECREF(wrapper);
  1558. goto error;
  1559. }
  1560. Py_DECREF(wrapper);
  1561. /* Set sys.stdin */
  1562. fd = fileno(stdin);
  1563. /* Under some conditions stdin, stdout and stderr may not be connected
  1564. * and fileno() may point to an invalid file descriptor. For example
  1565. * GUI apps don't have valid standard streams by default.
  1566. */
  1567. std = create_stdio(config, iomod, fd, 0, "<stdin>",
  1568. config->stdio_encoding,
  1569. config->stdio_errors);
  1570. if (std == NULL)
  1571. goto error;
  1572. PySys_SetObject("__stdin__", std);
  1573. _PySys_SetObjectId(&PyId_stdin, std);
  1574. Py_DECREF(std);
  1575. /* Set sys.stdout */
  1576. fd = fileno(stdout);
  1577. std = create_stdio(config, iomod, fd, 1, "<stdout>",
  1578. config->stdio_encoding,
  1579. config->stdio_errors);
  1580. if (std == NULL)
  1581. goto error;
  1582. PySys_SetObject("__stdout__", std);
  1583. _PySys_SetObjectId(&PyId_stdout, std);
  1584. Py_DECREF(std);
  1585. #if 1 /* Disable this if you have trouble debugging bootstrap stuff */
  1586. /* Set sys.stderr, replaces the preliminary stderr */
  1587. fd = fileno(stderr);
  1588. std = create_stdio(config, iomod, fd, 1, "<stderr>",
  1589. config->stdio_encoding,
  1590. "backslashreplace");
  1591. if (std == NULL)
  1592. goto error;
  1593. /* Same as hack above, pre-import stderr's codec to avoid recursion
  1594. when import.c tries to write to stderr in verbose mode. */
  1595. encoding_attr = PyObject_GetAttrString(std, "encoding");
  1596. if (encoding_attr != NULL) {
  1597. const char *std_encoding = PyUnicode_AsUTF8(encoding_attr);
  1598. if (std_encoding != NULL) {
  1599. PyObject *codec_info = _PyCodec_Lookup(std_encoding);
  1600. Py_XDECREF(codec_info);
  1601. }
  1602. Py_DECREF(encoding_attr);
  1603. }
  1604. PyErr_Clear(); /* Not a fatal error if codec isn't available */
  1605. if (PySys_SetObject("__stderr__", std) < 0) {
  1606. Py_DECREF(std);
  1607. goto error;
  1608. }
  1609. if (_PySys_SetObjectId(&PyId_stderr, std) < 0) {
  1610. Py_DECREF(std);
  1611. goto error;
  1612. }
  1613. Py_DECREF(std);
  1614. #endif
  1615. goto done;
  1616. error:
  1617. res = _Py_INIT_ERR("can't initialize sys standard streams");
  1618. done:
  1619. _Py_ClearStandardStreamEncoding();
  1620. Py_XDECREF(bimod);
  1621. Py_XDECREF(iomod);
  1622. return res;
  1623. }
  1624. static void
  1625. _Py_FatalError_DumpTracebacks(int fd)
  1626. {
  1627. fputc('\n', stderr);
  1628. fflush(stderr);
  1629. /* display the current Python stack */
  1630. _Py_DumpTracebackThreads(fd, NULL, NULL);
  1631. }
  1632. /* Print the current exception (if an exception is set) with its traceback,
  1633. or display the current Python stack.
  1634. Don't call PyErr_PrintEx() and the except hook, because Py_FatalError() is
  1635. called on catastrophic cases.
  1636. Return 1 if the traceback was displayed, 0 otherwise. */
  1637. static int
  1638. _Py_FatalError_PrintExc(int fd)
  1639. {
  1640. PyObject *ferr, *res;
  1641. PyObject *exception, *v, *tb;
  1642. int has_tb;
  1643. PyErr_Fetch(&exception, &v, &tb);
  1644. if (exception == NULL) {
  1645. /* No current exception */
  1646. return 0;
  1647. }
  1648. ferr = _PySys_GetObjectId(&PyId_stderr);
  1649. if (ferr == NULL || ferr == Py_None) {
  1650. /* sys.stderr is not set yet or set to None,
  1651. no need to try to display the exception */
  1652. return 0;
  1653. }
  1654. PyErr_NormalizeException(&exception, &v, &tb);
  1655. if (tb == NULL) {
  1656. tb = Py_None;
  1657. Py_INCREF(tb);
  1658. }
  1659. PyException_SetTraceback(v, tb);
  1660. if (exception == NULL) {
  1661. /* PyErr_NormalizeException() failed */
  1662. return 0;
  1663. }
  1664. has_tb = (tb != Py_None);
  1665. PyErr_Display(exception, v, tb);
  1666. Py_XDECREF(exception);
  1667. Py_XDECREF(v);
  1668. Py_XDECREF(tb);
  1669. /* sys.stderr may be buffered: call sys.stderr.flush() */
  1670. res = _PyObject_CallMethodId(ferr, &PyId_flush, NULL);
  1671. if (res == NULL)
  1672. PyErr_Clear();
  1673. else
  1674. Py_DECREF(res);
  1675. return has_tb;
  1676. }
  1677. /* Print fatal error message and abort */
  1678. #ifdef MS_WINDOWS
  1679. static void
  1680. fatal_output_debug(const char *msg)
  1681. {
  1682. /* buffer of 256 bytes allocated on the stack */
  1683. WCHAR buffer[256 / sizeof(WCHAR)];
  1684. size_t buflen = Py_ARRAY_LENGTH(buffer) - 1;
  1685. size_t msglen;
  1686. OutputDebugStringW(L"Fatal Python error: ");
  1687. msglen = strlen(msg);
  1688. while (msglen) {
  1689. size_t i;
  1690. if (buflen > msglen) {
  1691. buflen = msglen;
  1692. }
  1693. /* Convert the message to wchar_t. This uses a simple one-to-one
  1694. conversion, assuming that the this error message actually uses
  1695. ASCII only. If this ceases to be true, we will have to convert. */
  1696. for (i=0; i < buflen; ++i) {
  1697. buffer[i] = msg[i];
  1698. }
  1699. buffer[i] = L'\0';
  1700. OutputDebugStringW(buffer);
  1701. msg += buflen;
  1702. msglen -= buflen;
  1703. }
  1704. OutputDebugStringW(L"\n");
  1705. }
  1706. #endif
  1707. static void _Py_NO_RETURN
  1708. fatal_error(const char *prefix, const char *msg, int status)
  1709. {
  1710. const int fd = fileno(stderr);
  1711. static int reentrant = 0;
  1712. if (reentrant) {
  1713. /* Py_FatalError() caused a second fatal error.
  1714. Example: flush_std_files() raises a recursion error. */
  1715. goto exit;
  1716. }
  1717. reentrant = 1;
  1718. fprintf(stderr, "Fatal Python error: ");
  1719. if (prefix) {
  1720. fputs(prefix, stderr);
  1721. fputs(": ", stderr);
  1722. }
  1723. if (msg) {
  1724. fputs(msg, stderr);
  1725. }
  1726. else {
  1727. fprintf(stderr, "<message not set>");
  1728. }
  1729. fputs("\n", stderr);
  1730. fflush(stderr); /* it helps in Windows debug build */
  1731. /* Check if the current thread has a Python thread state
  1732. and holds the GIL */
  1733. PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
  1734. if (tss_tstate != NULL) {
  1735. PyThreadState *tstate = _PyThreadState_GET();
  1736. if (tss_tstate != tstate) {
  1737. /* The Python thread does not hold the GIL */
  1738. tss_tstate = NULL;
  1739. }
  1740. }
  1741. else {
  1742. /* Py_FatalError() has been called from a C thread
  1743. which has no Python thread state. */
  1744. }
  1745. int has_tstate_and_gil = (tss_tstate != NULL);
  1746. if (has_tstate_and_gil) {
  1747. /* If an exception is set, print the exception with its traceback */
  1748. if (!_Py_FatalError_PrintExc(fd)) {
  1749. /* No exception is set, or an exception is set without traceback */
  1750. _Py_FatalError_DumpTracebacks(fd);
  1751. }
  1752. }
  1753. else {
  1754. _Py_FatalError_DumpTracebacks(fd);
  1755. }
  1756. /* The main purpose of faulthandler is to display the traceback.
  1757. This function already did its best to display a traceback.
  1758. Disable faulthandler to prevent writing a second traceback
  1759. on abort(). */
  1760. _PyFaulthandler_Fini();
  1761. /* Check if the current Python thread hold the GIL */
  1762. if (has_tstate_and_gil) {
  1763. /* Flush sys.stdout and sys.stderr */
  1764. flush_std_files();
  1765. }
  1766. #ifdef MS_WINDOWS
  1767. fatal_output_debug(msg);
  1768. #endif /* MS_WINDOWS */
  1769. exit:
  1770. if (status < 0) {
  1771. #if defined(MS_WINDOWS) && defined(_DEBUG)
  1772. DebugBreak();
  1773. #endif
  1774. abort();
  1775. }
  1776. else {
  1777. exit(status);
  1778. }
  1779. }
  1780. void _Py_NO_RETURN
  1781. Py_FatalError(const char *msg)
  1782. {
  1783. fatal_error(NULL, msg, -1);
  1784. }
  1785. void _Py_NO_RETURN
  1786. _Py_ExitInitError(_PyInitError err)
  1787. {
  1788. if (err.exitcode >= 0) {
  1789. exit(err.exitcode);
  1790. }
  1791. else {
  1792. /* On "user" error: exit with status 1.
  1793. For all other errors, call abort(). */
  1794. int status = err.user_err ? 1 : -1;
  1795. fatal_error(err.prefix, err.msg, status);
  1796. }
  1797. }
  1798. /* Clean up and exit */
  1799. # include "pythread.h"
  1800. /* For the atexit module. */
  1801. void _Py_PyAtExit(void (*func)(PyObject *), PyObject *module)
  1802. {
  1803. PyInterpreterState *is = _PyInterpreterState_Get();
  1804. /* Guard against API misuse (see bpo-17852) */
  1805. assert(is->pyexitfunc == NULL || is->pyexitfunc == func);
  1806. is->pyexitfunc = func;
  1807. is->pyexitmodule = module;
  1808. }
  1809. static void
  1810. call_py_exitfuncs(PyInterpreterState *istate)
  1811. {
  1812. if (istate->pyexitfunc == NULL)
  1813. return;
  1814. (*istate->pyexitfunc)(istate->pyexitmodule);
  1815. PyErr_Clear();
  1816. }
  1817. /* Wait until threading._shutdown completes, provided
  1818. the threading module was imported in the first place.
  1819. The shutdown routine will wait until all non-daemon
  1820. "threading" threads have completed. */
  1821. static void
  1822. wait_for_thread_shutdown(void)
  1823. {
  1824. _Py_IDENTIFIER(_shutdown);
  1825. PyObject *result;
  1826. PyObject *threading = _PyImport_GetModuleId(&PyId_threading);
  1827. if (threading == NULL) {
  1828. if (PyErr_Occurred()) {
  1829. PyErr_WriteUnraisable(NULL);
  1830. }
  1831. /* else: threading not imported */
  1832. return;
  1833. }
  1834. result = _PyObject_CallMethodId(threading, &PyId__shutdown, NULL);
  1835. if (result == NULL) {
  1836. PyErr_WriteUnraisable(threading);
  1837. }
  1838. else {
  1839. Py_DECREF(result);
  1840. }
  1841. Py_DECREF(threading);
  1842. }
  1843. #define NEXITFUNCS 32
  1844. int Py_AtExit(void (*func)(void))
  1845. {
  1846. if (_PyRuntime.nexitfuncs >= NEXITFUNCS)
  1847. return -1;
  1848. _PyRuntime.exitfuncs[_PyRuntime.nexitfuncs++] = func;
  1849. return 0;
  1850. }
  1851. static void
  1852. call_ll_exitfuncs(void)
  1853. {
  1854. while (_PyRuntime.nexitfuncs > 0)
  1855. (*_PyRuntime.exitfuncs[--_PyRuntime.nexitfuncs])();
  1856. fflush(stdout);
  1857. fflush(stderr);
  1858. }
  1859. void _Py_NO_RETURN
  1860. Py_Exit(int sts)
  1861. {
  1862. if (Py_FinalizeEx() < 0) {
  1863. sts = 120;
  1864. }
  1865. exit(sts);
  1866. }
  1867. static _PyInitError
  1868. initsigs(void)
  1869. {
  1870. #ifdef SIGPIPE
  1871. PyOS_setsig(SIGPIPE, SIG_IGN);
  1872. #endif
  1873. #ifdef SIGXFZ
  1874. PyOS_setsig(SIGXFZ, SIG_IGN);
  1875. #endif
  1876. #ifdef SIGXFSZ
  1877. PyOS_setsig(SIGXFSZ, SIG_IGN);
  1878. #endif
  1879. PyOS_InitInterrupts(); /* May imply initsignal() */
  1880. if (PyErr_Occurred()) {
  1881. return _Py_INIT_ERR("can't import signal");
  1882. }
  1883. return _Py_INIT_OK();
  1884. }
  1885. /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
  1886. *
  1887. * All of the code in this function must only use async-signal-safe functions,
  1888. * listed at `man 7 signal` or
  1889. * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
  1890. */
  1891. void
  1892. _Py_RestoreSignals(void)
  1893. {
  1894. #ifdef SIGPIPE
  1895. PyOS_setsig(SIGPIPE, SIG_DFL);
  1896. #endif
  1897. #ifdef SIGXFZ
  1898. PyOS_setsig(SIGXFZ, SIG_DFL);
  1899. #endif
  1900. #ifdef SIGXFSZ
  1901. PyOS_setsig(SIGXFSZ, SIG_DFL);
  1902. #endif
  1903. }
  1904. /*
  1905. * The file descriptor fd is considered ``interactive'' if either
  1906. * a) isatty(fd) is TRUE, or
  1907. * b) the -i flag was given, and the filename associated with
  1908. * the descriptor is NULL or "<stdin>" or "???".
  1909. */
  1910. int
  1911. Py_FdIsInteractive(FILE *fp, const char *filename)
  1912. {
  1913. if (isatty((int)fileno(fp)))
  1914. return 1;
  1915. if (!Py_InteractiveFlag)
  1916. return 0;
  1917. return (filename == NULL) ||
  1918. (strcmp(filename, "<stdin>") == 0) ||
  1919. (strcmp(filename, "???") == 0);
  1920. }
  1921. /* Wrappers around sigaction() or signal(). */
  1922. PyOS_sighandler_t
  1923. PyOS_getsig(int sig)
  1924. {
  1925. #ifdef HAVE_SIGACTION
  1926. struct sigaction context;
  1927. if (sigaction(sig, NULL, &context) == -1)
  1928. return SIG_ERR;
  1929. return context.sa_handler;
  1930. #else
  1931. PyOS_sighandler_t handler;
  1932. /* Special signal handling for the secure CRT in Visual Studio 2005 */
  1933. #if defined(_MSC_VER) && _MSC_VER >= 1400
  1934. switch (sig) {
  1935. /* Only these signals are valid */
  1936. case SIGINT:
  1937. case SIGILL:
  1938. case SIGFPE:
  1939. case SIGSEGV:
  1940. case SIGTERM:
  1941. case SIGBREAK:
  1942. case SIGABRT:
  1943. break;
  1944. /* Don't call signal() with other values or it will assert */
  1945. default:
  1946. return SIG_ERR;
  1947. }
  1948. #endif /* _MSC_VER && _MSC_VER >= 1400 */
  1949. handler = signal(sig, SIG_IGN);
  1950. if (handler != SIG_ERR)
  1951. signal(sig, handler);
  1952. return handler;
  1953. #endif
  1954. }
  1955. /*
  1956. * All of the code in this function must only use async-signal-safe functions,
  1957. * listed at `man 7 signal` or
  1958. * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
  1959. */
  1960. PyOS_sighandler_t
  1961. PyOS_setsig(int sig, PyOS_sighandler_t handler)
  1962. {
  1963. #ifdef HAVE_SIGACTION
  1964. /* Some code in Modules/signalmodule.c depends on sigaction() being
  1965. * used here if HAVE_SIGACTION is defined. Fix that if this code
  1966. * changes to invalidate that assumption.
  1967. */
  1968. struct sigaction context, ocontext;
  1969. context.sa_handler = handler;
  1970. sigemptyset(&context.sa_mask);
  1971. context.sa_flags = 0;
  1972. if (sigaction(sig, &context, &ocontext) == -1)
  1973. return SIG_ERR;
  1974. return ocontext.sa_handler;
  1975. #else
  1976. PyOS_sighandler_t oldhandler;
  1977. oldhandler = signal(sig, handler);
  1978. #ifdef HAVE_SIGINTERRUPT
  1979. siginterrupt(sig, 1);
  1980. #endif
  1981. return oldhandler;
  1982. #endif
  1983. }
  1984. #ifdef __cplusplus
  1985. }
  1986. #endif