diff options
author | Guido van Rossum <guido@python.org> | 1998-04-10 20:18:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-04-10 20:18:25 (GMT) |
commit | ede0439cd8e53c50df8be78bef564fd585dc171d (patch) | |
tree | 44613b43727a729588bc90425eaab25485aa71da /Python/pystate.c | |
parent | c45cf029380f1b95a9d208d7c63843ce8317ad7d (diff) | |
download | cpython-ede0439cd8e53c50df8be78bef564fd585dc171d.zip cpython-ede0439cd8e53c50df8be78bef564fd585dc171d.tar.gz cpython-ede0439cd8e53c50df8be78bef564fd585dc171d.tar.bz2 |
/* 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()
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index f1dc413..e74e34c 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -126,6 +126,8 @@ PyThreadState_New(interp) tstate->ticker = 0; tstate->tracing = 0; + tstate->dict = NULL; + tstate->curexc_type = NULL; tstate->curexc_value = NULL; tstate->curexc_traceback = NULL; @@ -155,6 +157,8 @@ PyThreadState_Clear(tstate) ZAP(tstate->frame); + ZAP(tstate->dict); + ZAP(tstate->curexc_type); ZAP(tstate->curexc_value); ZAP(tstate->curexc_traceback); @@ -213,3 +217,20 @@ PyThreadState_Swap(new) return old; } + +/* 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() +{ + if (current_tstate == NULL) + Py_FatalError("PyThreadState_GetDict: no current thread"); + + if (current_tstate->dict == NULL) + current_tstate->dict = PyDict_New(); + return current_tstate->dict; +} |