pep-567: Add C API section. (#508)

This commit is contained in:
Yury Selivanov 2017-12-12 23:16:51 -05:00 committed by GitHub
parent 40eb4e992a
commit 29ab20e269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 3 deletions

View File

@ -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