Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 1 | #ifndef Py_SLICEOBJECT_H |
| 2 | #define Py_SLICEOBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 7 | /* The unique ellipsis object "..." */ |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 8 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 9 | PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */ |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 11 | #define Py_Ellipsis (&_Py_EllipsisObject) |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 12 | |
| 13 | /* Slice object interface */ |
| 14 | |
| 15 | /* |
| 16 | |
| 17 | A slice object containing start, stop, and step data members (the |
| 18 | names are from range). After much talk with Guido, it was decided to |
Armin Rigo | 89a3946 | 2004-10-28 16:32:00 +0000 | [diff] [blame] | 19 | let these be any arbitrary python type. Py_None stands for omitted values. |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 20 | */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 21 | #ifndef Py_LIMITED_API |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 22 | typedef struct { |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 23 | PyObject_HEAD |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 24 | PyObject *start, *stop, *step; /* not NULL */ |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 25 | } PySliceObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 26 | #endif |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 27 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 28 | PyAPI_DATA(PyTypeObject) PySlice_Type; |
Benjamin Peterson | fd838e6 | 2009-04-20 02:09:13 +0000 | [diff] [blame] | 29 | PyAPI_DATA(PyTypeObject) PyEllipsis_Type; |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 30 | |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 31 | #define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type) |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 32 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 33 | PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop, |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 34 | PyObject* step); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 35 | #ifndef Py_LIMITED_API |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop); |
Mark Dickinson | ffdb2c2 | 2012-11-17 19:18:10 +0000 | [diff] [blame] | 37 | PyAPI_FUNC(int) _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, |
| 38 | PyObject **start_ptr, PyObject **stop_ptr, |
| 39 | PyObject **step_ptr); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 40 | #endif |
| 41 | PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length, |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 42 | Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 43 | Py_DEPRECATED(3.7) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 44 | PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length, |
Serhiy Storchaka | b2a5be0 | 2017-01-25 13:23:05 +0200 | [diff] [blame] | 45 | Py_ssize_t *start, Py_ssize_t *stop, |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 46 | Py_ssize_t *step, |
| 47 | Py_ssize_t *slicelength); |
Serhiy Storchaka | b2a5be0 | 2017-01-25 13:23:05 +0200 | [diff] [blame] | 48 | |
| 49 | #if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100 |
| 50 | #define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \ |
Serhiy Storchaka | c761136 | 2017-02-04 11:04:00 +0200 | [diff] [blame] | 51 | PySlice_Unpack((slice), (start), (stop), (step)) < 0 ? \ |
| 52 | ((*(slicelen) = 0), -1) : \ |
| 53 | ((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \ |
Serhiy Storchaka | b2a5be0 | 2017-01-25 13:23:05 +0200 | [diff] [blame] | 54 | 0)) |
| 55 | PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice, |
| 56 | Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); |
| 57 | PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length, |
| 58 | Py_ssize_t *start, Py_ssize_t *stop, |
| 59 | Py_ssize_t step); |
| 60 | #endif |
Guido van Rossum | e15d0de | 1996-07-30 16:42:30 +0000 | [diff] [blame] | 61 | |
| 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | #endif /* !Py_SLICEOBJECT_H */ |