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.

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