slice.pxd 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. cdef extern from "Python.h":
  2. # PyTypeObject PySlice_Type
  3. #
  4. # The type object for slice objects. This is the same as slice and types.SliceType
  5. bint PySlice_Check(object ob)
  6. #
  7. # Return true if ob is a slice object; ob must not be NULL.
  8. slice PySlice_New(object start, object stop, object step)
  9. #
  10. # Return a new slice object with the given values. The start, stop, and step
  11. # parameters are used as the values of the slice object attributes of the same
  12. # names. Any of the values may be NULL, in which case the None will be used
  13. # for the corresponding attribute. Return NULL if the new object could not be
  14. # allocated.
  15. int PySlice_GetIndices(object slice, Py_ssize_t length,
  16. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) except? -1
  17. #
  18. # Retrieve the start, stop and step indices from the slice object slice,
  19. # assuming a sequence of length length. Treats indices greater than length
  20. # as errors.
  21. #
  22. # Returns 0 on success and -1 on error with no exception set (unless one
  23. # of the indices was not None and failed to be converted to an integer,
  24. # in which case -1 is returned with an exception set).
  25. #
  26. # You probably do not want to use this function.
  27. #
  28. # Changed in version 3.2: The parameter type for the slice parameter was
  29. # PySliceObject* before.
  30. int PySlice_GetIndicesEx(object slice, Py_ssize_t length,
  31. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
  32. Py_ssize_t *slicelength) except -1
  33. #
  34. # Usable replacement for PySlice_GetIndices(). Retrieve the start, stop, and step
  35. # indices from the slice object slice assuming a sequence of length length, and
  36. # store the length of the slice in slicelength. Out of bounds indices are clipped
  37. # in a manner consistent with the handling of normal slices.
  38. #
  39. # Returns 0 on success and -1 on error with exception set.
  40. #
  41. # Changed in version 3.2: The parameter type for the slice parameter was
  42. # PySliceObject* before.
  43. int PySlice_Unpack(object slice, Py_ssize_t *start, Py_ssize_t *stop,
  44. Py_ssize_t *step) except -1
  45. # Extract the start, stop and step data members from a slice object as C
  46. # integers. Silently reduce values larger than PY_SSIZE_T_MAX to
  47. # PY_SSIZE_T_MAX, silently boost the start and stop values less than
  48. # PY_SSIZE_T_MIN to PY_SSIZE_T_MIN, and silently boost the step values
  49. # less than -PY_SSIZE_T_MAX to -PY_SSIZE_T_MAX.
  50. # Return -1 on error, 0 on success.
  51. # New in version 3.6.1.
  52. Py_ssize_t PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t *start,
  53. Py_ssize_t *stop, Py_ssize_t step)
  54. # Adjust start/end slice indices assuming a sequence of the specified
  55. # length. Out of bounds indices are clipped in a manner consistent with
  56. # the handling of normal slices.
  57. # Return the length of the slice. Always successful. Doesn’t call Python
  58. # code.
  59. # New in version 3.6.1.