1use crate::object::*;
2use crate::pyport::Py_ssize_t;
3use std::os::raw::c_int;
4use std::ptr::addr_of_mut;
5
6#[cfg_attr(windows, link(name = "pythonXY"))]
7extern "C" {
8 #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")]
9 static mut _Py_EllipsisObject: PyObject;
10}
11
12#[inline]
13pub unsafe fn Py_Ellipsis() -> *mut PyObject {
14 addr_of_mut!(_Py_EllipsisObject)
15}
16
17#[cfg(not(Py_LIMITED_API))]
18#[repr(C)]
19pub struct PySliceObject {
20 pub ob_base: PyObject,
21 pub start: *mut PyObject,
22 pub stop: *mut PyObject,
23 pub step: *mut PyObject,
24}
25
26#[cfg_attr(windows, link(name = "pythonXY"))]
27extern "C" {
28 #[cfg_attr(PyPy, link_name = "PyPySlice_Type")]
29 pub static mut PySlice_Type: PyTypeObject;
30 pub static mut PyEllipsis_Type: PyTypeObject;
31}
32
33#[inline]
34pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int {
35 (Py_TYPE(ob:op) == addr_of_mut!(PySlice_Type)) as c_int
36}
37
38extern "C" {
39 #[cfg_attr(PyPy, link_name = "PyPySlice_New")]
40 pub fn PySlice_New(
41 start: *mut PyObject,
42 stop: *mut PyObject,
43 step: *mut PyObject,
44 ) -> *mut PyObject;
45
46 // skipped non-limited _PySlice_FromIndices
47 // skipped non-limited _PySlice_GetLongIndices
48
49 #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")]
50 pub fn PySlice_GetIndices(
51 r: *mut PyObject,
52 length: Py_ssize_t,
53 start: *mut Py_ssize_t,
54 stop: *mut Py_ssize_t,
55 step: *mut Py_ssize_t,
56 ) -> c_int;
57}
58
59#[inline]
60pub unsafe fn PySlice_GetIndicesEx(
61 slice: *mut PyObject,
62 length: Py_ssize_t,
63 start: *mut Py_ssize_t,
64 stop: *mut Py_ssize_t,
65 step: *mut Py_ssize_t,
66 slicelength: *mut Py_ssize_t,
67) -> c_int {
68 if PySlice_Unpack(slice, start, stop, step) < 0 {
69 *slicelength = 0;
70 -1
71 } else {
72 *slicelength = PySlice_AdjustIndices(length, start, stop, *step);
73 0
74 }
75}
76
77extern "C" {
78 #[cfg_attr(PyPy, link_name = "PyPySlice_Unpack")]
79 pub fn PySlice_Unpack(
80 slice: *mut PyObject,
81 start: *mut Py_ssize_t,
82 stop: *mut Py_ssize_t,
83 step: *mut Py_ssize_t,
84 ) -> c_int;
85
86 #[cfg_attr(all(PyPy, Py_3_10), link_name = "PyPySlice_AdjustIndices")]
87 pub fn PySlice_AdjustIndices(
88 length: Py_ssize_t,
89 start: *mut Py_ssize_t,
90 stop: *mut Py_ssize_t,
91 step: Py_ssize_t,
92 ) -> Py_ssize_t;
93}
94