Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:47

0001 #ifndef Py_INTERNAL_CORECONFIG_H
0002 #define Py_INTERNAL_CORECONFIG_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "this header requires Py_BUILD_CORE define"
0009 #endif
0010 
0011 /* Forward declaration */
0012 struct pyruntimestate;
0013 
0014 /* --- PyStatus ----------------------------------------------- */
0015 
0016 /* Almost all errors causing Python initialization to fail */
0017 #ifdef _MSC_VER
0018    /* Visual Studio 2015 doesn't implement C99 __func__ in C */
0019 #  define _PyStatus_GET_FUNC() __FUNCTION__
0020 #else
0021 #  define _PyStatus_GET_FUNC() __func__
0022 #endif
0023 
0024 #define _PyStatus_OK() \
0025     (PyStatus){._type = _PyStatus_TYPE_OK}
0026     /* other fields are set to 0 */
0027 #define _PyStatus_ERR(ERR_MSG) \
0028     (PyStatus){ \
0029         ._type = _PyStatus_TYPE_ERROR, \
0030         .func = _PyStatus_GET_FUNC(), \
0031         .err_msg = (ERR_MSG)}
0032         /* other fields are set to 0 */
0033 #define _PyStatus_NO_MEMORY_ERRMSG "memory allocation failed"
0034 #define _PyStatus_NO_MEMORY() _PyStatus_ERR(_PyStatus_NO_MEMORY_ERRMSG)
0035 #define _PyStatus_EXIT(EXITCODE) \
0036     (PyStatus){ \
0037         ._type = _PyStatus_TYPE_EXIT, \
0038         .exitcode = (EXITCODE)}
0039 #define _PyStatus_IS_ERROR(err) \
0040     ((err)._type == _PyStatus_TYPE_ERROR)
0041 #define _PyStatus_IS_EXIT(err) \
0042     ((err)._type == _PyStatus_TYPE_EXIT)
0043 #define _PyStatus_EXCEPTION(err) \
0044     ((err)._type != _PyStatus_TYPE_OK)
0045 #define _PyStatus_UPDATE_FUNC(err) \
0046     do { (err).func = _PyStatus_GET_FUNC(); } while (0)
0047 
0048 // Export for '_testinternalcapi' shared extension
0049 PyAPI_FUNC(void) _PyErr_SetFromPyStatus(PyStatus status);
0050 
0051 
0052 /* --- PyWideStringList ------------------------------------------------ */
0053 
0054 #define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
0055 
0056 #ifndef NDEBUG
0057 extern int _PyWideStringList_CheckConsistency(const PyWideStringList *list);
0058 #endif
0059 extern void _PyWideStringList_Clear(PyWideStringList *list);
0060 extern int _PyWideStringList_Copy(PyWideStringList *list,
0061     const PyWideStringList *list2);
0062 extern PyStatus _PyWideStringList_Extend(PyWideStringList *list,
0063     const PyWideStringList *list2);
0064 extern PyObject* _PyWideStringList_AsList(const PyWideStringList *list);
0065 
0066 
0067 /* --- _PyArgv ---------------------------------------------------- */
0068 
0069 typedef struct _PyArgv {
0070     Py_ssize_t argc;
0071     int use_bytes_argv;
0072     char * const *bytes_argv;
0073     wchar_t * const *wchar_argv;
0074 } _PyArgv;
0075 
0076 extern PyStatus _PyArgv_AsWstrList(const _PyArgv *args,
0077     PyWideStringList *list);
0078 
0079 
0080 /* --- Helper functions ------------------------------------------- */
0081 
0082 extern int _Py_str_to_int(
0083     const char *str,
0084     int *result);
0085 extern const wchar_t* _Py_get_xoption(
0086     const PyWideStringList *xoptions,
0087     const wchar_t *name);
0088 extern const char* _Py_GetEnv(
0089     int use_environment,
0090     const char *name);
0091 extern void _Py_get_env_flag(
0092     int use_environment,
0093     int *flag,
0094     const char *name);
0095 
0096 /* Py_GetArgcArgv() helper */
0097 extern void _Py_ClearArgcArgv(void);
0098 
0099 
0100 /* --- _PyPreCmdline ------------------------------------------------- */
0101 
0102 typedef struct {
0103     PyWideStringList argv;
0104     PyWideStringList xoptions;     /* "-X value" option */
0105     int isolated;             /* -I option */
0106     int use_environment;      /* -E option */
0107     int dev_mode;             /* -X dev and PYTHONDEVMODE */
0108     int warn_default_encoding;     /* -X warn_default_encoding and PYTHONWARNDEFAULTENCODING */
0109 } _PyPreCmdline;
0110 
0111 #define _PyPreCmdline_INIT \
0112     (_PyPreCmdline){ \
0113         .use_environment = -1, \
0114         .isolated = -1, \
0115         .dev_mode = -1}
0116 /* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
0117 
0118 extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
0119 extern PyStatus _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
0120     const _PyArgv *args);
0121 extern PyStatus _PyPreCmdline_SetConfig(
0122     const _PyPreCmdline *cmdline,
0123     PyConfig *config);
0124 extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
0125     const PyPreConfig *preconfig);
0126 
0127 
0128 /* --- PyPreConfig ----------------------------------------------- */
0129 
0130 // Export for '_testembed' program
0131 PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
0132 
0133 extern void _PyPreConfig_InitFromConfig(
0134     PyPreConfig *preconfig,
0135     const PyConfig *config);
0136 extern PyStatus _PyPreConfig_InitFromPreConfig(
0137     PyPreConfig *preconfig,
0138     const PyPreConfig *config2);
0139 extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig);
0140 extern void _PyPreConfig_GetConfig(PyPreConfig *preconfig,
0141     const PyConfig *config);
0142 extern PyStatus _PyPreConfig_Read(PyPreConfig *preconfig,
0143     const _PyArgv *args);
0144 extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig);
0145 
0146 
0147 /* --- PyConfig ---------------------------------------------- */
0148 
0149 typedef enum {
0150     /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */
0151     _PyConfig_INIT_COMPAT = 1,
0152     _PyConfig_INIT_PYTHON = 2,
0153     _PyConfig_INIT_ISOLATED = 3
0154 } _PyConfigInitEnum;
0155 
0156 typedef enum {
0157     /* For now, this means the GIL is enabled.
0158 
0159        gh-116329: This will eventually change to "the GIL is disabled but can
0160        be reenabled by loading an incompatible extension module." */
0161     _PyConfig_GIL_DEFAULT = -1,
0162 
0163     /* The GIL has been forced off or on, and will not be affected by module loading. */
0164     _PyConfig_GIL_DISABLE = 0,
0165     _PyConfig_GIL_ENABLE = 1,
0166 } _PyConfigGILEnum;
0167 
0168 // Export for '_testembed' program
0169 PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
0170 
0171 extern PyStatus _PyConfig_Copy(
0172     PyConfig *config,
0173     const PyConfig *config2);
0174 extern PyStatus _PyConfig_InitPathConfig(
0175     PyConfig *config,
0176     int compute_path_config);
0177 extern PyStatus _PyConfig_InitImportConfig(PyConfig *config);
0178 extern PyStatus _PyConfig_Read(PyConfig *config, int compute_path_config);
0179 extern PyStatus _PyConfig_Write(const PyConfig *config,
0180     struct pyruntimestate *runtime);
0181 extern PyStatus _PyConfig_SetPyArgv(
0182     PyConfig *config,
0183     const _PyArgv *args);
0184 
0185 
0186 extern void _Py_DumpPathConfig(PyThreadState *tstate);
0187 
0188 
0189 /* --- Function used for testing ---------------------------------- */
0190 
0191 // Export these functions for '_testinternalcapi' shared extension
0192 PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
0193 PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
0194 PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
0195 PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
0196 
0197 #ifdef __cplusplus
0198 }
0199 #endif
0200 #endif /* !Py_INTERNAL_CORECONFIG_H */