Skip to content

Commit

Permalink
change the flag to site instead of no_site and only set the interpret…
Browse files Browse the repository at this point in the history
…er config flag when it has been explicitly disabled. Add value error when site is off and isolated is not true
  • Loading branch information
tonybaloney committed Apr 20, 2023
1 parent 3658e81 commit e5c7b1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ typedef struct {
int allow_daemon_threads;
int check_multi_interp_extensions;
int own_gil;
int no_site;
int site_import;
} _PyInterpreterConfig;

#define _PyInterpreterConfig_INIT(nosite) \
#define _PyInterpreterConfig_INIT(site) \
{ \
.use_main_obmalloc = 0, \
.allow_fork = 0, \
Expand All @@ -265,10 +265,10 @@ typedef struct {
.allow_daemon_threads = 0, \
.check_multi_interp_extensions = 1, \
.own_gil = 1, \
.no_site = nosite, \
.site_import = site, \
}

#define _PyInterpreterConfig_LEGACY_INIT(nosite) \
#define _PyInterpreterConfig_LEGACY_INIT \
{ \
.use_main_obmalloc = 1, \
.allow_fork = 1, \
Expand All @@ -277,7 +277,7 @@ typedef struct {
.allow_daemon_threads = 1, \
.check_multi_interp_extensions = 0, \
.own_gil = 0, \
.no_site = nosite, \
.site_import = 1, \
}

/* --- Helper functions --------------------------------------- */
Expand Down
17 changes: 10 additions & 7 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,20 +503,23 @@ _run_script_in_interpreter(PyObject *mod, PyInterpreterState *interp,
static PyObject *
interp_create(PyObject *self, PyObject *args, PyObject *kwds)
{

static char *kwlist[] = {"isolated", "nosite", NULL};
int isolated = 1, nosite=1;
static char *kwlist[] = {"isolated", "site", NULL};
int isolated = 1, site=1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$ii:create", kwlist,
&isolated, &nosite)) {
&isolated, &site)) {
return NULL;
}
if (!isolated && !site){
// no site requires isolated
PyErr_SetString(PyExc_ValueError, "isolated must be True when combined with site=False");
return NULL;
}

// Create and initialize the new interpreter.
PyThreadState *save_tstate = _PyThreadState_GET();
assert(save_tstate != NULL);
const _PyInterpreterConfig config = isolated
? (_PyInterpreterConfig)_PyInterpreterConfig_INIT(nosite)
: (_PyInterpreterConfig)_PyInterpreterConfig_LEGACY_INIT(nosite);
? (_PyInterpreterConfig)_PyInterpreterConfig_INIT(site)
: (_PyInterpreterConfig)_PyInterpreterConfig_LEGACY_INIT;
// XXX Possible GILState issues?
PyThreadState *tstate = NULL;
PyStatus status = _Py_NewInterpreterFromConfig(&tstate, &config);
Expand Down
9 changes: 6 additions & 3 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ init_interp_settings(PyInterpreterState *interp, const _PyInterpreterConfig *con
interp->feature_flags |= Py_RTFLAGS_MULTI_INTERP_EXTENSIONS;
}

if (!config->site_import) {
interp->config.site_import = 0;
}

return _PyStatus_OK();
}

Expand Down Expand Up @@ -634,7 +638,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}

_PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT(0);
_PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
// The main interpreter always has its own GIL.
config.own_gil = 1;
status = init_interp_settings(interp, &config);
Expand Down Expand Up @@ -2078,7 +2082,6 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
goto error;
}

interp->config.site_import = !config->no_site;
status = init_interp_main(tstate);
if (_PyStatus_EXCEPTION(status)) {
goto error;
Expand Down Expand Up @@ -2116,7 +2119,7 @@ PyThreadState *
Py_NewInterpreter(void)
{
PyThreadState *tstate = NULL;
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT(0);
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
PyStatus status = _Py_NewInterpreterFromConfig(&tstate, &config);
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
Expand Down

0 comments on commit e5c7b1d

Please sign in to comment.