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.

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