Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

/* --- _PyWstrList ------------------------------------------------ */

typedef struct {
/* If length is greater than zero, items must be non-NULL
and all items strings must be non-NULL */
Py_ssize_t length;
wchar_t **items;
} _PyWstrList;

#define _PyWstrList_INIT (_PyWstrList){.length = 0, .items = NULL}


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

typedef struct {
Expand Down Expand Up @@ -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 */
wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */
wchar_t *program_name; /* Program name, see also Py_GetProgramName() */
_PyWstrList argv; /* Command line arguments */
wchar_t *program; /* argv[0] or "" */
_PyWstrList xoptions; /* Command line -X options */
_PyWstrList 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 */
int use_module_search_paths; /* If non-zero, use module_search_paths */
_PyWstrList module_search_paths; /* sys.path paths. Computed if
use_module_search_paths is equal
to zero. */

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, \
.use_module_search_paths = 0, \
.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);

/* --- _PyWstrList ------------------------------------------------ */

#ifndef NDEBUG
PyAPI_FUNC(int) _PyWstrList_CheckConsistency(const _PyWstrList *list);
#endif
PyAPI_FUNC(void) _PyWstrList_Clear(_PyWstrList *list);
PyAPI_FUNC(int) _PyWstrList_Copy(_PyWstrList *list,
const _PyWstrList *list2);
PyAPI_FUNC(int) _PyWstrList_Append(_PyWstrList *list,
const wchar_t *item);
PyAPI_FUNC(PyObject*) _PyWstrList_AsList(const _PyWstrList *list);


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

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


/* --- 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 _PyWstrList *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 Py_ssize_t _PyOS_optind;
extern const 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);
extern int _PyOS_GetOpt(Py_ssize_t 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(PyObject*) _PyPathConfig_ComputeArgv0(const _PyWstrList *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;
Py_ssize_t nxoption = config->xoptions.length;
wchar_t * const * xoptions = config->xoptions.items;
PyObject *dict = PyDict_New();
if (dict == NULL) {
return NULL;
}

for (int i=0; i < nxoption; i++) {
wchar_t *option = xoptions[i];
for (Py_ssize_t i=0; i < nxoption; i++) {
const 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) \
#define COPY_WSTRLIST(ATTR, LIST) \
do { \
if (ATTR == NULL) { \
ATTR = _Py_wstrlist_as_pylist(LEN, LIST); \
ATTR = _PyWstrList_AsList(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);
}
COPY_WSTRLIST(main_config->warnoptions, &config->warnoptions);
COPY_WSTRLIST(main_config->argv, &config->argv);

if (config->_install_importlib) {
COPY_WSTR(executable);
Expand All @@ -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);
&config->module_search_paths);

if (config->pycache_prefix != NULL) {
COPY_WSTR(pycache_prefix);
Expand Down Expand Up @@ -784,8 +780,7 @@ pymain_run_python(PyInterpreterState *interp, int *exitcode)
}
}
else if (!config->preconfig.isolated) {
PyObject *path0 = _PyPathConfig_ComputeArgv0(config->argc,
config->argv);
PyObject *path0 = _PyPathConfig_ComputeArgv0(&config->argv);
if (path0 == NULL) {
err = _Py_INIT_NO_MEMORY();
goto done;
Expand Down
12 changes: 6 additions & 6 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ static int test_init_from_config(void)
L"-c",
L"pass",
};
config.argc = Py_ARRAY_LENGTH(argv);
config.argv = argv;
config.argv.length = Py_ARRAY_LENGTH(argv);
config.argv.items = argv;

config.program = L"conf_program";

Expand All @@ -489,15 +489,15 @@ static int test_init_from_config(void)
L"core_xoption2=",
L"core_xoption3",
};
config.nxoption = Py_ARRAY_LENGTH(xoptions);
config.xoptions = xoptions;
config.xoptions.length = Py_ARRAY_LENGTH(xoptions);
config.xoptions.items = xoptions;

static wchar_t* warnoptions[2] = {
L"default",
L"error::ResourceWarning",
};
config.nwarnoption = Py_ARRAY_LENGTH(warnoptions);
config.warnoptions = warnoptions;
config.warnoptions.length = Py_ARRAY_LENGTH(warnoptions);
config.warnoptions.items = warnoptions;

/* FIXME: test module_search_path_env */
/* FIXME: test home */
Expand Down
Loading