Merge pull request #1861 from deantvv/ffi-setobject-cleanup

ffi: cleanup setobject
This commit is contained in:
David Hewitt 2021-09-05 14:45:57 +01:00 committed by GitHub
commit fc0d08c020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 82 additions and 56 deletions

View File

@ -1,30 +1,12 @@
use crate::ffi::object::*; use crate::ffi::object::*;
use crate::ffi::pyport::{Py_hash_t, Py_ssize_t}; #[cfg(not(Py_LIMITED_API))]
use crate::ffi::pyport::Py_hash_t;
use crate::ffi::pyport::Py_ssize_t;
use std::os::raw::c_int; 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; pub const PySet_MINSIZE: usize = 8;
#[cfg(not(Py_LIMITED_API))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct setentry { pub struct setentry {
@ -32,6 +14,7 @@ pub struct setentry {
pub hash: Py_hash_t, pub hash: Py_hash_t,
} }
#[cfg(not(Py_LIMITED_API))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PySetObject { pub struct PySetObject {
@ -46,12 +29,81 @@ pub struct PySetObject {
pub weakreflist: *mut PyObject, pub weakreflist: *mut PyObject,
} }
// skipped PySet_GET_SIZE
// skipped _PySet_Dummy
extern "C" {
#[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;
// skipped non-limited _PySet_Update
}
#[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;
}
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_Add")]
pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int;
#[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_Pop")]
pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPySet_Size")]
pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t;
#[cfg(PyPy)]
#[link_name = "PyPyFrozenSet_CheckExact"]
pub fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int;
}
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int { pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int
} }
extern "C" {
#[cfg(PyPy)]
#[link_name = "PyPyFrozenSet_Check"]
pub fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int;
}
#[inline]
#[cfg(not(PyPy))]
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(PyPy)]
#[link_name = "PyPyAnySet_CheckExact"]
pub fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int;
}
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int {
@ -65,42 +117,16 @@ pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int {
|| PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int
} }
// skipped PySet_CheckExact
extern "C" {
#[cfg(PyPy)]
#[link_name = "PyPySet_Check"]
pub fn PySet_Check(ob: *mut PyObject) -> c_int;
}
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int { 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 (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;
}