Skip to content

Commit a19b855

Browse files
committed
[GR-66023][GR-66025] add initial support for initconfig functions
PullRequest: graalpython/3856
2 parents 410e57c + fc1a4a4 commit a19b855

File tree

10 files changed

+3432
-31
lines changed

10 files changed

+3432
-31
lines changed

graalpython/com.oracle.graal.python.cext/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ set(SRC_FILES ${CAPI_SRC}/codecs.c ${CAPI_SRC}/setobject.c ${CAPI_SRC}/compile.c
149149
${CAPI_SRC}/fileobject.c ${CAPI_SRC}/pystrcmp.c ${CAPI_SRC}/getversion.c
150150
${CAPI_SRC}/genobject.c ${CAPI_SRC}/methodobject.c ${CAPI_SRC}/boolobject.c ${CAPI_SRC}/pylifecycle.c
151151
${CAPI_SRC}/errors.c ${CAPI_SRC}/signals.c ${CAPI_SRC}/datetime.c ${CAPI_SRC}/call.c
152-
${CAPI_SRC}/getargs.c ${CAPI_SRC}/tracemalloc.c
152+
${CAPI_SRC}/getargs.c ${CAPI_SRC}/tracemalloc.c ${CAPI_SRC}/initconfig.c
153153
)
154154

155155
file(GLOB_RECURSE ACTUAL_SRC_FILES
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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 */

graalpython/com.oracle.graal.python.cext/src/compile.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -39,19 +39,3 @@
3939
* SOFTWARE.
4040
*/
4141
#include "capi.h"
42-
43-
int Py_DebugFlag = 0;
44-
int Py_VerboseFlag = 0;
45-
int Py_QuietFlag = 0;
46-
int Py_InteractiveFlag = 0;
47-
int Py_InspectFlag = 0;
48-
int Py_OptimizeFlag = 0;
49-
int Py_NoSiteFlag = 0;
50-
int Py_BytesWarningFlag = 0;
51-
int Py_FrozenFlag = 0;
52-
int Py_IgnoreEnvironmentFlag = 0;
53-
int Py_DontWriteBytecodeFlag = 0;
54-
int Py_NoUserSiteDirectory;
55-
int Py_UnbufferedStdioFlag = 0;
56-
int Py_HashRandomizationFlag = 0;
57-
int Py_IsolatedFlag = 0;

0 commit comments

Comments
 (0)