Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _slice-objects: |
| 4 | |
| 5 | Slice Objects |
| 6 | ------------- |
| 7 | |
| 8 | |
| 9 | .. cvar:: PyTypeObject PySlice_Type |
| 10 | |
Georg Brandl | ab32fec | 2010-11-26 08:49:15 +0000 | [diff] [blame] | 11 | The type object for slice objects. This is the same as :class:`slice` in the |
| 12 | Python layer. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 13 | |
| 14 | |
| 15 | .. cfunction:: int PySlice_Check(PyObject *ob) |
| 16 | |
| 17 | Return true if *ob* is a slice object; *ob* must not be *NULL*. |
| 18 | |
| 19 | |
| 20 | .. cfunction:: PyObject* PySlice_New(PyObject *start, PyObject *stop, PyObject *step) |
| 21 | |
| 22 | Return a new slice object with the given values. The *start*, *stop*, and |
Jeroen Ruigrok van der Werven | bd87552 | 2009-04-26 21:06:15 +0000 | [diff] [blame] | 23 | *step* parameters are used as the values of the slice object attributes of |
| 24 | the same names. Any of the values may be *NULL*, in which case the |
| 25 | ``None`` will be used for the corresponding attribute. Return *NULL* if |
| 26 | the new object could not be allocated. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | .. cfunction:: int PySlice_GetIndices(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) |
| 30 | |
| 31 | Retrieve the start, stop and step indices from the slice object *slice*, |
Jeroen Ruigrok van der Werven | bd87552 | 2009-04-26 21:06:15 +0000 | [diff] [blame] | 32 | assuming a sequence of length *length*. Treats indices greater than |
| 33 | *length* as errors. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 34 | |
Jeroen Ruigrok van der Werven | bd87552 | 2009-04-26 21:06:15 +0000 | [diff] [blame] | 35 | Returns 0 on success and -1 on error with no exception set (unless one of |
| 36 | the indices was not :const:`None` and failed to be converted to an integer, |
| 37 | in which case -1 is returned with an exception set). |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 38 | |
Georg Brandl | e6bcc91 | 2008-05-12 18:05:20 +0000 | [diff] [blame] | 39 | You probably do not want to use this function. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | .. cfunction:: int PySlice_GetIndicesEx(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength) |
| 43 | |
Jeroen Ruigrok van der Werven | bd87552 | 2009-04-26 21:06:15 +0000 | [diff] [blame] | 44 | Usable replacement for :cfunc:`PySlice_GetIndices`. Retrieve the start, |
| 45 | stop, and step indices from the slice object *slice* assuming a sequence of |
| 46 | length *length*, and store the length of the slice in *slicelength*. Out |
| 47 | of bounds indices are clipped in a manner consistent with the handling of |
| 48 | normal slices. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 49 | |
| 50 | Returns 0 on success and -1 on error with exception set. |
Jeroen Ruigrok van der Werven | bd87552 | 2009-04-26 21:06:15 +0000 | [diff] [blame] | 51 | |