• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_INTERNAL_CORECONFIG_H
2 #define Py_INTERNAL_CORECONFIG_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #ifndef Py_BUILD_CORE
8 #  error "this header requires Py_BUILD_CORE define"
9 #endif
10 
11 /* Forward declaration */
12 struct pyruntimestate;
13 
14 /* --- PyStatus ----------------------------------------------- */
15 
16 /* Almost all errors causing Python initialization to fail */
17 #ifdef _MSC_VER
18    /* Visual Studio 2015 doesn't implement C99 __func__ in C */
19 #  define _PyStatus_GET_FUNC() __FUNCTION__
20 #else
21 #  define _PyStatus_GET_FUNC() __func__
22 #endif
23 
24 #define _PyStatus_OK() \
25     (PyStatus){._type = _PyStatus_TYPE_OK,}
26     /* other fields are set to 0 */
27 #define _PyStatus_ERR(ERR_MSG) \
28     (PyStatus){ \
29         ._type = _PyStatus_TYPE_ERROR, \
30         .func = _PyStatus_GET_FUNC(), \
31         .err_msg = (ERR_MSG)}
32         /* other fields are set to 0 */
33 #define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
34 #define _PyStatus_EXIT(EXITCODE) \
35     (PyStatus){ \
36         ._type = _PyStatus_TYPE_EXIT, \
37         .exitcode = (EXITCODE)}
38 #define _PyStatus_IS_ERROR(err) \
39     (err._type == _PyStatus_TYPE_ERROR)
40 #define _PyStatus_IS_EXIT(err) \
41     (err._type == _PyStatus_TYPE_EXIT)
42 #define _PyStatus_EXCEPTION(err) \
43     (err._type != _PyStatus_TYPE_OK)
44 #define _PyStatus_UPDATE_FUNC(err) \
45     do { err.func = _PyStatus_GET_FUNC(); } while (0)
46 
47 /* --- PyWideStringList ------------------------------------------------ */
48 
49 #define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
50 
51 #ifndef NDEBUG
52 PyAPI_FUNC(int) _PyWideStringList_CheckConsistency(const PyWideStringList *list);
53 #endif
54 PyAPI_FUNC(void) _PyWideStringList_Clear(PyWideStringList *list);
55 PyAPI_FUNC(int) _PyWideStringList_Copy(PyWideStringList *list,
56     const PyWideStringList *list2);
57 PyAPI_FUNC(PyStatus) _PyWideStringList_Extend(PyWideStringList *list,
58     const PyWideStringList *list2);
59 PyAPI_FUNC(PyObject*) _PyWideStringList_AsList(const PyWideStringList *list);
60 
61 
62 /* --- _PyArgv ---------------------------------------------------- */
63 
64 typedef struct _PyArgv {
65     Py_ssize_t argc;
66     int use_bytes_argv;
67     char * const *bytes_argv;
68     wchar_t * const *wchar_argv;
69 } _PyArgv;
70 
71 PyAPI_FUNC(PyStatus) _PyArgv_AsWstrList(const _PyArgv *args,
72     PyWideStringList *list);
73 
74 
75 /* --- Helper functions ------------------------------------------- */
76 
77 PyAPI_FUNC(int) _Py_str_to_int(
78     const char *str,
79     int *result);
80 PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
81     const PyWideStringList *xoptions,
82     const wchar_t *name);
83 PyAPI_FUNC(const char*) _Py_GetEnv(
84     int use_environment,
85     const char *name);
86 PyAPI_FUNC(void) _Py_get_env_flag(
87     int use_environment,
88     int *flag,
89     const char *name);
90 
91 /* Py_GetArgcArgv() helper */
92 PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
93 
94 
95 /* --- _PyPreCmdline ------------------------------------------------- */
96 
97 typedef struct {
98     PyWideStringList argv;
99     PyWideStringList xoptions;     /* "-X value" option */
100     int isolated;             /* -I option */
101     int use_environment;      /* -E option */
102     int dev_mode;             /* -X dev and PYTHONDEVMODE */
103 } _PyPreCmdline;
104 
105 #define _PyPreCmdline_INIT \
106     (_PyPreCmdline){ \
107         .use_environment = -1, \
108         .isolated = -1, \
109         .dev_mode = -1}
110 /* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
111 
112 extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
113 extern PyStatus _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
114     const _PyArgv *args);
115 extern PyStatus _PyPreCmdline_SetConfig(
116     const _PyPreCmdline *cmdline,
117     PyConfig *config);
118 extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
119     const PyPreConfig *preconfig);
120 
121 
122 /* --- PyPreConfig ----------------------------------------------- */
123 
124 PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
125 extern void _PyPreConfig_InitFromConfig(
126     PyPreConfig *preconfig,
127     const PyConfig *config);
128 extern PyStatus _PyPreConfig_InitFromPreConfig(
129     PyPreConfig *preconfig,
130     const PyPreConfig *config2);
131 extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig);
132 extern void _PyPreConfig_GetConfig(PyPreConfig *preconfig,
133     const PyConfig *config);
134 extern PyStatus _PyPreConfig_Read(PyPreConfig *preconfig,
135     const _PyArgv *args);
136 extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig);
137 
138 
139 /* --- PyConfig ---------------------------------------------- */
140 
141 typedef enum {
142     /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */
143     _PyConfig_INIT_COMPAT = 1,
144     _PyConfig_INIT_PYTHON = 2,
145     _PyConfig_INIT_ISOLATED = 3
146 } _PyConfigInitEnum;
147 
148 PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
149 extern PyStatus _PyConfig_Copy(
150     PyConfig *config,
151     const PyConfig *config2);
152 extern PyStatus _PyConfig_InitPathConfig(PyConfig *config);
153 extern PyStatus _PyConfig_Write(const PyConfig *config,
154     struct pyruntimestate *runtime);
155 extern PyStatus _PyConfig_SetPyArgv(
156     PyConfig *config,
157     const _PyArgv *args);
158 
159 
160 /* --- Function used for testing ---------------------------------- */
161 
162 PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 #endif /* !Py_INTERNAL_CORECONFIG_H */
168