| #ifndef Py_INTERNAL_CROSSINTERP_H |
| #define Py_INTERNAL_CROSSINTERP_H |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
|
|
| #ifndef Py_BUILD_CORE |
| # error "this header requires Py_BUILD_CORE define" |
| #endif |
|
|
| #include "pycore_lock.h" |
| #include "pycore_pyerrors.h" |
|
|
| |
| |
| |
|
|
| PyAPI_DATA(PyObject *) PyExc_InterpreterError; |
| PyAPI_DATA(PyObject *) PyExc_InterpreterNotFoundError; |
|
|
|
|
| |
| |
| |
|
|
| typedef int (*_Py_simple_func)(void *); |
| extern int _Py_CallInInterpreter( |
| PyInterpreterState *interp, |
| _Py_simple_func func, |
| void *arg); |
| extern int _Py_CallInInterpreterAndRawFree( |
| PyInterpreterState *interp, |
| _Py_simple_func func, |
| void *arg); |
|
|
|
|
| |
| |
| |
|
|
| typedef struct _xid _PyCrossInterpreterData; |
| typedef PyObject *(*xid_newobjectfunc)(_PyCrossInterpreterData *); |
| typedef void (*xid_freefunc)(void *); |
|
|
| |
| |
| |
| struct _xid { |
| |
| |
| |
| void *data; |
| |
| |
| |
| |
| |
| |
| PyObject *obj; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int64_t interpid; |
| |
| |
| |
| |
| xid_newobjectfunc new_object; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| xid_freefunc free; |
| }; |
|
|
| PyAPI_FUNC(_PyCrossInterpreterData *) _PyCrossInterpreterData_New(void); |
| PyAPI_FUNC(void) _PyCrossInterpreterData_Free(_PyCrossInterpreterData *data); |
|
|
| #define _PyCrossInterpreterData_DATA(DATA) ((DATA)->data) |
| #define _PyCrossInterpreterData_OBJ(DATA) ((DATA)->obj) |
| #define _PyCrossInterpreterData_INTERPID(DATA) ((DATA)->interpid) |
| |
|
|
|
|
| |
|
|
| PyAPI_FUNC(void) _PyCrossInterpreterData_Init( |
| _PyCrossInterpreterData *data, |
| PyInterpreterState *interp, void *shared, PyObject *obj, |
| xid_newobjectfunc new_object); |
| PyAPI_FUNC(int) _PyCrossInterpreterData_InitWithSize( |
| _PyCrossInterpreterData *, |
| PyInterpreterState *interp, const size_t, PyObject *, |
| xid_newobjectfunc); |
| PyAPI_FUNC(void) _PyCrossInterpreterData_Clear( |
| PyInterpreterState *, _PyCrossInterpreterData *); |
|
|
| |
| |
| |
| #define _PyCrossInterpreterData_SET_FREE(DATA, FUNC) \ |
| do { \ |
| (DATA)->free = (FUNC); \ |
| } while (0) |
| |
| |
| |
| |
| |
| |
| |
| #define _PyCrossInterpreterData_SET_NEW_OBJECT(DATA, FUNC) \ |
| do { \ |
| (DATA)->new_object = (FUNC); \ |
| } while (0) |
|
|
|
|
| |
|
|
| PyAPI_FUNC(int) _PyObject_CheckCrossInterpreterData(PyObject *); |
| PyAPI_FUNC(int) _PyObject_GetCrossInterpreterData(PyObject *, _PyCrossInterpreterData *); |
| PyAPI_FUNC(PyObject *) _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *); |
| PyAPI_FUNC(int) _PyCrossInterpreterData_Release(_PyCrossInterpreterData *); |
| PyAPI_FUNC(int) _PyCrossInterpreterData_ReleaseAndRawFree(_PyCrossInterpreterData *); |
|
|
|
|
| |
|
|
| |
| |
| |
|
|
| typedef int (*crossinterpdatafunc)(PyThreadState *tstate, PyObject *, |
| _PyCrossInterpreterData *); |
|
|
| struct _xidregitem; |
|
|
| struct _xidregitem { |
| struct _xidregitem *prev; |
| struct _xidregitem *next; |
| |
| PyTypeObject *cls; |
| |
| PyObject *weakref; |
| size_t refcount; |
| crossinterpdatafunc getdata; |
| }; |
|
|
| struct _xidregistry { |
| int global; |
| int initialized; |
| PyMutex mutex; |
| struct _xidregitem *head; |
| }; |
|
|
| PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc); |
| PyAPI_FUNC(int) _PyCrossInterpreterData_UnregisterClass(PyTypeObject *); |
| PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *); |
|
|
|
|
| |
| |
| |
|
|
| struct _xi_runtime_state { |
| |
| |
| struct _xidregistry registry; |
| }; |
|
|
| struct _xi_state { |
| |
| |
| struct _xidregistry registry; |
|
|
| |
| PyObject *PyExc_NotShareableError; |
| }; |
|
|
| extern PyStatus _PyXI_Init(PyInterpreterState *interp); |
| extern void _PyXI_Fini(PyInterpreterState *interp); |
|
|
| extern PyStatus _PyXI_InitTypes(PyInterpreterState *interp); |
| extern void _PyXI_FiniTypes(PyInterpreterState *interp); |
|
|
| #define _PyInterpreterState_GetXIState(interp) (&(interp)->xi) |
|
|
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| typedef struct _excinfo { |
| struct _excinfo_type { |
| PyTypeObject *builtin; |
| const char *name; |
| const char *qualname; |
| const char *module; |
| } type; |
| const char *msg; |
| const char *errdisplay; |
| } _PyXI_excinfo; |
|
|
| PyAPI_FUNC(int) _PyXI_InitExcInfo(_PyXI_excinfo *info, PyObject *exc); |
| PyAPI_FUNC(PyObject *) _PyXI_FormatExcInfo(_PyXI_excinfo *info); |
| PyAPI_FUNC(PyObject *) _PyXI_ExcInfoAsObject(_PyXI_excinfo *info); |
| PyAPI_FUNC(void) _PyXI_ClearExcInfo(_PyXI_excinfo *info); |
|
|
|
|
| typedef enum error_code { |
| _PyXI_ERR_NO_ERROR = 0, |
| _PyXI_ERR_UNCAUGHT_EXCEPTION = -1, |
| _PyXI_ERR_OTHER = -2, |
| _PyXI_ERR_NO_MEMORY = -3, |
| _PyXI_ERR_ALREADY_RUNNING = -4, |
| _PyXI_ERR_MAIN_NS_FAILURE = -5, |
| _PyXI_ERR_APPLY_NS_FAILURE = -6, |
| _PyXI_ERR_NOT_SHAREABLE = -7, |
| } _PyXI_errcode; |
|
|
|
|
| typedef struct _sharedexception { |
| |
| PyInterpreterState *interp; |
| |
| _PyXI_errcode code; |
| |
| |
| |
| _PyXI_excinfo uncaught; |
| } _PyXI_error; |
|
|
| PyAPI_FUNC(PyObject *) _PyXI_ApplyError(_PyXI_error *err); |
|
|
|
|
| typedef struct xi_session _PyXI_session; |
| typedef struct _sharedns _PyXI_namespace; |
|
|
| PyAPI_FUNC(void) _PyXI_FreeNamespace(_PyXI_namespace *ns); |
| PyAPI_FUNC(_PyXI_namespace *) _PyXI_NamespaceFromNames(PyObject *names); |
| PyAPI_FUNC(int) _PyXI_FillNamespaceFromDict( |
| _PyXI_namespace *ns, |
| PyObject *nsobj, |
| _PyXI_session *session); |
| PyAPI_FUNC(int) _PyXI_ApplyNamespace( |
| _PyXI_namespace *ns, |
| PyObject *nsobj, |
| PyObject *dflt); |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| struct xi_session { |
| |
| |
| |
| |
| PyThreadState *prev_tstate; |
| |
| |
| PyThreadState *init_tstate; |
| |
| int own_init_tstate; |
|
|
| |
| |
| |
| |
| |
| int running; |
| |
| |
| |
| PyObject *main_ns; |
|
|
| |
| |
| _PyXI_errcode *error_override; |
| |
| _PyXI_error *error; |
|
|
| |
| _PyXI_error _error; |
| _PyXI_errcode _error_override; |
| }; |
|
|
| PyAPI_FUNC(int) _PyXI_Enter( |
| _PyXI_session *session, |
| PyInterpreterState *interp, |
| PyObject *nsupdates); |
| PyAPI_FUNC(void) _PyXI_Exit(_PyXI_session *session); |
|
|
| PyAPI_FUNC(PyObject *) _PyXI_ApplyCapturedException(_PyXI_session *session); |
| PyAPI_FUNC(int) _PyXI_HasCapturedException(_PyXI_session *session); |
|
|
|
|
| |
| |
| |
|
|
| |
| PyAPI_FUNC(PyInterpreterState *) _PyXI_NewInterpreter( |
| PyInterpreterConfig *config, |
| long *maybe_whence, |
| PyThreadState **p_tstate, |
| PyThreadState **p_save_tstate); |
| PyAPI_FUNC(void) _PyXI_EndInterpreter( |
| PyInterpreterState *interp, |
| PyThreadState *tstate, |
| PyThreadState **p_save_tstate); |
|
|
|
|
| #ifdef __cplusplus |
| } |
| #endif |
| #endif |
|
|