Lines Matching defs:tstate

48 static void _PyThreadState_Delete(PyThreadState *tstate, int check_current);
223 struct _gilstate_runtime_state *gilstate, PyThreadState* tstate);
305 PyThreadState *tstate = _PyThreadState_GET();
307 /* tstate is NULL when Py_InitializeFromConfig() calls
309 if (_PySys_Audit(tstate, "cpython.PyInterpreterState_New", NULL) < 0) {
315 if (tstate != NULL) {
316 _PyErr_NoMemory(tstate);
321 /* Don't get runtime from tstate since tstate can be NULL. */
365 if (tstate != NULL) {
366 _PyErr_SetString(tstate, PyExc_RuntimeError,
391 interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
395 if (_PySys_Audit(tstate, "cpython.PyInterpreterState_Clear", NULL) < 0) {
396 _PyErr_Clear(tstate);
440 _PyGC_CollectNoFail(tstate);
470 _PyInterpreterState_Clear(PyThreadState *tstate)
472 interpreter_clear(tstate->interp, tstate);
479 PyThreadState *tstate;
482 while ((tstate = interp->threads.head) != NULL) {
483 _PyThreadState_Delete(tstate, check_current);
541 PyThreadState *tstate = _PyThreadState_Swap(gilstate, NULL);
542 if (tstate != NULL && tstate->interp != interpreters->main) {
571 _PyThreadState_Swap(gilstate, tstate);
580 PyThreadState *tstate = _PyThreadState_GET();
581 _Py_EnsureTstateNotNULL(tstate);
582 PyInterpreterState *interp = tstate->interp;
681 PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
683 PyThreadState *save_tstate = _PyThreadState_Swap(gilstate, tstate);
684 Py_EndInterpreter(tstate);
748 free_threadstate(PyThreadState *tstate)
750 if (!tstate->_static) {
751 PyMem_RawFree(tstate);
764 init_threadstate(PyThreadState *tstate,
768 if (tstate->_initialized) {
773 tstate->interp = interp;
776 tstate->id = id;
778 assert(interp->threads.head == tstate);
781 assert(next->prev == NULL || next->prev == tstate);
782 next->prev = tstate;
784 tstate->next = next;
785 assert(tstate->prev == NULL);
787 tstate->thread_id = PyThread_get_thread_ident();
789 tstate->native_thread_id = PyThread_get_thread_native_id();
792 tstate->recursion_limit = interp->ceval.recursion_limit,
793 tstate->recursion_remaining = interp->ceval.recursion_limit,
795 tstate->exc_info = &tstate->exc_state;
797 tstate->cframe = &tstate->root_cframe;
798 tstate->datastack_chunk = NULL;
799 tstate->datastack_top = NULL;
800 tstate->datastack_limit = NULL;
802 tstate->_initialized = 1;
808 PyThreadState *tstate;
831 tstate = &interp->_initial_thread;
832 assert(tstate->_static);
839 tstate = new_tstate;
841 memcpy(tstate,
843 sizeof(*tstate));
846 tstate->_static = false;
848 interp->threads.head = tstate;
850 init_threadstate(tstate, interp, id, old_head);
857 return tstate;
863 PyThreadState *tstate = new_threadstate(interp);
864 _PyThreadState_SetCurrent(tstate);
865 return tstate;
877 _PyThreadState_Init(PyThreadState *tstate)
883 _PyThreadState_SetCurrent(PyThreadState *tstate)
885 _PyGILState_NoteThreadState(&tstate->interp->runtime->gilstate, tstate);
908 _PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
911 assert(_PyErr_Occurred(tstate));
915 _PyErr_SetString(tstate,
921 PyInterpreterState *interp = tstate->interp;
948 PyThreadState *tstate = _PyThreadState_GET();
949 PyInterpreterState *interp = tstate->interp;
958 return _PyState_AddModule(tstate, module, def);
964 PyThreadState *tstate = _PyThreadState_GET();
965 PyInterpreterState *interp = tstate->interp;
968 _PyErr_SetString(tstate,
1019 PyThreadState_Clear(PyThreadState *tstate)
1021 int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
1023 if (verbose && tstate->cframe->current_frame != NULL) {
1027 _PyEval_EvalFrameDefault(), tstate->frame is not reset to its
1035 /* Don't clear tstate->pyframe: it is a borrowed reference */
1037 Py_CLEAR(tstate->dict);
1038 Py_CLEAR(tstate->async_exc);
1040 Py_CLEAR(tstate->curexc_type);
1041 Py_CLEAR(tstate->curexc_value);
1042 Py_CLEAR(tstate->curexc_traceback);
1044 Py_CLEAR(tstate->exc_state.exc_value);
1047 if (verbose && tstate->exc_info != &tstate->exc_state) {
1052 tstate->c_profilefunc = NULL;
1053 tstate->c_tracefunc = NULL;
1054 Py_CLEAR(tstate->c_profileobj);
1055 Py_CLEAR(tstate->c_traceobj);
1057 Py_CLEAR(tstate->async_gen_firstiter);
1058 Py_CLEAR(tstate->async_gen_finalizer);
1060 Py_CLEAR(tstate->context);
1062 if (tstate->on_delete != NULL) {
1063 tstate->on_delete(tstate->on_delete_data);
1070 tstate_delete_common(PyThreadState *tstate,
1073 _Py_EnsureTstateNotNULL(tstate);
1074 PyInterpreterState *interp = tstate->interp;
1081 if (tstate->prev) {
1082 tstate->prev->next = tstate->next;
1085 interp->threads.head = tstate->next;
1087 if (tstate->next) {
1088 tstate->next->prev = tstate->prev;
1093 PyThread_tss_get(&gilstate->autoTSSkey) == tstate)
1097 _PyStackChunk *chunk = tstate->datastack_chunk;
1098 tstate->datastack_chunk = NULL;
1107 _PyThreadState_Delete(PyThreadState *tstate, int check_current)
1109 struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
1111 if (tstate == _PyRuntimeGILState_GetThreadState(gilstate)) {
1112 _Py_FatalErrorFormat(__func__, "tstate %p is still current", tstate);
1115 tstate_delete_common(tstate, gilstate);
1116 free_threadstate(tstate);
1121 PyThreadState_Delete(PyThreadState *tstate)
1123 _PyThreadState_Delete(tstate, 1);
1128 _PyThreadState_DeleteCurrent(PyThreadState *tstate)
1130 _Py_EnsureTstateNotNULL(tstate);
1131 struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
1132 tstate_delete_common(tstate, gilstate);
1134 _PyEval_ReleaseLock(tstate);
1135 free_threadstate(tstate);
1142 PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
1143 _PyThreadState_DeleteCurrent(tstate);
1155 _PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
1157 PyInterpreterState *interp = tstate->interp;
1160 /* Remove all thread states, except tstate, from the linked list of
1164 if (list == tstate) {
1165 list = tstate->next;
1167 if (tstate->prev) {
1168 tstate->prev->next = tstate->next;
1170 if (tstate->next) {
1171 tstate->next->prev = tstate->prev;
1173 tstate->prev = tstate->next = NULL;
1174 interp->threads.head = tstate;
1199 PyThreadState *tstate = _PyThreadState_GET();
1200 _Py_EnsureTstateNotNULL(tstate);
1201 return tstate;
1243 _PyThreadState_GetDict(PyThreadState *tstate)
1245 assert(tstate != NULL);
1246 if (tstate->dict == NULL) {
1247 tstate->dict = PyDict_New();
1248 if (tstate->dict == NULL) {
1249 _PyErr_Clear(tstate);
1252 return tstate->dict;
1259 PyThreadState *tstate = _PyThreadState_GET();
1260 if (tstate == NULL) {
1263 return _PyThreadState_GetDict(tstate);
1268 PyThreadState_GetInterpreter(PyThreadState *tstate)
1270 assert(tstate != NULL);
1271 return tstate->interp;
1276 PyThreadState_GetFrame(PyThreadState *tstate)
1278 assert(tstate != NULL);
1279 _PyInterpreterFrame *f = tstate->cframe->current_frame;
1296 PyThreadState_GetID(PyThreadState *tstate)
1298 assert(tstate != NULL);
1299 return tstate->id;
1324 for (PyThreadState *tstate = interp->threads.head; tstate != NULL; tstate = tstate->next) {
1325 if (tstate->thread_id != id) {
1330 * (if any) in tstate->async_exc, but that can in turn
1336 PyObject *old_exc = tstate->async_exc;
1338 tstate->async_exc = exc;
1342 _PyEval_SignalAsyncExc(tstate->interp);
1375 PyThreadState_Next(PyThreadState *tstate) {
1376 return tstate->next;
1387 PyThreadState *tstate = _PyThreadState_GET();
1388 if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
1403 _PyRuntimeState *runtime = tstate->interp->runtime;
1445 PyThreadState *tstate = _PyThreadState_GET();
1447 _Py_EnsureTstateNotNULL(tstate);
1449 if (_PySys_Audit(tstate, "sys._current_exceptions", NULL) < 0) {
1464 _PyRuntimeState *runtime = tstate->interp->runtime;
1512 PyThreadState_IsCurrent(PyThreadState *tstate)
1514 /* Must be the tstate for this thread */
1516 assert(_PyGILState_GetThisThreadState(gilstate) == tstate);
1517 return tstate == _PyRuntimeGILState_GetThreadState(gilstate);
1538 _PyGILState_SetTstate(PyThreadState *tstate)
1540 if (!_Py_IsMainInterpreter(tstate->interp)) {
1547 assert(tstate != NULL);
1548 assert(tstate->interp != NULL);
1550 struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
1552 gilstate->autoInterpreterState = tstate->interp;
1554 assert(tstate->gilstate_counter == 0);
1556 _PyGILState_NoteThreadState(gilstate, tstate);
1583 PyThreadState *tstate = _PyGILState_GetThisThreadState(gilstate);
1592 if (tstate &&
1593 PyThread_tss_set(&gilstate->autoTSSkey, (void *)tstate) != 0)
1607 _PyGILState_NoteThreadState(struct _gilstate_runtime_state *gilstate, PyThreadState* tstate)
1629 if ((PyThread_tss_set(&gilstate->autoTSSkey, (void *)tstate)) != 0) {
1635 tstate->gilstate_counter = 1;
1665 PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
1666 if (tstate == NULL) {
1670 return (tstate == _PyGILState_GetThisThreadState(gilstate));
1725 PyThreadState *tstate = PyThread_tss_get(&runtime->gilstate.autoTSSkey);
1726 if (tstate == NULL) {
1736 if (!PyThreadState_IsCurrent(tstate)) {
1739 tstate);
1741 assert(PyThreadState_IsCurrent(tstate));
1742 --tstate->gilstate_counter;
1743 assert(tstate->gilstate_counter >= 0); /* illegal counter value */
1748 if (tstate->gilstate_counter == 0) {
1751 PyThreadState_Clear(tstate);
1757 assert(_PyRuntimeGILState_GetThreadState(&runtime->gilstate) == tstate);
1758 _PyThreadState_DeleteCurrent(tstate);
1797 _check_xidata(PyThreadState *tstate, _PyCrossInterpreterData *data)
1804 _PyErr_SetString(tstate, PyExc_SystemError, "missing interp");
1809 _PyErr_SetString(tstate, PyExc_SystemError, "missing new_object func");
1821 PyThreadState *tstate = _PyThreadState_GET();
1824 _Py_EnsureTstateNotNULL(tstate);
1826 PyInterpreterState *interp = tstate->interp;
1847 if (_check_xidata(tstate, data) != 0) {
1877 PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
1879 save_tstate = _PyThreadState_Swap(gilstate, tstate);
2171 PyThreadState *tstate = _PyThreadState_GET();
2172 return _PyInterpreterState_GetConfig(tstate->interp);
2178 push_chunk(PyThreadState *tstate, int size)
2184 _PyStackChunk *new = allocate_chunk(allocate_size, tstate->datastack_chunk);
2188 if (tstate->datastack_chunk) {
2189 tstate->datastack_chunk->top = tstate->datastack_top -
2190 &tstate->datastack_chunk->data[0];
2192 tstate->datastack_chunk = new;
2193 tstate->datastack_limit = (PyObject **)(((char *)new) + allocate_size);
2198 tstate->datastack_top = res + size;
2203 _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size)
2205 if (_PyThreadState_HasStackSpace(tstate, size)) {
2206 _PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
2207 tstate->datastack_top += size;
2214 return (_PyInterpreterFrame *)push_chunk(tstate, (int)size);
2218 _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame)
2220 assert(tstate->datastack_chunk);
2222 if (base == &tstate->datastack_chunk->data[0]) {
2223 _PyStackChunk *chunk = tstate->datastack_chunk;
2227 tstate->datastack_top = &previous->data[previous->top];
2228 tstate->datastack_chunk = previous;
2230 tstate->datastack_limit = (PyObject **)(((char *)previous) + previous->size);
2233 assert(tstate->datastack_top);
2234 assert(tstate->datastack_top >= base);
2235 tstate->datastack_top = base;