diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-03-15 23:47:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 23:47:43 (GMT) |
commit | d2fdd1fedf6b9dc785cf5025b548a989faed089a (patch) | |
tree | fad1d8a72d9dea315758219cd5f1122ba0d0a87a /Python/pystate.c | |
parent | c11183cdcff6af13c4339fdcce84ab63f7930ddc (diff) | |
download | cpython-d2fdd1fedf6b9dc785cf5025b548a989faed089a.zip cpython-d2fdd1fedf6b9dc785cf5025b548a989faed089a.tar.gz cpython-d2fdd1fedf6b9dc785cf5025b548a989faed089a.tar.bz2 |
bpo-36124: Add PyInterpreterState.dict. (gh-12132)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index cdf5a69..6a2dc10 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -224,6 +224,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->builtins_copy); Py_CLEAR(interp->importlib); Py_CLEAR(interp->import_func); + Py_CLEAR(interp->dict); #ifdef HAVE_FORK Py_CLEAR(interp->before_forkers); Py_CLEAR(interp->after_forkers_parent); @@ -462,6 +463,19 @@ _PyInterpreterState_GetMainModule(PyInterpreterState *interp) return PyMapping_GetItemString(interp->modules, "__main__"); } +PyObject * +PyInterpreterState_GetDict(PyInterpreterState *interp) +{ + if (interp->dict == NULL) { + interp->dict = PyDict_New(); + if (interp->dict == NULL) { + PyErr_Clear(); + } + } + /* Returning NULL means no per-interpreter dict is available. */ + return interp->dict; +} + /* Default implementation for _PyThreadState_GetFrame */ static struct _frame * threadstate_getframe(PyThreadState *self) |