# setobject.rs - source
Source of the Rust file `/home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.13.2/src/ffi/setobject.rs`.
Keywords: rust, rustlang, rust-lang

      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

    use crate::ffi::object::*;
    use crate::ffi::pyport::{Py_hash_t, Py_ssize_t};
    use std::os::raw::c_int;

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

        #[cfg(PyPy)]
        #[link_name = "PyPyFrozenSet_CheckExact"]
        pub fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int;

        #[cfg(PyPy)]
        #[link_name = "PyPyAnySet_CheckExact"]
        pub fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int;

        #[cfg(PyPy)]
        #[link_name = "PyPySet_Check"]
        pub fn PySet_Check(ob: *mut PyObject) -> c_int;
    }

    pub const PySet_MINSIZE: usize = 8;

    #[repr(C)]
    #[derive(Debug)]
    pub struct setentry {
        pub key: *mut PyObject,
        pub hash: Py_hash_t,
    }

    #[repr(C)]
    #[derive(Debug)]
    pub struct PySetObject {
        pub ob_base: PyObject,
        pub fill: Py_ssize_t,
        pub used: Py_ssize_t,
        pub mask: Py_ssize_t,
        pub table: *mut setentry,
        pub hash: Py_hash_t,
        pub finger: Py_ssize_t,
        pub smalltable: [setentry; PySet_MINSIZE],
        pub weakreflist: *mut PyObject,
    }

    #[inline]
    #[cfg(not(PyPy))]
    pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
        (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int
    }

    #[inline]
    #[cfg(not(PyPy))]
    pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int {
        (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) 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]
    #[cfg(not(PyPy))]
    pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int {
        (Py_TYPE(ob) == &mut PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0) as c_int
    }

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

    extern "C" {
        #[cfg_attr(PyPy, link_name = "PyPySet_New")]
        pub fn PySet_New(arg1: *mut PyObject) -> *mut PyObject;
        #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")]
        pub fn PyFrozenSet_New(arg1: *mut PyObject) -> *mut PyObject;
        #[cfg_attr(PyPy, link_name = "PyPySet_Size")]
        pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t;
        #[cfg_attr(PyPy, link_name = "PyPySet_Clear")]
        pub fn PySet_Clear(set: *mut PyObject) -> c_int;
        #[cfg_attr(PyPy, link_name = "PyPySet_Contains")]
        pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int;
        #[cfg_attr(PyPy, link_name = "PyPySet_Discard")]
        pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int;
        #[cfg_attr(PyPy, link_name = "PyPySet_Add")]
        pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int;
        #[cfg_attr(PyPy, link_name = "PyPySet_Pop")]
        pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject;

        #[cfg(not(Py_LIMITED_API))]
        #[cfg_attr(PyPy, link_name = "_PyPySet_NextEntry")]
        pub fn _PySet_NextEntry(
            set: *mut PyObject,
            pos: *mut Py_ssize_t,
            key: *mut *mut PyObject,
            hash: *mut super::Py_hash_t,
        ) -> c_int;
    }