Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
context.h108 linesDownload Raw Back to cpython
1#ifndef Py_LIMITED_API2#ifndef Py_CONTEXT_H3#define Py_CONTEXT_H4#ifdef __cplusplus5extern "C" {6#endif7 8PyAPI_DATA(PyTypeObject) PyContext_Type;9typedef struct _pycontextobject PyContext;10 11PyAPI_DATA(PyTypeObject) PyContextVar_Type;12typedef struct _pycontextvarobject PyContextVar;13 14PyAPI_DATA(PyTypeObject) PyContextToken_Type;15typedef struct _pycontexttokenobject PyContextToken;16 17 18#define PyContext_CheckExact(o) Py_IS_TYPE((o), &PyContext_Type)19#define PyContextVar_CheckExact(o) Py_IS_TYPE((o), &PyContextVar_Type)20#define PyContextToken_CheckExact(o) Py_IS_TYPE((o), &PyContextToken_Type)21 22 23PyAPI_FUNC(PyObject *) PyContext_New(void);24PyAPI_FUNC(PyObject *) PyContext_Copy(PyObject *);25PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void);26 27PyAPI_FUNC(int) PyContext_Enter(PyObject *);28PyAPI_FUNC(int) PyContext_Exit(PyObject *);29 30typedef enum {31    /*32     * The current context has switched to a different context.  The object33     * passed to the watch callback is the now-current contextvars.Context34     * object, or None if no context is current.35     */36    Py_CONTEXT_SWITCHED = 1,37} PyContextEvent;38 39/*40 * Context object watcher callback function.  The object passed to the callback41 * is event-specific; see PyContextEvent for details.42 *43 * if the callback returns with an exception set, it must return -1. Otherwise44 * it should return 045 */46typedef int (*PyContext_WatchCallback)(PyContextEvent, PyObject *);47 48/*49 * Register a per-interpreter callback that will be invoked for context object50 * enter/exit events.51 *52 * Returns a handle that may be passed to PyContext_ClearWatcher on success,53 * or -1 and sets and error if no more handles are available.54 */55PyAPI_FUNC(int) PyContext_AddWatcher(PyContext_WatchCallback callback);56 57/*58 * Clear the watcher associated with the watcher_id handle.59 *60 * Returns 0 on success or -1 if no watcher exists for the provided id.61 */62PyAPI_FUNC(int) PyContext_ClearWatcher(int watcher_id);63 64/* Create a new context variable.65 66   default_value can be NULL.67*/68PyAPI_FUNC(PyObject *) PyContextVar_New(69    const char *name, PyObject *default_value);70 71 72/* Get a value for the variable.73 74   Returns -1 if an error occurred during lookup.75 76   Returns 0 if value either was or was not found.77 78   If value was found, *value will point to it.79   If not, it will point to:80 81   - default_value, if not NULL;82   - the default value of "var", if not NULL;83   - NULL.84 85   '*value' will be a new ref, if not NULL.86*/87PyAPI_FUNC(int) PyContextVar_Get(88    PyObject *var, PyObject *default_value, PyObject **value);89 90 91/* Set a new value for the variable.92   Returns NULL if an error occurs.93*/94PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);95 96 97/* Reset a variable to its previous value.98   Returns 0 on success, -1 on error.99*/100PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);101 102 103#ifdef __cplusplus104}105#endif106#endif /* !Py_CONTEXT_H */107#endif /* !Py_LIMITED_API */108 
codekingpro/portable-devtools · Team Ai