• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_SLICEOBJECT_H
2 #define Py_SLICEOBJECT_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 /* The unique ellipsis object "..." */
8 
9 PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */
10 
11 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030D0000
12 #  define Py_Ellipsis Py_GetConstantBorrowed(Py_CONSTANT_ELLIPSIS)
13 #else
14 #  define Py_Ellipsis (&_Py_EllipsisObject)
15 #endif
16 
17 /* Slice object interface */
18 
19 /*
20 
21 A slice object containing start, stop, and step data members (the
22 names are from range).  After much talk with Guido, it was decided to
23 let these be any arbitrary python type.  Py_None stands for omitted values.
24 */
25 #ifndef Py_LIMITED_API
26 typedef struct {
27     PyObject_HEAD
28     PyObject *start, *stop, *step;      /* not NULL */
29 } PySliceObject;
30 #endif
31 
32 PyAPI_DATA(PyTypeObject) PySlice_Type;
33 PyAPI_DATA(PyTypeObject) PyEllipsis_Type;
34 
35 #define PySlice_Check(op) Py_IS_TYPE((op), &PySlice_Type)
36 
37 PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
38                                   PyObject* step);
39 #ifndef Py_LIMITED_API
40 PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop);
41 PyAPI_FUNC(int) _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
42                                  PyObject **start_ptr, PyObject **stop_ptr,
43                                  PyObject **step_ptr);
44 #endif
45 PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length,
46                                   Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
47 Py_DEPRECATED(3.7)
48 PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length,
49                                      Py_ssize_t *start, Py_ssize_t *stop,
50                                      Py_ssize_t *step,
51                                      Py_ssize_t *slicelength);
52 
53 #if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100
54 #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) (  \
55     PySlice_Unpack((slice), (start), (stop), (step)) < 0 ?                  \
56     ((*(slicelen) = 0), -1) :                                               \
57     ((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \
58      0))
59 PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice,
60                                Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
61 PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length,
62                                              Py_ssize_t *start, Py_ssize_t *stop,
63                                              Py_ssize_t step);
64 #endif
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 #endif /* !Py_SLICEOBJECT_H */
70