summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-25 21:22:55 +0100
committerGitHub <noreply@github.com>2020-03-25 21:22:55 +0100
commit0e427c6d159e86f17270770cd8dc37372e3c4004 (patch)
tree6d2090b90405358e5fca7c5a6ceb023909b4362e /Python/pystate.c
parent302e5a8f79514fd84bafbc44b7c97ec636302322 (diff)
downloadcpython-git-0e427c6d159e86f17270770cd8dc37372e3c4004.tar.gz
bpo-39947: Add _PyThreadState_GetDict() function (GH-19160)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index c7154ea706..66a1d3b492 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -4,9 +4,10 @@
#include "Python.h"
#include "pycore_ceval.h"
#include "pycore_initconfig.h"
+#include "pycore_pyerrors.h"
+#include "pycore_pylifecycle.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
-#include "pycore_pylifecycle.h"
/* --------------------------------------------------------------------------
CAUTION
@@ -980,19 +981,27 @@ PyThreadState_Swap(PyThreadState *newts)
and the caller should assume no per-thread state is available. */
PyObject *
+_PyThreadState_GetDict(PyThreadState *tstate)
+{
+ assert(tstate != NULL);
+ if (tstate->dict == NULL) {
+ tstate->dict = PyDict_New();
+ if (tstate->dict == NULL) {
+ _PyErr_Clear(tstate);
+ }
+ }
+ return tstate->dict;
+}
+
+
+PyObject *
PyThreadState_GetDict(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- if (tstate == NULL)
+ if (tstate == NULL) {
return NULL;
-
- if (tstate->dict == NULL) {
- PyObject *d;
- tstate->dict = d = PyDict_New();
- if (d == NULL)
- PyErr_Clear();
}
- return tstate->dict;
+ return _PyThreadState_GetDict(tstate);
}