mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-39947: Add _PyThreadState_GetDict() function (GH-19160)
This commit is contained in:
parent
302e5a8f79
commit
0e427c6d15
3 changed files with 23 additions and 11 deletions
|
|
@ -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
|
||||
|
|
@ -979,20 +980,28 @@ PyThreadState_Swap(PyThreadState *newts)
|
|||
PyThreadState_GetDict() returns NULL, an exception has *not* been raised
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue