Skip to main content

pyo3_ffi/
context.rs

1use crate::object::{PyObject, PyTypeObject, Py_TYPE};
2use std::ffi::{c_char, c_int};
3
4extern_libpython! {
5    pub static mut PyContext_Type: PyTypeObject;
6    // skipped non-limited opaque PyContext
7    pub static mut PyContextVar_Type: PyTypeObject;
8    // skipped non-limited opaque PyContextVar
9    pub static mut PyContextToken_Type: PyTypeObject;
10    // skipped non-limited opaque PyContextToken
11}
12
13#[inline]
14pub unsafe fn PyContext_CheckExact(op: *mut PyObject) -> c_int {
15    (Py_TYPE(op) == &raw mut PyContext_Type) as c_int
16}
17
18#[inline]
19pub unsafe fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int {
20    (Py_TYPE(op) == &raw mut PyContextVar_Type) as c_int
21}
22
23#[inline]
24pub unsafe fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int {
25    (Py_TYPE(op) == &raw mut PyContextToken_Type) as c_int
26}
27
28extern_libpython! {
29    pub fn PyContext_New() -> *mut PyObject;
30    pub fn PyContext_Copy(ctx: *mut PyObject) -> *mut PyObject;
31    pub fn PyContext_CopyCurrent() -> *mut PyObject;
32
33    pub fn PyContext_Enter(ctx: *mut PyObject) -> c_int;
34    pub fn PyContext_Exit(ctx: *mut PyObject) -> c_int;
35
36    pub fn PyContextVar_New(name: *const c_char, def: *mut PyObject) -> *mut PyObject;
37    pub fn PyContextVar_Get(
38        var: *mut PyObject,
39        default_value: *mut PyObject,
40        value: *mut *mut PyObject,
41    ) -> c_int;
42    pub fn PyContextVar_Set(var: *mut PyObject, value: *mut PyObject) -> *mut PyObject;
43    pub fn PyContextVar_Reset(var: *mut PyObject, token: *mut PyObject) -> c_int;
44    // skipped non-limited _PyContext_NewHamtForTests
45}