Python's test suite."
(Contributed by Victor Stinner in :issue:`46852`.)
+* The ``--experimental-isolated-subinterpreters`` configure flag
+ (and corresponding ``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS``)
+ have been removed.
+
+
Porting to Python 3.11
======================
PyObject* const* args, size_t argcount,
PyObject *kwnames);
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
-#else
extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
-#endif
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
extern void _PyEval_FiniGIL(PyInterpreterState *interp);
/* Request for dropping the GIL */
_Py_atomic_int gil_drop_request;
struct _pending_calls pending;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state gil;
-#endif
};
/* Variable and macro for in-line access to current thread
and interpreter state */
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-PyAPI_FUNC(PyThreadState*) _PyThreadState_GetTSS(void);
-#endif
-
static inline PyThreadState*
_PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- return _PyThreadState_GetTSS();
-#else
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current);
-#endif
}
/* Get the current Python thread state.
static inline PyThreadState*
_PyThreadState_GET(void)
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- return _PyThreadState_GetTSS();
-#else
return _PyRuntimeState_GetThreadState(&_PyRuntime);
-#endif
}
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalError_TstateNULL(const char *func);
the main thread of the main interpreter can handle signals: see
_Py_ThreadCanHandleSignals(). */
_Py_atomic_int signals_pending;
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
struct _gil_runtime_state gil;
-#endif
};
/* GIL state */
--- /dev/null
+The ``--experimental-isolated-subinterpreters`` configure option and
+``EXPERIMENTAL_ISOLATED_SUBINTERPRETERS`` macro have been removed.
return -1;
}
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- // Switch to interpreter.
- PyThreadState *new_tstate = PyInterpreterState_ThreadHead(interp);
- PyThreadState *save1 = PyEval_SaveThread();
-
- (void)PyThreadState_Swap(new_tstate);
-
- // Run the script.
- _sharedexception *exc = NULL;
- int result = _run_script(interp, codestr, shared, &exc);
-
- // Switch back.
- PyEval_RestoreThread(save1);
-#else
// Switch to interpreter.
PyThreadState *save_tstate = NULL;
if (interp != PyInterpreterState_Get()) {
if (save_tstate != NULL) {
PyThreadState_Swap(save_tstate);
}
-#endif
// Propagate any exception out to the caller.
if (exc != NULL) {
assert(gcstate->garbage != NULL);
assert(!_PyErr_Occurred(tstate));
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- if (tstate->interp->config._isolated_interpreter) {
- // bpo-40533: The garbage collector must not be run on parallel on
- // Python objects shared by multiple interpreters.
- return 0;
- }
-#endif
-
if (gcstate->debug & DEBUG_STATS) {
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
show_stats_each_generations(gcstate);
} PySlot_Offset;
-/* bpo-40521: Interned strings are shared by all subinterpreters */
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-# define INTERN_NAME_STRINGS
-#endif
-
static PyObject *
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
if (name == NULL)
return -1;
}
-#ifdef INTERN_NAME_STRINGS
+ /* bpo-40521: Interned strings are shared by all subinterpreters */
if (!PyUnicode_CHECK_INTERNED(name)) {
PyUnicode_InternInPlace(&name);
if (!PyUnicode_CHECK_INTERNED(name)) {
return -1;
}
}
-#endif
}
else {
/* Will fail in _PyObject_GenericSetAttrWithDict. */
for (slotdef *p = slotdefs; p->name; p++) {
/* Slots must be ordered by their offset in the PyHeapTypeObject. */
assert(!p[1].name || p->offset <= p[1].offset);
-#ifdef INTERN_NAME_STRINGS
+ /* bpo-40521: Interned strings are shared by all subinterpreters */
p->name_strobj = PyUnicode_InternFromString(p->name);
if (!p->name_strobj || !PyUnicode_CHECK_INTERNED(p->name_strobj)) {
return _PyStatus_NO_MEMORY();
}
-#else
- p->name_strobj = PyUnicode_FromString(p->name);
- if (!p->name_strobj) {
- return _PyStatus_NO_MEMORY();
- }
-#endif
}
slotdefs_initialized = 1;
return _PyStatus_OK();
int offset;
assert(PyUnicode_CheckExact(name));
-#ifdef INTERN_NAME_STRINGS
assert(PyUnicode_CHECK_INTERNED(name));
-#endif
assert(slotdefs_initialized);
pp = ptrs;
for (p = slotdefs; p->name; p++) {
assert(PyUnicode_CheckExact(p->name_strobj));
assert(PyUnicode_CheckExact(name));
-#ifdef INTERN_NAME_STRINGS
+ /* bpo-40521: Using interned strings. */
if (p->name_strobj == name) {
*pp++ = p;
}
-#else
- if (p->name_strobj == name || _PyUnicode_EQ(p->name_strobj, name)) {
- *pp++ = p;
- }
-#endif
}
*pp = NULL;
for (pp = ptrs; *pp; pp++) {
# define OVERALLOCATE_FACTOR 4
#endif
-/* bpo-40521: Interned strings are shared by all interpreters. */
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-# define INTERNED_STRINGS
-#endif
-
/* This dictionary holds all interned unicode strings. Note that references
to strings in this dictionary are *not* counted in the string's ob_refcnt.
When the interned string reaches a refcnt of 0 the string deallocation
Another way to look at this is that to say that the actual reference
count of a string is: s->ob_refcnt + (s->state ? 2 : 0)
*/
-#ifdef INTERNED_STRINGS
static PyObject *interned = NULL;
-#endif
/* Forward declaration */
static inline int
switch (PyUnicode_CHECK_INTERNED(unicode)) {
case SSTATE_NOT_INTERNED:
break;
-
case SSTATE_INTERNED_MORTAL:
{
-#ifdef INTERNED_STRINGS
/* Revive the dead object temporarily. PyDict_DelItem() removes two
references (key and value) which were ignored by
PyUnicode_InternInPlace(). Use refcnt=3 rather than refcnt=2
}
assert(Py_REFCNT(unicode) == 1);
Py_SET_REFCNT(unicode, 0);
-#endif
break;
}
if (PyUnicode_CHECK_INTERNED(left))
return 0;
-#ifdef INTERNED_STRINGS
assert(_PyUnicode_HASH(right_uni) != -1);
Py_hash_t hash = _PyUnicode_HASH(left);
if (hash != -1 && hash != _PyUnicode_HASH(right_uni)) {
return 0;
}
-#endif
return unicode_compare_eq(left, right_uni);
}
return;
}
-#ifdef INTERNED_STRINGS
if (PyUnicode_READY(s) == -1) {
PyErr_Clear();
return;
this. */
Py_SET_REFCNT(s, Py_REFCNT(s) - 2);
_PyUnicode_STATE(s).interned = SSTATE_INTERNED_MORTAL;
-#else
- // PyDict expects that interned strings have their hash
- // (PyASCIIObject.hash) already computed.
- (void)unicode_hash(s);
-#endif
}
void
"(the current Python thread state is NULL)");
}
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-int
-_PyEval_ThreadsInitialized(PyInterpreterState *interp)
-{
- return gil_created(&interp->ceval.gil);
-}
-
-int
-PyEval_ThreadsInitialized(void)
-{
- // Fatal error if there is no current interpreter
- PyInterpreterState *interp = PyInterpreterState_Get();
- return _PyEval_ThreadsInitialized(interp);
-}
-#else
int
_PyEval_ThreadsInitialized(_PyRuntimeState *runtime)
{
_PyRuntimeState *runtime = &_PyRuntime;
return _PyEval_ThreadsInitialized(runtime);
}
-#endif
PyStatus
_PyEval_InitGIL(PyThreadState *tstate)
{
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
if (!_Py_IsMainInterpreter(tstate->interp)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
return _PyStatus_OK();
}
-#endif
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
-#else
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
-#endif
assert(!gil_created(gil));
PyThread_init_thread();
void
_PyEval_FiniGIL(PyInterpreterState *interp)
{
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
if (!_Py_IsMainInterpreter(interp)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
return;
}
-#endif
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &interp->ceval.gil;
-#else
struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
-#endif
if (!gil_created(gil)) {
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
yet: do nothing. */
take_gil(tstate);
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- (void)_PyThreadState_Swap(gilstate, tstate);
-#else
if (_PyThreadState_Swap(gilstate, tstate) != NULL) {
Py_FatalError("non-NULL old thread state");
}
-#endif
}
void
{
_PyRuntimeState *runtime = tstate->interp->runtime;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
-#else
struct _gil_runtime_state *gil = &runtime->ceval.gil;
-#endif
if (!gil_created(gil)) {
return _PyStatus_OK();
}
PyEval_SaveThread(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- PyThreadState *old_tstate = _PyThreadState_GET();
- PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, old_tstate);
-#else
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
-#endif
_Py_EnsureTstateNotNULL(tstate);
struct _ceval_runtime_state *ceval = &runtime->ceval;
struct _ceval_state *ceval2 = &tstate->interp->ceval;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- assert(gil_created(&ceval2->gil));
-#else
assert(gil_created(&ceval->gil));
-#endif
drop_gil(ceval, ceval2, tstate);
return tstate;
}
void
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
{
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
_gil_initialize(&ceval->gil);
-#endif
}
void
assert(pending->lock == NULL);
pending->lock = pending_lock;
-
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- _gil_initialize(&ceval->gil);
-#endif
}
void
take_gil(tstate);
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- (void)_PyThreadState_Swap(&runtime->gilstate, tstate);
-#else
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
Py_FatalError("orphan tstate");
}
-#endif
}
/* Check for asynchronous exception. */
drop_gil(struct _ceval_runtime_state *ceval, struct _ceval_state *ceval2,
PyThreadState *tstate)
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &ceval2->gil;
-#else
struct _gil_runtime_state *gil = &ceval->gil;
-#endif
if (!_Py_atomic_load_relaxed(&gil->locked)) {
Py_FatalError("drop_gil: GIL is not locked");
}
PyInterpreterState *interp = tstate->interp;
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
struct _ceval_state *ceval2 = &interp->ceval;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &ceval2->gil;
-#else
struct _gil_runtime_state *gil = &ceval->gil;
-#endif
/* Check that _PyEval_InitThreads() was called to create the lock */
assert(gil_created(gil));
void _PyEval_SetSwitchInterval(unsigned long microseconds)
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- PyInterpreterState *interp = PyInterpreterState_Get();
- struct _gil_runtime_state *gil = &interp->ceval.gil;
-#else
struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
-#endif
gil->interval = microseconds;
}
unsigned long _PyEval_GetSwitchInterval()
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- PyInterpreterState *interp = PyInterpreterState_Get();
- struct _gil_runtime_state *gil = &interp->ceval.gil;
-#else
struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
-#endif
return gil->interval;
}
config->coerce_c_locale_warn = 0;
config->dev_mode = -1;
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- /* bpo-40512: pymalloc is not compatible with subinterpreters,
- force usage of libc malloc() which is thread-safe. */
-#ifdef Py_DEBUG
- config->allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG;
-#else
- config->allocator = PYMEM_ALLOCATOR_MALLOC;
-#endif
-#else
config->allocator = PYMEM_ALLOCATOR_NOT_SET;
-#endif
#ifdef MS_WINDOWS
config->legacy_windows_fs_encoding = -1;
#endif
/* Copy the current interpreter config into the new interpreter */
const PyConfig *config;
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
if (save_tstate != NULL) {
config = _PyInterpreterState_GetConfig(save_tstate->interp);
}
else
-#endif
{
/* No current thread state, copy from the main interpreter */
PyInterpreterState *main_interp = _PyInterpreterState_Main();
}
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-PyThreadState*
-_PyThreadState_GetTSS(void) {
- return PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey);
-}
-#endif
-
-
PyThreadState *
_PyThreadState_UncheckedGet(void)
{
PyThreadState *
_PyThreadState_Swap(struct _gilstate_runtime_state *gilstate, PyThreadState *newts)
{
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- PyThreadState *oldts = _PyThreadState_GetTSS();
-#else
PyThreadState *oldts = _PyRuntimeGILState_GetThreadState(gilstate);
-#endif
_PyRuntimeGILState_SetThreadState(gilstate, newts);
/* It should not be possible for more than one thread state
Py_FatalError("Invalid thread state for this thread");
errno = err;
}
-#endif
-#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- PyThread_tss_set(&gilstate->autoTSSkey, newts);
#endif
return oldts;
}
/* Ensure that _PyEval_InitThreads() and _PyGILState_Init() have been
called by Py_Initialize() */
-#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
assert(_PyEval_ThreadsInitialized(runtime));
-#endif
assert(gilstate->autoInterpreterState);
PyThreadState *tcur = (PyThreadState *)PyThread_tss_get(&gilstate->autoTSSkey);
with_openssl_rpath
with_ssl_default_suites
with_builtin_hashlib_hashes
-with_experimental_isolated_subinterpreters
enable_test_modules
'
ac_precious_vars='build_alias
--with-builtin-hashlib-hashes=md5,sha1,sha256,sha512,sha3,blake2
builtin hash modules, md5, sha1, sha256, sha512,
sha3 (with shake), blake2
- --with-experimental-isolated-subinterpreters
- better isolate subinterpreters, experimental build
- mode (default is no)
Some influential environment variables:
PKG_CONFIG path to pkg-config utility
fi
-# --with-experimental-isolated-subinterpreters
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-experimental-isolated-subinterpreters" >&5
-$as_echo_n "checking for --with-experimental-isolated-subinterpreters... " >&6; }
-
-# Check whether --with-experimental-isolated-subinterpreters was given.
-if test "${with_experimental_isolated_subinterpreters+set}" = set; then :
- withval=$with_experimental_isolated_subinterpreters;
-if test "$withval" != no
-then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; };
- $as_echo "#define EXPERIMENTAL_ISOLATED_SUBINTERPRETERS 1" >>confdefs.h
-
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; };
-fi
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
# Check whether to disable test modules. Once set, setup.py will not build
# test extension modules and "make install" will not install test suites.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --disable-test-modules" >&5
], [have_libb2=no])
])
-# --with-experimental-isolated-subinterpreters
-AH_TEMPLATE(EXPERIMENTAL_ISOLATED_SUBINTERPRETERS,
- [Better isolate subinterpreters, experimental build mode.])
-AC_MSG_CHECKING(for --with-experimental-isolated-subinterpreters)
-AC_ARG_WITH(experimental-isolated-subinterpreters,
- AS_HELP_STRING([--with-experimental-isolated-subinterpreters],
- [better isolate subinterpreters, experimental build mode (default is no)]),
-[
-if test "$withval" != no
-then
- AC_MSG_RESULT(yes);
- AC_DEFINE(EXPERIMENTAL_ISOLATED_SUBINTERPRETERS)
-else
- AC_MSG_RESULT(no);
-fi],
-[AC_MSG_RESULT(no)])
-
# Check whether to disable test modules. Once set, setup.py will not build
# test extension modules and "make install" will not install test suites.
AC_MSG_CHECKING([for --disable-test-modules])
/* Define if --enable-ipv6 is specified */
#undef ENABLE_IPV6
-/* Better isolate subinterpreters, experimental build mode. */
-#undef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
-
/* Define to 1 if your system stores words within floats with the most
significant word first */
#undef FLOAT_WORDS_BIGENDIAN