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