diff --git a/pep-0567.rst b/pep-0567.rst index ebe514c59..c3fb17f5e 100644 --- a/pep-0567.rst +++ b/pep-0567.rst @@ -263,10 +263,37 @@ as follows:: ... -CPython C API -------------- +C API +----- -TBD +1. ``PyContextVar * PyContextVar_New(char *name)``: create a + ``ContextVar`` object. + +2. ``PyObject * PyContextVar_Get(PyContextVar *)``: + return the value of the variable in the current context. + +3. ``PyContextToken * PyContextVar_Set(PyContextVar *, PyObject *)``: + set the value of the variable in the current context. + +4. ``PyContextVar_Reset(PyContextToken *)``: + reset the value of the context variable. + +5. ``PyContext * PyContext_New()``: create a new empty context. + +6. ``PyContext * PyContext_Get()``: get the current context. + +7. ``int PyContext_Set(PyContext *)``: set a new context as the + current for the current OS thread. It is required to always + restore the previous context:: + + PyContext *old_ctx = PyContext_Get(); + if (old_ctx == NULL) goto error; + + if (PyContext_Set(new_ctx)) goto error; + + // run some code + + if (PyContext_Set(old_ctx)) goto error; Implementation