codekingpro/portable-devtools
114k
1#ifndef Py_INTERNAL_CORECONFIG_H2#define Py_INTERNAL_CORECONFIG_H3#ifdef __cplusplus4extern "C" {5#endif6 7#ifndef Py_BUILD_CORE8# error "this header requires Py_BUILD_CORE define"9#endif10 11#include "pycore_typedefs.h" // _PyRuntimeState12 13/* --- PyStatus ----------------------------------------------- */14 15/* Almost all errors causing Python initialization to fail */16#ifdef _MSC_VER17 /* Visual Studio 2015 doesn't implement C99 __func__ in C */18# define _PyStatus_GET_FUNC() __FUNCTION__19#else20# define _PyStatus_GET_FUNC() __func__21#endif22 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_ERRMSG "memory allocation failed"33#define _PyStatus_NO_MEMORY() _PyStatus_ERR(_PyStatus_NO_MEMORY_ERRMSG)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// Export for '_testinternalcapi' shared extension48PyAPI_FUNC(void) _PyErr_SetFromPyStatus(PyStatus status);49 50 51/* --- PyWideStringList ------------------------------------------------ */52 53#define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}54 55#ifndef NDEBUG56extern int _PyWideStringList_CheckConsistency(const PyWideStringList *list);57#endif58extern void _PyWideStringList_Clear(PyWideStringList *list);59extern int _PyWideStringList_Copy(PyWideStringList *list,60 const PyWideStringList *list2);61extern PyStatus _PyWideStringList_Extend(PyWideStringList *list,62 const PyWideStringList *list2);63extern PyObject* _PyWideStringList_AsList(const PyWideStringList *list);64 65 66/* --- _PyArgv ---------------------------------------------------- */67 68typedef struct _PyArgv {69 Py_ssize_t argc;70 int use_bytes_argv;71 char * const *bytes_argv;72 wchar_t * const *wchar_argv;73} _PyArgv;74 75extern PyStatus _PyArgv_AsWstrList(const _PyArgv *args,76 PyWideStringList *list);77 78 79/* --- Helper functions ------------------------------------------- */80 81extern int _Py_str_to_int(82 const char *str,83 int *result);84extern const wchar_t* _Py_get_xoption(85 const PyWideStringList *xoptions,86 const wchar_t *name);87extern const char* _Py_GetEnv(88 int use_environment,89 const char *name);90extern void _Py_get_env_flag(91 int use_environment,92 int *flag,93 const char *name);94 95/* Py_GetArgcArgv() helper */96extern void _Py_ClearArgcArgv(void);97 98 99/* --- _PyPreCmdline ------------------------------------------------- */100 101typedef struct {102 PyWideStringList argv;103 PyWideStringList xoptions; /* "-X value" option */104 int isolated; /* -I option */105 int use_environment; /* -E option */106 int dev_mode; /* -X dev and PYTHONDEVMODE */107 int warn_default_encoding; /* -X warn_default_encoding and PYTHONWARNDEFAULTENCODING */108} _PyPreCmdline;109 110#define _PyPreCmdline_INIT \111 (_PyPreCmdline){ \112 .use_environment = -1, \113 .isolated = -1, \114 .dev_mode = -1}115/* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */116 117extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline);118extern PyStatus _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,119 const _PyArgv *args);120extern PyStatus _PyPreCmdline_SetConfig(121 const _PyPreCmdline *cmdline,122 PyConfig *config);123extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,124 const PyPreConfig *preconfig);125 126 127/* --- PyPreConfig ----------------------------------------------- */128 129// Export for '_testembed' program130PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);131 132extern void _PyPreConfig_InitFromConfig(133 PyPreConfig *preconfig,134 const PyConfig *config);135extern PyStatus _PyPreConfig_InitFromPreConfig(136 PyPreConfig *preconfig,137 const PyPreConfig *config2);138extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig);139extern void _PyPreConfig_GetConfig(PyPreConfig *preconfig,140 const PyConfig *config);141extern PyStatus _PyPreConfig_Read(PyPreConfig *preconfig,142 const _PyArgv *args);143extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig);144 145 146/* --- PyConfig ---------------------------------------------- */147 148typedef enum {149 /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */150 _PyConfig_INIT_COMPAT = 1,151 _PyConfig_INIT_PYTHON = 2,152 _PyConfig_INIT_ISOLATED = 3153} _PyConfigInitEnum;154 155typedef enum {156 /* In free threaded builds, this means that the GIL is disabled at startup,157 but may be enabled by loading an incompatible extension module. */158 _PyConfig_GIL_DEFAULT = -1,159 160 /* The GIL has been forced off or on, and will not be affected by module loading. */161 _PyConfig_GIL_DISABLE = 0,162 _PyConfig_GIL_ENABLE = 1,163} _PyConfigGILEnum;164 165// Export for '_testembed' program166PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);167 168extern PyStatus _PyConfig_Copy(169 PyConfig *config,170 const PyConfig *config2);171extern PyStatus _PyConfig_InitPathConfig(172 PyConfig *config,173 int compute_path_config);174extern PyStatus _PyConfig_InitImportConfig(PyConfig *config);175extern PyStatus _PyConfig_Read(PyConfig *config, int compute_path_config);176extern PyStatus _PyConfig_Write(const PyConfig *config,177 _PyRuntimeState *runtime);178extern PyStatus _PyConfig_SetPyArgv(179 PyConfig *config,180 const _PyArgv *args);181extern PyObject* _PyConfig_CreateXOptionsDict(const PyConfig *config);182 183extern void _Py_DumpPathConfig(PyThreadState *tstate);184 185 186/* --- Function used for testing ---------------------------------- */187 188// Export these functions for '_testinternalcapi' shared extension189PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);190PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);191PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);192PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);193 194#ifdef __cplusplus195}196#endif197#endif /* !Py_INTERNAL_CORECONFIG_H */198 