Skip to content

Commit 0327bde

Browse files
authored
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)
1 parent bdb8315 commit 0327bde

File tree

5 files changed

+966
-601
lines changed

5 files changed

+966
-601
lines changed

‎Include/pylifecycle.h‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,7 @@
77
extern "C" {
88
#endif
99

10-
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
11-
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
12-
13-
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
14-
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
15-
#ifdef Py_BUILD_CORE
16-
PyAPI_FUNC(wchar_t *) _Py_GetPythonHomeWithConfig(
17-
const _PyMainInterpreterConfig *config);
18-
#endif
19-
2010
#ifndef Py_LIMITED_API
21-
/* Only used by applications that embed the interpreter and need to
22-
* override the standard encoding determination mechanism
23-
*/
24-
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
25-
const char *errors);
26-
2711
typedef struct {
2812
const char *prefix;
2913
const char *msg;
@@ -46,9 +30,31 @@ typedef struct {
4630
Don't abort() the process on such error. */
4731
#define _Py_INIT_USER_ERR(MSG) \
4832
(_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1}
33+
#define _Py_INIT_NO_MEMORY() _Py_INIT_ERR("memory allocation failed")
4934
#define _Py_INIT_FAILED(err) \
5035
(err.msg != NULL)
5136

37+
#endif
38+
39+
40+
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
41+
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
42+
43+
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
44+
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
45+
#ifdef Py_BUILD_CORE
46+
PyAPI_FUNC(_PyInitError) _Py_GetPythonHomeWithConfig(
47+
const _PyMainInterpreterConfig *config,
48+
wchar_t **home);
49+
#endif
50+
51+
#ifndef Py_LIMITED_API
52+
/* Only used by applications that embed the interpreter and need to
53+
* override the standard encoding determination mechanism
54+
*/
55+
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
56+
const char *errors);
57+
5258
/* PEP 432 Multi-phase initialization API (Private while provisional!) */
5359
PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *);
5460
PyAPI_FUNC(int) _Py_IsCoreInitialized(void);

0 commit comments

Comments
 (0)