python27_sys/
classobject.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use libc::c_int;

use crate::object::*;
use crate::pyport::Py_ssize_t;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyClassObject {
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_next: *mut PyObject,
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_prev: *mut PyObject,
    pub ob_refcnt: Py_ssize_t,
    pub ob_type: *mut PyTypeObject,
    pub cl_bases: *mut PyObject,
    pub cl_dict: *mut PyObject,
    pub cl_name: *mut PyObject,
    pub cl_getattr: *mut PyObject,
    pub cl_setattr: *mut PyObject,
    pub cl_delattr: *mut PyObject,
    pub cl_weakreflist: *mut PyObject,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyInstanceObject {
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_next: *mut PyObject,
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_prev: *mut PyObject,
    pub ob_refcnt: Py_ssize_t,
    pub ob_type: *mut PyTypeObject,
    pub in_class: *mut PyClassObject,
    pub in_dict: *mut PyObject,
    pub in_weakreflist: *mut PyObject,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyMethodObject {
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_next: *mut PyObject,
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_prev: *mut PyObject,
    pub ob_refcnt: Py_ssize_t,
    pub ob_type: *mut PyTypeObject,
    pub im_func: *mut PyObject,
    pub im_self: *mut PyObject,
    pub im_class: *mut PyObject,
    pub im_weakreflist: *mut PyObject,
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub static mut PyClass_Type: PyTypeObject;
    pub static mut PyInstance_Type: PyTypeObject;
    pub static mut PyMethod_Type: PyTypeObject;
}

#[inline(always)]
pub unsafe fn PyClass_Check(op: *mut PyObject) -> c_int {
    let u: *mut PyTypeObject = &mut PyClass_Type;
    (Py_TYPE(op) == u) as c_int
}

#[inline(always)]
pub unsafe fn PyInstance_Check(op: *mut PyObject) -> c_int {
    let u: *mut PyTypeObject = &mut PyInstance_Type;
    (Py_TYPE(op) == u) as c_int
}

#[inline(always)]
pub unsafe fn PyMethod_Check(op: *mut PyObject) -> c_int {
    let u: *mut PyTypeObject = &mut PyMethod_Type;
    (Py_TYPE(op) == u) as c_int
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub fn PyClass_New(
        arg1: *mut PyObject,
        arg2: *mut PyObject,
        arg3: *mut PyObject,
    ) -> *mut PyObject;
    pub fn PyInstance_New(
        arg1: *mut PyObject,
        arg2: *mut PyObject,
        arg3: *mut PyObject,
    ) -> *mut PyObject;
    pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
    pub fn PyMethod_New(
        arg1: *mut PyObject,
        arg2: *mut PyObject,
        arg3: *mut PyObject,
    ) -> *mut PyObject;
    pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject;
    pub fn PyMethod_Self(arg1: *mut PyObject) -> *mut PyObject;
    pub fn PyMethod_Class(arg1: *mut PyObject) -> *mut PyObject;
    fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) -> *mut PyObject;
    pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
    pub fn PyMethod_ClearFreeList() -> c_int;
}

#[inline(always)]
pub unsafe fn PyMethod_GET_FUNCTION(meth: *mut PyObject) -> *mut PyObject {
    (*(meth as *mut PyMethodObject)).im_func
}

#[inline(always)]
pub unsafe fn PyMethod_GET_SELF(meth: *mut PyObject) -> *mut PyObject {
    (*(meth as *mut PyMethodObject)).im_self
}

#[inline(always)]
pub unsafe fn PyMethod_GET_CLASS(meth: *mut PyObject) -> *mut PyObject {
    (*(meth as *mut PyMethodObject)).im_class
}