mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-32030: Rewrite calculate_path() (#4521)
* calculate_path() rewritten in Modules/getpath.c and PC/getpathp.c
* Move global variables into a new PyPathConfig structure.
* calculate_path():
* Split the huge calculate_path() function into subfunctions.
* Add PyCalculatePath structure to pass data between subfunctions.
* Document PyCalculatePath fields.
* Move cleanup code into a new calculate_free() subfunction
* calculate_init() now handles Py_DecodeLocale() failures properly
* calculate_path() is now atomic: only replace PyPathConfig
(path_config) at once on success.
* _Py_GetPythonHomeWithConfig() now returns an error on failure
* Add _Py_INIT_NO_MEMORY() helper: report a memory allocation failure
* Coding style fixes (PEP 7)
This commit is contained in:
parent
bdb8315c21
commit
0327bde9da
5 changed files with 970 additions and 605 deletions
|
|
@ -7,23 +7,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
|
||||
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
|
||||
|
||||
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
|
||||
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
|
||||
#ifdef Py_BUILD_CORE
|
||||
PyAPI_FUNC(wchar_t *) _Py_GetPythonHomeWithConfig(
|
||||
const _PyMainInterpreterConfig *config);
|
||||
#endif
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
/* Only used by applications that embed the interpreter and need to
|
||||
* override the standard encoding determination mechanism
|
||||
*/
|
||||
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
|
||||
const char *errors);
|
||||
|
||||
typedef struct {
|
||||
const char *prefix;
|
||||
const char *msg;
|
||||
|
|
@ -46,9 +30,31 @@ typedef struct {
|
|||
Don't abort() the process on such error. */
|
||||
#define _Py_INIT_USER_ERR(MSG) \
|
||||
(_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1}
|
||||
#define _Py_INIT_NO_MEMORY() _Py_INIT_ERR("memory allocation failed")
|
||||
#define _Py_INIT_FAILED(err) \
|
||||
(err.msg != NULL)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
|
||||
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
|
||||
|
||||
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
|
||||
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
|
||||
#ifdef Py_BUILD_CORE
|
||||
PyAPI_FUNC(_PyInitError) _Py_GetPythonHomeWithConfig(
|
||||
const _PyMainInterpreterConfig *config,
|
||||
wchar_t **home);
|
||||
#endif
|
||||
|
||||
#ifndef Py_LIMITED_API
|
||||
/* Only used by applications that embed the interpreter and need to
|
||||
* override the standard encoding determination mechanism
|
||||
*/
|
||||
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
|
||||
const char *errors);
|
||||
|
||||
/* PEP 432 Multi-phase initialization API (Private while provisional!) */
|
||||
PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *);
|
||||
PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue