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.

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