python27_sys/
setobject.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
use libc::c_int;

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

ignore! {
    #[repr(C)] pub struct PySetObject { _private: [u8; 0] }
}

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

#[inline]
pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
    let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
    (Py_TYPE(ob) == f) as c_int
}

#[inline]
pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int {
    let s: *mut PyTypeObject = &mut PySet_Type;
    let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
    (Py_TYPE(ob) == s || Py_TYPE(ob) == f) as c_int
}

#[inline]
pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int {
    (PyAnySet_CheckExact(ob) != 0
        || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0
        || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int
}

#[inline]
pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int {
    let s: *mut PyTypeObject = &mut PySet_Type;
    (Py_TYPE(ob) == s || PyType_IsSubtype(Py_TYPE(ob), s) != 0) as c_int
}

#[inline]
pub unsafe fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int {
    let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
    (Py_TYPE(ob) == f || PyType_IsSubtype(Py_TYPE(ob), f) != 0) as c_int
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject;
    pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject;
    pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t;
    pub fn PySet_Clear(set: *mut PyObject) -> c_int;
    pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int;
    pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int;
    pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int;

    ignore! {
        pub fn _PySet_Next(set: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject) -> c_int;
        pub fn _PySet_NextEntry(
            set: *mut PyObject,
            pos: *mut Py_ssize_t,
            key: *mut *mut PyObject,
            hash: *mut c_long,
        ) -> c_int;
    }

    pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject;

    ignore! {
        pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) -> c_int;
    }
}