ffi: cleanup structseq

This commit is contained in:
Dean Li 2021-09-21 14:22:55 +08:00
parent f771d1684e
commit 040e751f59
No known key found for this signature in database
GPG Key ID: 4F55BB69D480672A
1 changed files with 40 additions and 0 deletions

View File

@ -1,4 +1,5 @@
use crate::ffi::object::{PyObject, PyTypeObject};
#[cfg(not(PyPy))]
use crate::ffi::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
@ -18,9 +19,48 @@ pub struct PyStructSequence_Desc {
pub n_in_sequence: c_int,
}
// skipped PyStructSequence_UnnamedField;
extern "C" {
#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(PyPy, link_name = "PyPyStructSequence_InitType")]
pub fn PyStructSequence_InitType(_type: *mut PyTypeObject, desc: *mut PyStructSequence_Desc);
#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(PyPy, link_name = "PyPyStructSequence_InitType2")]
pub fn PyStructSequence_InitType2(
_type: *mut PyTypeObject,
desc: *mut PyStructSequence_Desc,
) -> c_int;
#[cfg(not(PyPy))]
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject;
#[cfg_attr(PyPy, link_name = "PyPyStructSequence_New")]
pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject;
}
#[cfg(not(Py_LIMITED_API))]
pub type PyStructSequence = crate::ffi::PyTupleObject;
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
#[inline]
pub unsafe fn PyStructSequence_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
crate::ffi::PyTuple_SET_ITEM(op, i, v)
}
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
#[inline]
pub unsafe fn PyStructSequence_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
crate::ffi::PyTuple_GET_ITEM(op, i)
}
extern "C" {
#[cfg(not(PyPy))]
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
pub fn PyStructSequence_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject);
#[cfg(not(PyPy))]
#[cfg_attr(docsrs, doc(cfg(not(PyPy))))]
pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
}