17db96d56Sopenharmony_ci#ifndef Py_CPYTHON_PYSTATE_H 27db96d56Sopenharmony_ci# error "this header file must not be included directly" 37db96d56Sopenharmony_ci#endif 47db96d56Sopenharmony_ci 57db96d56Sopenharmony_ci 67db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); 77db96d56Sopenharmony_ciPyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int); 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyInterpreterState_GetMainModule(PyInterpreterState *); 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci/* State unique per thread */ 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci/* Py_tracefunc return -1 when raising an exception, or 0 for success. */ 147db96d56Sopenharmony_citypedef int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *); 157db96d56Sopenharmony_ci 167db96d56Sopenharmony_ci/* The following values are used for 'what' for tracefunc functions 177db96d56Sopenharmony_ci * 187db96d56Sopenharmony_ci * To add a new kind of trace event, also update "trace_init" in 197db96d56Sopenharmony_ci * Python/sysmodule.c to define the Python level event name 207db96d56Sopenharmony_ci */ 217db96d56Sopenharmony_ci#define PyTrace_CALL 0 227db96d56Sopenharmony_ci#define PyTrace_EXCEPTION 1 237db96d56Sopenharmony_ci#define PyTrace_LINE 2 247db96d56Sopenharmony_ci#define PyTrace_RETURN 3 257db96d56Sopenharmony_ci#define PyTrace_C_CALL 4 267db96d56Sopenharmony_ci#define PyTrace_C_EXCEPTION 5 277db96d56Sopenharmony_ci#define PyTrace_C_RETURN 6 287db96d56Sopenharmony_ci#define PyTrace_OPCODE 7 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci 317db96d56Sopenharmony_citypedef struct { 327db96d56Sopenharmony_ci PyCodeObject *code; // The code object for the bounds. May be NULL. 337db96d56Sopenharmony_ci PyCodeAddressRange bounds; // Only valid if code != NULL. 347db96d56Sopenharmony_ci} PyTraceInfo; 357db96d56Sopenharmony_ci 367db96d56Sopenharmony_ci// Internal structure: you should not use it directly, but use public functions 377db96d56Sopenharmony_ci// like PyThreadState_EnterTracing() and PyThreadState_LeaveTracing(). 387db96d56Sopenharmony_citypedef struct _PyCFrame { 397db96d56Sopenharmony_ci /* This struct will be threaded through the C stack 407db96d56Sopenharmony_ci * allowing fast access to per-thread state that needs 417db96d56Sopenharmony_ci * to be accessed quickly by the interpreter, but can 427db96d56Sopenharmony_ci * be modified outside of the interpreter. 437db96d56Sopenharmony_ci * 447db96d56Sopenharmony_ci * WARNING: This makes data on the C stack accessible from 457db96d56Sopenharmony_ci * heap objects. Care must be taken to maintain stack 467db96d56Sopenharmony_ci * discipline and make sure that instances of this struct cannot 477db96d56Sopenharmony_ci * accessed outside of their lifetime. 487db96d56Sopenharmony_ci */ 497db96d56Sopenharmony_ci uint8_t use_tracing; // 0 or 255 (or'ed into opcode, hence 8-bit type) 507db96d56Sopenharmony_ci /* Pointer to the currently executing frame (it can be NULL) */ 517db96d56Sopenharmony_ci struct _PyInterpreterFrame *current_frame; 527db96d56Sopenharmony_ci struct _PyCFrame *previous; 537db96d56Sopenharmony_ci} _PyCFrame; 547db96d56Sopenharmony_ci 557db96d56Sopenharmony_citypedef struct _err_stackitem { 567db96d56Sopenharmony_ci /* This struct represents a single execution context where we might 577db96d56Sopenharmony_ci * be currently handling an exception. It is a per-coroutine state 587db96d56Sopenharmony_ci * (coroutine in the computer science sense, including the thread 597db96d56Sopenharmony_ci * and generators). 607db96d56Sopenharmony_ci * 617db96d56Sopenharmony_ci * This is used as an entry on the exception stack, where each 627db96d56Sopenharmony_ci * entry indicates if it is currently handling an exception. 637db96d56Sopenharmony_ci * This ensures that the exception state is not impacted 647db96d56Sopenharmony_ci * by "yields" from an except handler. The thread 657db96d56Sopenharmony_ci * always has an entry (the bottom-most one). 667db96d56Sopenharmony_ci */ 677db96d56Sopenharmony_ci 687db96d56Sopenharmony_ci /* The exception currently being handled in this context, if any. */ 697db96d56Sopenharmony_ci PyObject *exc_value; 707db96d56Sopenharmony_ci 717db96d56Sopenharmony_ci struct _err_stackitem *previous_item; 727db96d56Sopenharmony_ci 737db96d56Sopenharmony_ci} _PyErr_StackItem; 747db96d56Sopenharmony_ci 757db96d56Sopenharmony_citypedef struct _stack_chunk { 767db96d56Sopenharmony_ci struct _stack_chunk *previous; 777db96d56Sopenharmony_ci size_t size; 787db96d56Sopenharmony_ci size_t top; 797db96d56Sopenharmony_ci PyObject * data[1]; /* Variable sized */ 807db96d56Sopenharmony_ci} _PyStackChunk; 817db96d56Sopenharmony_ci 827db96d56Sopenharmony_cistruct _ts { 837db96d56Sopenharmony_ci /* See Python/ceval.c for comments explaining most fields */ 847db96d56Sopenharmony_ci 857db96d56Sopenharmony_ci PyThreadState *prev; 867db96d56Sopenharmony_ci PyThreadState *next; 877db96d56Sopenharmony_ci PyInterpreterState *interp; 887db96d56Sopenharmony_ci 897db96d56Sopenharmony_ci /* Has been initialized to a safe state. 907db96d56Sopenharmony_ci 917db96d56Sopenharmony_ci In order to be effective, this must be set to 0 during or right 927db96d56Sopenharmony_ci after allocation. */ 937db96d56Sopenharmony_ci int _initialized; 947db96d56Sopenharmony_ci 957db96d56Sopenharmony_ci /* Was this thread state statically allocated? */ 967db96d56Sopenharmony_ci int _static; 977db96d56Sopenharmony_ci 987db96d56Sopenharmony_ci int recursion_remaining; 997db96d56Sopenharmony_ci int recursion_limit; 1007db96d56Sopenharmony_ci int recursion_headroom; /* Allow 50 more calls to handle any errors. */ 1017db96d56Sopenharmony_ci 1027db96d56Sopenharmony_ci /* 'tracing' keeps track of the execution depth when tracing/profiling. 1037db96d56Sopenharmony_ci This is to prevent the actual trace/profile code from being recorded in 1047db96d56Sopenharmony_ci the trace/profile. */ 1057db96d56Sopenharmony_ci int tracing; 1067db96d56Sopenharmony_ci int tracing_what; /* The event currently being traced, if any. */ 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci /* Pointer to current _PyCFrame in the C stack frame of the currently, 1097db96d56Sopenharmony_ci * or most recently, executing _PyEval_EvalFrameDefault. */ 1107db96d56Sopenharmony_ci _PyCFrame *cframe; 1117db96d56Sopenharmony_ci 1127db96d56Sopenharmony_ci Py_tracefunc c_profilefunc; 1137db96d56Sopenharmony_ci Py_tracefunc c_tracefunc; 1147db96d56Sopenharmony_ci PyObject *c_profileobj; 1157db96d56Sopenharmony_ci PyObject *c_traceobj; 1167db96d56Sopenharmony_ci 1177db96d56Sopenharmony_ci /* The exception currently being raised */ 1187db96d56Sopenharmony_ci PyObject *curexc_type; 1197db96d56Sopenharmony_ci PyObject *curexc_value; 1207db96d56Sopenharmony_ci PyObject *curexc_traceback; 1217db96d56Sopenharmony_ci 1227db96d56Sopenharmony_ci /* Pointer to the top of the exception stack for the exceptions 1237db96d56Sopenharmony_ci * we may be currently handling. (See _PyErr_StackItem above.) 1247db96d56Sopenharmony_ci * This is never NULL. */ 1257db96d56Sopenharmony_ci _PyErr_StackItem *exc_info; 1267db96d56Sopenharmony_ci 1277db96d56Sopenharmony_ci PyObject *dict; /* Stores per-thread state */ 1287db96d56Sopenharmony_ci 1297db96d56Sopenharmony_ci int gilstate_counter; 1307db96d56Sopenharmony_ci 1317db96d56Sopenharmony_ci PyObject *async_exc; /* Asynchronous exception to raise */ 1327db96d56Sopenharmony_ci unsigned long thread_id; /* Thread id where this tstate was created */ 1337db96d56Sopenharmony_ci 1347db96d56Sopenharmony_ci /* Native thread id where this tstate was created. This will be 0 except on 1357db96d56Sopenharmony_ci * those platforms that have the notion of native thread id, for which the 1367db96d56Sopenharmony_ci * macro PY_HAVE_THREAD_NATIVE_ID is then defined. 1377db96d56Sopenharmony_ci */ 1387db96d56Sopenharmony_ci unsigned long native_thread_id; 1397db96d56Sopenharmony_ci 1407db96d56Sopenharmony_ci int trash_delete_nesting; 1417db96d56Sopenharmony_ci PyObject *trash_delete_later; 1427db96d56Sopenharmony_ci 1437db96d56Sopenharmony_ci /* Called when a thread state is deleted normally, but not when it 1447db96d56Sopenharmony_ci * is destroyed after fork(). 1457db96d56Sopenharmony_ci * Pain: to prevent rare but fatal shutdown errors (issue 18808), 1467db96d56Sopenharmony_ci * Thread.join() must wait for the join'ed thread's tstate to be unlinked 1477db96d56Sopenharmony_ci * from the tstate chain. That happens at the end of a thread's life, 1487db96d56Sopenharmony_ci * in pystate.c. 1497db96d56Sopenharmony_ci * The obvious way doesn't quite work: create a lock which the tstate 1507db96d56Sopenharmony_ci * unlinking code releases, and have Thread.join() wait to acquire that 1517db96d56Sopenharmony_ci * lock. The problem is that we _are_ at the end of the thread's life: 1527db96d56Sopenharmony_ci * if the thread holds the last reference to the lock, decref'ing the 1537db96d56Sopenharmony_ci * lock will delete the lock, and that may trigger arbitrary Python code 1547db96d56Sopenharmony_ci * if there's a weakref, with a callback, to the lock. But by this time 1557db96d56Sopenharmony_ci * _PyRuntime.gilstate.tstate_current is already NULL, so only the simplest 1567db96d56Sopenharmony_ci * of C code can be allowed to run (in particular it must not be possible to 1577db96d56Sopenharmony_ci * release the GIL). 1587db96d56Sopenharmony_ci * So instead of holding the lock directly, the tstate holds a weakref to 1597db96d56Sopenharmony_ci * the lock: that's the value of on_delete_data below. Decref'ing a 1607db96d56Sopenharmony_ci * weakref is harmless. 1617db96d56Sopenharmony_ci * on_delete points to _threadmodule.c's static release_sentinel() function. 1627db96d56Sopenharmony_ci * After the tstate is unlinked, release_sentinel is called with the 1637db96d56Sopenharmony_ci * weakref-to-lock (on_delete_data) argument, and release_sentinel releases 1647db96d56Sopenharmony_ci * the indirectly held lock. 1657db96d56Sopenharmony_ci */ 1667db96d56Sopenharmony_ci void (*on_delete)(void *); 1677db96d56Sopenharmony_ci void *on_delete_data; 1687db96d56Sopenharmony_ci 1697db96d56Sopenharmony_ci int coroutine_origin_tracking_depth; 1707db96d56Sopenharmony_ci 1717db96d56Sopenharmony_ci PyObject *async_gen_firstiter; 1727db96d56Sopenharmony_ci PyObject *async_gen_finalizer; 1737db96d56Sopenharmony_ci 1747db96d56Sopenharmony_ci PyObject *context; 1757db96d56Sopenharmony_ci uint64_t context_ver; 1767db96d56Sopenharmony_ci 1777db96d56Sopenharmony_ci /* Unique thread state id. */ 1787db96d56Sopenharmony_ci uint64_t id; 1797db96d56Sopenharmony_ci 1807db96d56Sopenharmony_ci PyTraceInfo trace_info; 1817db96d56Sopenharmony_ci 1827db96d56Sopenharmony_ci _PyStackChunk *datastack_chunk; 1837db96d56Sopenharmony_ci PyObject **datastack_top; 1847db96d56Sopenharmony_ci PyObject **datastack_limit; 1857db96d56Sopenharmony_ci /* XXX signal handlers should also be here */ 1867db96d56Sopenharmony_ci 1877db96d56Sopenharmony_ci /* The following fields are here to avoid allocation during init. 1887db96d56Sopenharmony_ci The data is exposed through PyThreadState pointer fields. 1897db96d56Sopenharmony_ci These fields should not be accessed directly outside of init. 1907db96d56Sopenharmony_ci This is indicated by an underscore prefix on the field names. 1917db96d56Sopenharmony_ci 1927db96d56Sopenharmony_ci All other PyInterpreterState pointer fields are populated when 1937db96d56Sopenharmony_ci needed and default to NULL. 1947db96d56Sopenharmony_ci */ 1957db96d56Sopenharmony_ci // Note some fields do not have a leading underscore for backward 1967db96d56Sopenharmony_ci // compatibility. See https://bugs.python.org/issue45953#msg412046. 1977db96d56Sopenharmony_ci 1987db96d56Sopenharmony_ci /* The thread's exception stack entry. (Always the last entry.) */ 1997db96d56Sopenharmony_ci _PyErr_StackItem exc_state; 2007db96d56Sopenharmony_ci 2017db96d56Sopenharmony_ci /* The bottom-most frame on the stack. */ 2027db96d56Sopenharmony_ci _PyCFrame root_cframe; 2037db96d56Sopenharmony_ci}; 2047db96d56Sopenharmony_ci 2057db96d56Sopenharmony_ci 2067db96d56Sopenharmony_ci/* other API */ 2077db96d56Sopenharmony_ci 2087db96d56Sopenharmony_ci// Alias for backward compatibility with Python 3.8 2097db96d56Sopenharmony_ci#define _PyInterpreterState_Get PyInterpreterState_Get 2107db96d56Sopenharmony_ci 2117db96d56Sopenharmony_ciPyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *); 2127db96d56Sopenharmony_ci 2137db96d56Sopenharmony_ci/* Similar to PyThreadState_Get(), but don't issue a fatal error 2147db96d56Sopenharmony_ci * if it is NULL. */ 2157db96d56Sopenharmony_ciPyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void); 2167db96d56Sopenharmony_ci 2177db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyThreadState_GetDict(PyThreadState *tstate); 2187db96d56Sopenharmony_ci 2197db96d56Sopenharmony_ci// Disable tracing and profiling. 2207db96d56Sopenharmony_ciPyAPI_FUNC(void) PyThreadState_EnterTracing(PyThreadState *tstate); 2217db96d56Sopenharmony_ci 2227db96d56Sopenharmony_ci// Reset tracing and profiling: enable them if a trace function or a profile 2237db96d56Sopenharmony_ci// function is set, otherwise disable them. 2247db96d56Sopenharmony_ciPyAPI_FUNC(void) PyThreadState_LeaveTracing(PyThreadState *tstate); 2257db96d56Sopenharmony_ci 2267db96d56Sopenharmony_ci/* PyGILState */ 2277db96d56Sopenharmony_ci 2287db96d56Sopenharmony_ci/* Helper/diagnostic function - return 1 if the current thread 2297db96d56Sopenharmony_ci currently holds the GIL, 0 otherwise. 2307db96d56Sopenharmony_ci 2317db96d56Sopenharmony_ci The function returns 1 if _PyGILState_check_enabled is non-zero. */ 2327db96d56Sopenharmony_ciPyAPI_FUNC(int) PyGILState_Check(void); 2337db96d56Sopenharmony_ci 2347db96d56Sopenharmony_ci/* Get the single PyInterpreterState used by this process' GILState 2357db96d56Sopenharmony_ci implementation. 2367db96d56Sopenharmony_ci 2377db96d56Sopenharmony_ci This function doesn't check for error. Return NULL before _PyGILState_Init() 2387db96d56Sopenharmony_ci is called and after _PyGILState_Fini() is called. 2397db96d56Sopenharmony_ci 2407db96d56Sopenharmony_ci See also _PyInterpreterState_Get() and _PyInterpreterState_GET(). */ 2417db96d56Sopenharmony_ciPyAPI_FUNC(PyInterpreterState *) _PyGILState_GetInterpreterStateUnsafe(void); 2427db96d56Sopenharmony_ci 2437db96d56Sopenharmony_ci/* The implementation of sys._current_frames() Returns a dict mapping 2447db96d56Sopenharmony_ci thread id to that thread's current frame. 2457db96d56Sopenharmony_ci*/ 2467db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void); 2477db96d56Sopenharmony_ci 2487db96d56Sopenharmony_ci/* The implementation of sys._current_exceptions() Returns a dict mapping 2497db96d56Sopenharmony_ci thread id to that thread's current exception. 2507db96d56Sopenharmony_ci*/ 2517db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyThread_CurrentExceptions(void); 2527db96d56Sopenharmony_ci 2537db96d56Sopenharmony_ci/* Routines for advanced debuggers, requested by David Beazley. 2547db96d56Sopenharmony_ci Don't use unless you know what you are doing! */ 2557db96d56Sopenharmony_ciPyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Main(void); 2567db96d56Sopenharmony_ciPyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); 2577db96d56Sopenharmony_ciPyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); 2587db96d56Sopenharmony_ciPyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); 2597db96d56Sopenharmony_ciPyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); 2607db96d56Sopenharmony_ciPyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); 2617db96d56Sopenharmony_ci 2627db96d56Sopenharmony_ci/* Frame evaluation API */ 2637db96d56Sopenharmony_ci 2647db96d56Sopenharmony_citypedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int); 2657db96d56Sopenharmony_ci 2667db96d56Sopenharmony_ciPyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( 2677db96d56Sopenharmony_ci PyInterpreterState *interp); 2687db96d56Sopenharmony_ciPyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc( 2697db96d56Sopenharmony_ci PyInterpreterState *interp, 2707db96d56Sopenharmony_ci _PyFrameEvalFunction eval_frame); 2717db96d56Sopenharmony_ci 2727db96d56Sopenharmony_ciPyAPI_FUNC(const PyConfig*) _PyInterpreterState_GetConfig(PyInterpreterState *interp); 2737db96d56Sopenharmony_ci 2747db96d56Sopenharmony_ci/* Get a copy of the current interpreter configuration. 2757db96d56Sopenharmony_ci 2767db96d56Sopenharmony_ci Return 0 on success. Raise an exception and return -1 on error. 2777db96d56Sopenharmony_ci 2787db96d56Sopenharmony_ci The caller must initialize 'config', using PyConfig_InitPythonConfig() 2797db96d56Sopenharmony_ci for example. 2807db96d56Sopenharmony_ci 2817db96d56Sopenharmony_ci Python must be preinitialized to call this method. 2827db96d56Sopenharmony_ci The caller must hold the GIL. */ 2837db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy( 2847db96d56Sopenharmony_ci struct PyConfig *config); 2857db96d56Sopenharmony_ci 2867db96d56Sopenharmony_ci/* Set the configuration of the current interpreter. 2877db96d56Sopenharmony_ci 2887db96d56Sopenharmony_ci This function should be called during or just after the Python 2897db96d56Sopenharmony_ci initialization. 2907db96d56Sopenharmony_ci 2917db96d56Sopenharmony_ci Update the sys module with the new configuration. If the sys module was 2927db96d56Sopenharmony_ci modified directly after the Python initialization, these changes are lost. 2937db96d56Sopenharmony_ci 2947db96d56Sopenharmony_ci Some configuration like faulthandler or warnoptions can be updated in the 2957db96d56Sopenharmony_ci configuration, but don't reconfigure Python (don't enable/disable 2967db96d56Sopenharmony_ci faulthandler and don't reconfigure warnings filters). 2977db96d56Sopenharmony_ci 2987db96d56Sopenharmony_ci Return 0 on success. Raise an exception and return -1 on error. 2997db96d56Sopenharmony_ci 3007db96d56Sopenharmony_ci The configuration should come from _PyInterpreterState_GetConfigCopy(). */ 3017db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyInterpreterState_SetConfig( 3027db96d56Sopenharmony_ci const struct PyConfig *config); 3037db96d56Sopenharmony_ci 3047db96d56Sopenharmony_ci// Get the configuration of the current interpreter. 3057db96d56Sopenharmony_ci// The caller must hold the GIL. 3067db96d56Sopenharmony_ciPyAPI_FUNC(const PyConfig*) _Py_GetConfig(void); 3077db96d56Sopenharmony_ci 3087db96d56Sopenharmony_ci 3097db96d56Sopenharmony_ci/* cross-interpreter data */ 3107db96d56Sopenharmony_ci 3117db96d56Sopenharmony_ci// _PyCrossInterpreterData is similar to Py_buffer as an effectively 3127db96d56Sopenharmony_ci// opaque struct that holds data outside the object machinery. This 3137db96d56Sopenharmony_ci// is necessary to pass safely between interpreters in the same process. 3147db96d56Sopenharmony_citypedef struct _xid _PyCrossInterpreterData; 3157db96d56Sopenharmony_ci 3167db96d56Sopenharmony_cistruct _xid { 3177db96d56Sopenharmony_ci // data is the cross-interpreter-safe derivation of a Python object 3187db96d56Sopenharmony_ci // (see _PyObject_GetCrossInterpreterData). It will be NULL if the 3197db96d56Sopenharmony_ci // new_object func (below) encodes the data. 3207db96d56Sopenharmony_ci void *data; 3217db96d56Sopenharmony_ci // obj is the Python object from which the data was derived. This 3227db96d56Sopenharmony_ci // is non-NULL only if the data remains bound to the object in some 3237db96d56Sopenharmony_ci // way, such that the object must be "released" (via a decref) when 3247db96d56Sopenharmony_ci // the data is released. In that case the code that sets the field, 3257db96d56Sopenharmony_ci // likely a registered "crossinterpdatafunc", is responsible for 3267db96d56Sopenharmony_ci // ensuring it owns the reference (i.e. incref). 3277db96d56Sopenharmony_ci PyObject *obj; 3287db96d56Sopenharmony_ci // interp is the ID of the owning interpreter of the original 3297db96d56Sopenharmony_ci // object. It corresponds to the active interpreter when 3307db96d56Sopenharmony_ci // _PyObject_GetCrossInterpreterData() was called. This should only 3317db96d56Sopenharmony_ci // be set by the cross-interpreter machinery. 3327db96d56Sopenharmony_ci // 3337db96d56Sopenharmony_ci // We use the ID rather than the PyInterpreterState to avoid issues 3347db96d56Sopenharmony_ci // with deleted interpreters. Note that IDs are never re-used, so 3357db96d56Sopenharmony_ci // each one will always correspond to a specific interpreter 3367db96d56Sopenharmony_ci // (whether still alive or not). 3377db96d56Sopenharmony_ci int64_t interp; 3387db96d56Sopenharmony_ci // new_object is a function that returns a new object in the current 3397db96d56Sopenharmony_ci // interpreter given the data. The resulting object (a new 3407db96d56Sopenharmony_ci // reference) will be equivalent to the original object. This field 3417db96d56Sopenharmony_ci // is required. 3427db96d56Sopenharmony_ci PyObject *(*new_object)(_PyCrossInterpreterData *); 3437db96d56Sopenharmony_ci // free is called when the data is released. If it is NULL then 3447db96d56Sopenharmony_ci // nothing will be done to free the data. For some types this is 3457db96d56Sopenharmony_ci // okay (e.g. bytes) and for those types this field should be set 3467db96d56Sopenharmony_ci // to NULL. However, for most the data was allocated just for 3477db96d56Sopenharmony_ci // cross-interpreter use, so it must be freed when 3487db96d56Sopenharmony_ci // _PyCrossInterpreterData_Release is called or the memory will 3497db96d56Sopenharmony_ci // leak. In that case, at the very least this field should be set 3507db96d56Sopenharmony_ci // to PyMem_RawFree (the default if not explicitly set to NULL). 3517db96d56Sopenharmony_ci // The call will happen with the original interpreter activated. 3527db96d56Sopenharmony_ci void (*free)(void *); 3537db96d56Sopenharmony_ci}; 3547db96d56Sopenharmony_ci 3557db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyObject_GetCrossInterpreterData(PyObject *, _PyCrossInterpreterData *); 3567db96d56Sopenharmony_ciPyAPI_FUNC(PyObject *) _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *); 3577db96d56Sopenharmony_ciPyAPI_FUNC(void) _PyCrossInterpreterData_Release(_PyCrossInterpreterData *); 3587db96d56Sopenharmony_ci 3597db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyObject_CheckCrossInterpreterData(PyObject *); 3607db96d56Sopenharmony_ci 3617db96d56Sopenharmony_ci/* cross-interpreter data registry */ 3627db96d56Sopenharmony_ci 3637db96d56Sopenharmony_citypedef int (*crossinterpdatafunc)(PyObject *, _PyCrossInterpreterData *); 3647db96d56Sopenharmony_ci 3657db96d56Sopenharmony_ciPyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc); 3667db96d56Sopenharmony_ciPyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *); 367