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