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.

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