Title: [WIP] bpo-36142: Rework Python init to add _PyPreConfig by vstinner · Pull Request #12087 · python/cpython · GitHub
Open Graph Title: [WIP] bpo-36142: Rework Python init to add _PyPreConfig by vstinner · Pull Request #12087 · python/cpython
X Title: [WIP] bpo-36142: Rework Python init to add _PyPreConfig by vstinner · Pull Request #12087 · python/cpython
Description: I added a _PyCoreConfig structure to Python 3.7 which contains almost all parameters used to configure Python. Problems: _PyCoreConfig uses bytes and Unicode strings (char* and wchar_t*) whereas it is also used to setup the memory allocator and (filesystem, locale and stdio) encodings. I propose to add a new _PyPreConfig which is the "strict minimum" configuration to setup encodings and the memory allocator. In practice, it also contains parameters which directly or indirectly impacts the allocator and encodings. For example, isolated impacts use_environment which impacts the allocator (PYTHONMALLOC environment variable). Another example: dev_mode=1 sets the allocator to "debug". The command line arguments are now parsed twice. _PyPreConfig only parses a few parameters like -E, -I and -X. A temporary _PyPreCmdline is used to store command line arguments like -X options. I moved structures closer to where they are used. "Global" _PyMain structure has been removed. _PyCmdline now lives way shorter than previously and is moved from main.c to coreconfig.c. The idea is to better control when and how memory is allocated. In term of API, we get something like: _PyCoreConfig config = _PyCoreConfig_INIT; config.preconfig.stdio_encoding = "iso8859-1"; config.preconfig.stdio_errors = "replace"; config.user_site_directory = 0; ... _PyInitError err = _Py_InitializeFromConfig(&config); if (_Py_INIT_FAILED(err)) { _Py_ExitInitError(err); } ... Py_Finalize(); return 0; "config.preconfig.stdio_errors" syntax isn't great, but it's simpler to implement than duplicating all _PyPreConfig fields into _PyCoreConfig. Changes: Add Python/preconfig.c file Add _PyPreConfig structure: pre-initialization configuration for allocator and encodings. _PyCoreConfig now has a "_PyPreConfig preconfig;" field Add _PyArgv structure: helper to pass command line argument in bytes (char*) or Unicode (wchar_t*) Add exitcode to _PyInitError Add 'exitcode' field to _PyInitError structure Add _Py_INIT_EXIT() macro Rename _Py_FatalInitError() to _Py_ExitInitError() Add new fields to _PyCoreConfig: run_command run_filename run_module skip_source_first_line Add _PyMain_Usage() Hardcode short and long options in _PyOS_GetOpt(). Make _PyCoreConfig_xxx() functions internal (Py_BUILD_CORE). Move _PyCmdline from main.c to coreconfig.c main.c: Remove _PyMain structure https://bugs.python.org/issue36142
Open Graph Description: I added a _PyCoreConfig structure to Python 3.7 which contains almost all parameters used to configure Python. Problems: _PyCoreConfig uses bytes and Unicode strings (char* and wchar_t*) whereas it...
X Description: I added a _PyCoreConfig structure to Python 3.7 which contains almost all parameters used to configure Python. Problems: _PyCoreConfig uses bytes and Unicode strings (char* and wchar_t*) whereas it...
Opengraph URL: https://github.com/python/cpython/pull/12087
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6aa9c6b1-2a45-7045-0489-9fd71accc0f0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ED10:5CEA4:2074726:2CEE112:6A4ED4E4 |
| html-safe-nonce | 4e9e67a7e8c8675fb93499e4b8bb743ca5a94a160e2ff4064f1360a1ae521a0a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDEwOjVDRUE0OjIwNzQ3MjY6MkNFRTExMjo2QTRFRDRFNCIsInZpc2l0b3JfaWQiOiI3NzgzNTA4NDQxOTEwMTM4MDg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cf6883ead483be7a4311195d36d81a32f4b2d396e0b0dfe5c9fed5b6bea5ef45 |
| hovercard-subject-tag | pull_request:256903549 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/12087/files |
| twitter:image | https://avatars.githubusercontent.com/u/194129?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/194129?s=400&v=4 |
| og:image:alt | I added a _PyCoreConfig structure to Python 3.7 which contains almost all parameters used to configure Python. Problems: _PyCoreConfig uses bytes and Unicode strings (char* and wchar_t*) whereas it... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c37fe3e3f5f306900bd5b6bee97463f66c938b2c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width