Type Alias simics_api_sys::bindings::PyThreadState

source ·
pub type PyThreadState = _ts;
Expand description

struct _ts is defined in cpython/pystate.h

Aliased Type§

struct PyThreadState {
Show 33 fields pub prev: *mut _ts, pub next: *mut _ts, pub interp: *mut _is, pub frame: *mut _frame, pub recursion_depth: i32, pub recursion_headroom: i32, pub stackcheck_counter: i32, pub tracing: i32, pub cframe: *mut _cframe, pub c_profilefunc: Option<unsafe extern "C" fn(_: *mut _object, _: *mut _frame, _: i32, _: *mut _object) -> i32>, pub c_tracefunc: Option<unsafe extern "C" fn(_: *mut _object, _: *mut _frame, _: i32, _: *mut _object) -> i32>, pub c_profileobj: *mut _object, pub c_traceobj: *mut _object, pub curexc_type: *mut _object, pub curexc_value: *mut _object, pub curexc_traceback: *mut _object, pub exc_state: _err_stackitem, pub exc_info: *mut _err_stackitem, pub dict: *mut _object, pub gilstate_counter: i32, pub async_exc: *mut _object, pub thread_id: u64, pub trash_delete_nesting: i32, pub trash_delete_later: *mut _object, pub on_delete: Option<unsafe extern "C" fn(_: *mut c_void)>, pub on_delete_data: *mut c_void, pub coroutine_origin_tracking_depth: i32, pub async_gen_firstiter: *mut _object, pub async_gen_finalizer: *mut _object, pub context: *mut _object, pub context_ver: u64, pub id: u64, pub root_cframe: _cframe,
}

Fields§

§prev: *mut _ts

See Python/ceval.c for comments explaining most fields

§next: *mut _ts§interp: *mut _is§frame: *mut _frame

Borrowed reference to the current frame (it can be NULL)

§recursion_depth: i32§recursion_headroom: i32

Allow 50 more calls to handle any errors.

§stackcheck_counter: i32§tracing: i32

‘tracing’ keeps track of the execution depth when tracing/profiling. This is to prevent the actual trace/profile code from being recorded in the trace/profile.

§cframe: *mut _cframe

Pointer to current CFrame in the C stack frame of the currently, or most recently, executing _PyEval_EvalFrameDefault.

§c_profilefunc: Option<unsafe extern "C" fn(_: *mut _object, _: *mut _frame, _: i32, _: *mut _object) -> i32>§c_tracefunc: Option<unsafe extern "C" fn(_: *mut _object, _: *mut _frame, _: i32, _: *mut _object) -> i32>§c_profileobj: *mut _object§c_traceobj: *mut _object§curexc_type: *mut _object

The exception currently being raised

§curexc_value: *mut _object§curexc_traceback: *mut _object§exc_state: _err_stackitem

The exception currently being handled, if no coroutines/generators are present. Always last element on the stack referred to be exc_info.

§exc_info: *mut _err_stackitem

Pointer to the top of the stack of the exceptions currently being handled

§dict: *mut _object

Stores per-thread state

§gilstate_counter: i32§async_exc: *mut _object

Asynchronous exception to raise

§thread_id: u64

Thread id where this tstate was created

§trash_delete_nesting: i32§trash_delete_later: *mut _object§on_delete: Option<unsafe extern "C" fn(_: *mut c_void)>

Called when a thread state is deleted normally, but not when it is destroyed after fork(). Pain: to prevent rare but fatal shutdown errors (issue 18808), Thread.join() must wait for the join’ed thread’s tstate to be unlinked from the tstate chain. That happens at the end of a thread’s life, in pystate.c. The obvious way doesn’t quite work: create a lock which the tstate unlinking code releases, and have Thread.join() wait to acquire that lock. The problem is that we are at the end of the thread’s life: if the thread holds the last reference to the lock, decref’ing the lock will delete the lock, and that may trigger arbitrary Python code if there’s a weakref, with a callback, to the lock. But by this time _PyRuntime.gilstate.tstate_current is already NULL, so only the simplest of C code can be allowed to run (in particular it must not be possible to release the GIL). So instead of holding the lock directly, the tstate holds a weakref to the lock: that’s the value of on_delete_data below. Decref’ing a weakref is harmless. on_delete points to _threadmodule.c’s static release_sentinel() function. After the tstate is unlinked, release_sentinel is called with the weakref-to-lock (on_delete_data) argument, and release_sentinel releases the indirectly held lock.

§on_delete_data: *mut c_void§coroutine_origin_tracking_depth: i32§async_gen_firstiter: *mut _object§async_gen_finalizer: *mut _object§context: *mut _object§context_ver: u64§id: u64

Unique thread state id.

§root_cframe: _cframe