◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
42 changes: 24 additions & 18 deletions Include/cpython/coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ typedef struct {
#define _Py_INIT_FAILED(err) \
(err.msg != NULL || err.exitcode != -1)

/* --- _PyPreConfig ----------------------------------------------- */

typedef struct {
Expand Down @@ -162,29 +174,24 @@ typedef struct {
char *filesystem_encoding;
char *filesystem_errors;

wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */

wchar_t *program_name; /* Program name, see also Py_GetProgramName() */
int argc; /* Number of command line arguments,
-1 means unset */
wchar_t **argv; /* Command line arguments */
wchar_t *program; /* argv[0] or "" */

int nxoption; /* Number of -X options */
wchar_t **xoptions; /* -X options */

int nwarnoption; /* Number of warnings options */
wchar_t **warnoptions; /* Warnings options */

/* Path configuration inputs */
wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
wchar_t *home; /* PYTHONHOME environment variable,
see also Py_SetPythonHome(). */

/* Path configuration outputs */
int nmodule_search_path; /* Number of sys.path paths,
-1 means unset */
wchar_t **module_search_paths; /* sys.path paths */
wchar_t *executable; /* sys.executable */
wchar_t *prefix; /* sys.prefix */
wchar_t *base_prefix; /* sys.base_prefix */
Expand Down Expand Up @@ -366,8 +373,7 @@ typedef struct {
.use_hash_seed = -1, \
.faulthandler = -1, \
.tracemalloc = -1, \
.argc = -1, \
.nmodule_search_path = -1, \
.site_import = -1, \
.bytes_warning = -1, \
.inspect = -1, \
Expand Down
37 changes: 18 additions & 19 deletions Include/internal/pycore_coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,38 @@ extern "C" {
# error "this header requires Py_BUILD_CORE or Py_BUILD_CORE_BUILTIN defined"
#endif

/* --- _Py_wstrlist ----------------------------------------------- */

PyAPI_FUNC(void) _Py_wstrlist_clear(
int len,
wchar_t **list);
PyAPI_FUNC(wchar_t**) _Py_wstrlist_copy(
int len,
wchar_t * const *list);
PyAPI_FUNC(_PyInitError) _Py_wstrlist_append(
int *len,
wchar_t ***list,
const wchar_t *str);
PyAPI_FUNC(PyObject*) _Py_wstrlist_as_pylist(
int len,
wchar_t **list);

/* --- _PyArgv ---------------------------------------------------- */

PyAPI_FUNC(_PyInitError) _PyArgv_Decode(const _PyArgv *args,
wchar_t*** argv_p);

/* --- Py_GetArgcArgv() helpers ----------------------------------- */

PyAPI_FUNC(void) _Py_ClearArgcArgv(void);

/* --- _PyPreConfig ----------------------------------------------- */

PyAPI_FUNC(int) _Py_str_to_int(
const char *str,
int *result);
PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
int nxoption,
wchar_t * const *xoptions,
const wchar_t *name);

PyAPI_FUNC(void) _PyPreConfig_Clear(_PyPreConfig *config);
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#endif

extern int _PyOS_opterr;
extern int _PyOS_optind;
extern wchar_t *_PyOS_optarg;

extern void _PyOS_ResetGetOpt(void);

Expand All @@ -17,6 +17,6 @@ typedef struct {
int val;
} _PyOS_LongOption;

extern int _PyOS_GetOpt(int argc, wchar_t **argv, int *longindex);

#endif /* !Py_INTERNAL_PYGETOPT_H */
2 changes: 1 addition & 1 deletion Include/internal/pycore_pathconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal(
PyAPI_FUNC(_PyInitError) _PyPathConfig_Calculate_impl(
_PyPathConfig *config,
const _PyCoreConfig *core_config);
PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
PyAPI_FUNC(int) _Py_FindEnvConfigValue(
FILE *env_file,
const wchar_t *key,
Expand Down
25 changes: 10 additions & 15 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ mainconfig_add_xoption(PyObject *opts, const wchar_t *s)
static PyObject*
mainconfig_create_xoptions_dict(const _PyCoreConfig *config)
{
int nxoption = config->nxoption;
wchar_t **xoptions = config->xoptions;
PyObject *dict = PyDict_New();
if (dict == NULL) {
return NULL;
}

for (int i=0; i < nxoption; i++) {
wchar_t *option = xoptions[i];
if (mainconfig_add_xoption(dict, option) < 0) {
Py_DECREF(dict);
return NULL;
Expand Down Expand Up @@ -243,22 +243,18 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *main_config,
} \
} \
} while (0)
#define COPY_WSTRLIST(ATTR, LEN, LIST) \
do { \
if (ATTR == NULL) { \
ATTR = _Py_wstrlist_as_pylist(LEN, LIST); \
if (ATTR == NULL) { \
return _Py_INIT_NO_MEMORY(); \
} \
} \
} while (0)

COPY_WSTRLIST(main_config->warnoptions,
config->nwarnoption, config->warnoptions);
if (config->argc >= 0) {
COPY_WSTRLIST(main_config->argv,
config->argc, config->argv);
}

if (config->_install_importlib) {
COPY_WSTR(executable);
@@ -268,7 +264,7 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *main_config,
COPY_WSTR(base_exec_prefix);

COPY_WSTRLIST(main_config->module_search_path,
config->nmodule_search_path, config->module_search_paths);

if (config->pycache_prefix != NULL) {
COPY_WSTR(pycache_prefix);
Expand Down @@ -784,8 +780,7 @@ pymain_run_python(PyInterpreterState *interp, int *exitcode)
}
}
else if (!config->preconfig.isolated) {
PyObject *path0 = _PyPathConfig_ComputeArgv0(config->argc,
config->argv);
if (path0 == NULL) {
err = _Py_INIT_NO_MEMORY();
goto done;
Expand Down
Loading
Toggle all file notes Toggle all file annotations