boot = PyMem_NEW(struct bootstate, 1);
if (boot == NULL)
return PyErr_NoMemory();
- boot->interp = _PyInterpreterState_Get();
+ boot->interp = _PyInterpreterState_GET_UNSAFE();
boot->func = func;
boot->args = args;
boot->keyw = keyw;
static PyObject *
thread__count(PyObject *self, PyObject *Py_UNUSED(ignored))
{
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
return PyLong_FromLong(interp->num_threads);
}
PyObject *m, *d, *v;
double time_max;
double timeout_max;
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
/* Initialize types: */
if (PyType_Ready(&localdummytype) < 0)
void
PyOS_BeforeFork(void)
{
- run_at_forkers(_PyInterpreterState_Get()->before_forkers, 1);
+ run_at_forkers(_PyInterpreterState_GET_UNSAFE()->before_forkers, 1);
_PyImport_AcquireLock();
}
if (_PyImport_ReleaseLock() <= 0)
Py_FatalError("failed releasing import lock after fork");
- run_at_forkers(_PyInterpreterState_Get()->after_forkers_parent, 0);
+ run_at_forkers(_PyInterpreterState_GET_UNSAFE()->after_forkers_parent, 0);
}
void
_PyRuntimeState_ReInitThreads(runtime);
_PyInterpreterState_DeleteExceptMain(runtime);
- run_at_forkers(_PyInterpreterState_Get()->after_forkers_child, 0);
+ run_at_forkers(_PyInterpreterState_GET_UNSAFE()->after_forkers_child, 0);
}
static int
check_null_or_callable(after_in_parent, "after_in_parent")) {
return NULL;
}
- interp = _PyInterpreterState_Get();
+ interp = _PyInterpreterState_GET_UNSAFE();
if (register_at_forker(&interp->before_forkers, before)) {
return NULL;
{
pid_t pid;
- if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
+ if (_PyInterpreterState_GET_UNSAFE() != PyInterpreterState_Main()) {
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
return NULL;
}
{
pid_t pid;
- if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
+ if (_PyInterpreterState_GET_UNSAFE() != PyInterpreterState_Main()) {
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
return NULL;
}
int master_fd = -1;
pid_t pid;
- if (_PyInterpreterState_Get() != PyInterpreterState_Main()) {
+ if (_PyInterpreterState_GET_UNSAFE() != PyInterpreterState_Main()) {
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
return NULL;
}
PyObject *
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
{
- if (!_PyImport_IsInitialized(_PyInterpreterState_Get())) {
+ if (!_PyImport_IsInitialized(_PyInterpreterState_GET_UNSAFE())) {
PyErr_SetString(PyExc_SystemError,
"Python import machinery not initialized");
return NULL;
static PyObject *
module_repr(PyModuleObject *m)
{
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
return PyObject_CallMethod(interp->importlib, "_module_repr", "O", m);
}
int PyCodec_Register(PyObject *search_function)
{
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
goto onError;
if (search_function == NULL) {
PyObject *v;
int result;
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
if (interp->codec_search_path == NULL) {
return -1;
}
Return 0 on success, -1 on error */
int PyCodec_RegisterError(const char *name, PyObject *error)
{
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
return -1;
if (!PyCallable_Check(error)) {
}
};
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
PyObject *mod;
if (interp->codec_search_path != NULL)
/* Support for dynamic loading of extension modules */
#include "Python.h"
-#include "pycore_pystate.h"
+#include "pycore_pystate.h" // _PyInterpreterState_GET_UNSAFE()
#include "importdl.h"
#include <sys/types.h>
}
}
- dlopenflags = _PyInterpreterState_Get()->dlopenflags;
+ dlopenflags = _PyInterpreterState_GET_UNSAFE()->dlopenflags;
handle = dlopen(pathname, dlopenflags);
PyImport_GetMagicNumber(void)
{
long res;
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
PyObject *external, *pyc_magic;
external = PyObject_GetAttrString(interp->importlib, "_bootstrap_external");
goto failure;
}
- const wchar_t *mode = _PyInterpreterState_Get()->config.check_hash_pycs_mode;
+ const wchar_t *mode = _PyInterpreterState_GET_UNSAFE()->config.check_hash_pycs_mode;
PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1);
if (pyc_mode == NULL) {
goto failure;
Py_CLEAR(dict);
/* pre config */
- PyInterpreterState *interp = _PyInterpreterState_Get();
- const PyPreConfig *pre_config = &_PyRuntime.preconfig;
+ PyThreadState *tstate = _PyThreadState_GET();
+ const PyPreConfig *pre_config = &tstate->interp->runtime->preconfig;
dict = _PyPreConfig_AsDict(pre_config);
if (dict == NULL) {
goto error;
Py_CLEAR(dict);
/* core config */
- const PyConfig *config = &interp->config;
+ const PyConfig *config = &tstate->interp->config;
dict = config_as_dict(config);
if (dict == NULL) {
goto error;
PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
int nomem_count = 0;
#ifdef Py_REF_DEBUG
- int show_ref_count = _PyInterpreterState_Get()->config.show_ref_count;
+ int show_ref_count = _PyInterpreterState_GET_UNSAFE()->config.show_ref_count;
#endif
filename = PyUnicode_DecodeFSDefault(filename_str);
filename_obj = PyUnicode_DecodeFSDefault(filename);
if (filename_obj == NULL)
return -1;
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
bootstrap = PyObject_GetAttrString(interp->importlib,
"_bootstrap_external");
if (bootstrap != NULL) {
/* Set globals['__builtins__'] if it doesn't exist */
if (globals != NULL && PyDict_GetItemString(globals, "__builtins__") == NULL) {
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
if (PyDict_SetItemString(globals, "__builtins__", interp->builtins) < 0) {
return NULL;
}
size_t
PyThread_get_stacksize(void)
{
- return _PyInterpreterState_Get()->pythread_stacksize;
+ return _PyInterpreterState_GET_UNSAFE()->pythread_stacksize;
}
/* Only platforms defining a THREAD_SET_STACKSIZE() macro