-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context.h functions (PyContext_New, PyContext*)
Formatting
- Loading branch information
Aviram Hassan
committed
Oct 22, 2020
1 parent
864eeca
commit 0fd500f
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::ffi::object::{PyObject, PyTypeObject, Py_TYPE}; | ||
use std::os::raw::{c_char, c_int}; | ||
|
||
extern "C" { | ||
pub static mut PyContext_Type: PyTypeObject; | ||
pub static mut PyContextVar_Type: PyTypeObject; | ||
pub static mut PyContextToken_Type: PyTypeObject; | ||
pub fn PyContext_New() -> *mut PyObject; | ||
pub fn PyContext_Copy(ctx: *mut PyObject) -> *mut PyObject; | ||
pub fn PyContext_CopyCurrent() -> *mut PyObject; | ||
pub fn PyContext_Enter(ctx: *mut PyObject) -> c_int; | ||
pub fn PyContext_Exit(ctx: *mut PyObject) -> c_int; | ||
pub fn PyContextVar_New(name: *const c_char, def: *mut PyObject) -> *mut PyObject; | ||
pub fn PyContextVar_Get( | ||
var: *mut PyObject, | ||
default_value: *mut PyObject, | ||
value: *mut *mut PyObject, | ||
) -> c_int; | ||
pub fn PyContextVar_Set(var: *mut PyObject, value: *mut PyObject) -> *mut PyObject; | ||
pub fn PyContextVar_Reset(var: *mut PyObject, token: *mut PyObject) -> c_int; | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn PyContext_CheckExact(op: *mut PyObject) -> c_int { | ||
(Py_TYPE(op) == &mut PyContext_Type) as c_int | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn PyContextVar_CheckExact(op: *mut PyObject) -> c_int { | ||
(Py_TYPE(op) == &mut PyContextVar_Type) as c_int | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn PyContextToken_CheckExact(op: *mut PyObject) -> c_int { | ||
(Py_TYPE(op) == &mut PyContextToken_Type) as c_int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters