Mercurial > cpython-lru_cache-weakref
diff Python/pystate.c @ 7970:4ceee1ef99b0 legacy-trunk
/* 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()
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 10 Apr 1998 20:18:25 +0000 |
| parents | a8e3b2e9f5d2 |
| children | 914f83e7fa0a |
line wrap: on
line diff
--- a/Python/pystate.c Fri Apr 10 20:06:21 1998 +0000 +++ b/Python/pystate.c Fri Apr 10 20:18:25 1998 +0000 @@ -126,6 +126,8 @@ 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 @@ ZAP(tstate->frame); + ZAP(tstate->dict); + ZAP(tstate->curexc_type); ZAP(tstate->curexc_value); ZAP(tstate->curexc_traceback); @@ -213,3 +217,20 @@ 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; +}
