Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ede0439

Browse files
committed
/* An extension mechanism to store arbitrary additional per-thread state.
PyThreadState_GetDict() returns a dictionary that can be used to hold such state; the caller should pick a unique key and store its state there. If PyThreadState_GetDict() returns NULL, an exception has been raised (most likely MemoryError) and the caller should pass on the exception. */ PyObject * PyThreadState_GetDict()
1 parent c45cf02 commit ede0439

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Python/pystate.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ PyThreadState_New(interp)
126126
tstate->ticker = 0;
127127
tstate->tracing = 0;
128128

129+
tstate->dict = NULL;
130+
129131
tstate->curexc_type = NULL;
130132
tstate->curexc_value = NULL;
131133
tstate->curexc_traceback = NULL;
@@ -155,6 +157,8 @@ PyThreadState_Clear(tstate)
155157

156158
ZAP(tstate->frame);
157159

160+
ZAP(tstate->dict);
161+
158162
ZAP(tstate->curexc_type);
159163
ZAP(tstate->curexc_value);
160164
ZAP(tstate->curexc_traceback);
@@ -213,3 +217,20 @@ PyThreadState_Swap(new)
213217

214218
return old;
215219
}
220+
221+
/* An extension mechanism to store arbitrary additional per-thread state.
222+
PyThreadState_GetDict() returns a dictionary that can be used to hold such
223+
state; the caller should pick a unique key and store its state there. If
224+
PyThreadState_GetDict() returns NULL, an exception has been raised (most
225+
likely MemoryError) and the caller should pass on the exception. */
226+
227+
PyObject *
228+
PyThreadState_GetDict()
229+
{
230+
if (current_tstate == NULL)
231+
Py_FatalError("PyThreadState_GetDict: no current thread");
232+
233+
if (current_tstate->dict == NULL)
234+
current_tstate->dict = PyDict_New();
235+
return current_tstate->dict;
236+
}

0 commit comments

Comments
 (0)