sliceobject.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. Written by Jim Hugunin and Chris Chase.
  3. This includes both the singular ellipsis object and slice objects.
  4. Guido, feel free to do whatever you want in the way of copyrights
  5. for this file.
  6. */
  7. /*
  8. Py_Ellipsis encodes the '...' rubber index token. It is similar to
  9. the Py_NoneStruct in that there is no way to create other objects of
  10. this type and there is exactly one in existence.
  11. */
  12. #include "Python.h"
  13. #include "pycore_abstract.h" // _PyIndex_Check()
  14. #include "pycore_long.h" // _PyLong_GetZero()
  15. #include "pycore_object.h" // _PyObject_GC_TRACK()
  16. #include "structmember.h" // PyMemberDef
  17. static PyObject *
  18. ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  19. {
  20. if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_GET_SIZE(kwargs))) {
  21. PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments");
  22. return NULL;
  23. }
  24. return Py_NewRef(Py_Ellipsis);
  25. }
  26. static void
  27. ellipsis_dealloc(PyObject *ellipsis)
  28. {
  29. /* This should never get called, but we also don't want to SEGV if
  30. * we accidentally decref Ellipsis out of existence. Instead,
  31. * since Ellipsis is an immortal object, re-set the reference count.
  32. */
  33. _Py_SetImmortal(ellipsis);
  34. }
  35. static PyObject *
  36. ellipsis_repr(PyObject *op)
  37. {
  38. return PyUnicode_FromString("Ellipsis");
  39. }
  40. static PyObject *
  41. ellipsis_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
  42. {
  43. return PyUnicode_FromString("Ellipsis");
  44. }
  45. static PyMethodDef ellipsis_methods[] = {
  46. {"__reduce__", ellipsis_reduce, METH_NOARGS, NULL},
  47. {NULL, NULL}
  48. };
  49. PyTypeObject PyEllipsis_Type = {
  50. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  51. "ellipsis", /* tp_name */
  52. 0, /* tp_basicsize */
  53. 0, /* tp_itemsize */
  54. ellipsis_dealloc, /* tp_dealloc */
  55. 0, /* tp_vectorcall_offset */
  56. 0, /* tp_getattr */
  57. 0, /* tp_setattr */
  58. 0, /* tp_as_async */
  59. ellipsis_repr, /* tp_repr */
  60. 0, /* tp_as_number */
  61. 0, /* tp_as_sequence */
  62. 0, /* tp_as_mapping */
  63. 0, /* tp_hash */
  64. 0, /* tp_call */
  65. 0, /* tp_str */
  66. PyObject_GenericGetAttr, /* tp_getattro */
  67. 0, /* tp_setattro */
  68. 0, /* tp_as_buffer */
  69. Py_TPFLAGS_DEFAULT, /* tp_flags */
  70. 0, /* tp_doc */
  71. 0, /* tp_traverse */
  72. 0, /* tp_clear */
  73. 0, /* tp_richcompare */
  74. 0, /* tp_weaklistoffset */
  75. 0, /* tp_iter */
  76. 0, /* tp_iternext */
  77. ellipsis_methods, /* tp_methods */
  78. 0, /* tp_members */
  79. 0, /* tp_getset */
  80. 0, /* tp_base */
  81. 0, /* tp_dict */
  82. 0, /* tp_descr_get */
  83. 0, /* tp_descr_set */
  84. 0, /* tp_dictoffset */
  85. 0, /* tp_init */
  86. 0, /* tp_alloc */
  87. ellipsis_new, /* tp_new */
  88. };
  89. PyObject _Py_EllipsisObject = {
  90. _PyObject_EXTRA_INIT
  91. { _Py_IMMORTAL_REFCNT },
  92. &PyEllipsis_Type
  93. };
  94. /* Slice object implementation */
  95. void _PySlice_Fini(PyInterpreterState *interp)
  96. {
  97. PySliceObject *obj = interp->slice_cache;
  98. if (obj != NULL) {
  99. interp->slice_cache = NULL;
  100. PyObject_GC_Del(obj);
  101. }
  102. }
  103. /* start, stop, and step are python objects with None indicating no
  104. index is present.
  105. */
  106. static PySliceObject *
  107. _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
  108. {
  109. assert(start != NULL && stop != NULL && step != NULL);
  110. PyInterpreterState *interp = _PyInterpreterState_GET();
  111. PySliceObject *obj;
  112. if (interp->slice_cache != NULL) {
  113. obj = interp->slice_cache;
  114. interp->slice_cache = NULL;
  115. _Py_NewReference((PyObject *)obj);
  116. }
  117. else {
  118. obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
  119. if (obj == NULL) {
  120. goto error;
  121. }
  122. }
  123. obj->start = start;
  124. obj->stop = stop;
  125. obj->step = Py_NewRef(step);
  126. _PyObject_GC_TRACK(obj);
  127. return obj;
  128. error:
  129. Py_DECREF(start);
  130. Py_DECREF(stop);
  131. return NULL;
  132. }
  133. PyObject *
  134. PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
  135. {
  136. if (step == NULL) {
  137. step = Py_None;
  138. }
  139. if (start == NULL) {
  140. start = Py_None;
  141. }
  142. if (stop == NULL) {
  143. stop = Py_None;
  144. }
  145. return (PyObject *)_PyBuildSlice_Consume2(Py_NewRef(start),
  146. Py_NewRef(stop), step);
  147. }
  148. PyObject *
  149. _PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop)
  150. {
  151. assert(start != NULL && stop != NULL);
  152. return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None);
  153. }
  154. PyObject *
  155. _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
  156. {
  157. PyObject *start, *end, *slice;
  158. start = PyLong_FromSsize_t(istart);
  159. if (!start)
  160. return NULL;
  161. end = PyLong_FromSsize_t(istop);
  162. if (!end) {
  163. Py_DECREF(start);
  164. return NULL;
  165. }
  166. slice = PySlice_New(start, end, NULL);
  167. Py_DECREF(start);
  168. Py_DECREF(end);
  169. return slice;
  170. }
  171. int
  172. PySlice_GetIndices(PyObject *_r, Py_ssize_t length,
  173. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
  174. {
  175. PySliceObject *r = (PySliceObject*)_r;
  176. /* XXX support long ints */
  177. if (r->step == Py_None) {
  178. *step = 1;
  179. } else {
  180. if (!PyLong_Check(r->step)) return -1;
  181. *step = PyLong_AsSsize_t(r->step);
  182. }
  183. if (r->start == Py_None) {
  184. *start = *step < 0 ? length-1 : 0;
  185. } else {
  186. if (!PyLong_Check(r->start)) return -1;
  187. *start = PyLong_AsSsize_t(r->start);
  188. if (*start < 0) *start += length;
  189. }
  190. if (r->stop == Py_None) {
  191. *stop = *step < 0 ? -1 : length;
  192. } else {
  193. if (!PyLong_Check(r->stop)) return -1;
  194. *stop = PyLong_AsSsize_t(r->stop);
  195. if (*stop < 0) *stop += length;
  196. }
  197. if (*stop > length) return -1;
  198. if (*start >= length) return -1;
  199. if (*step == 0) return -1;
  200. return 0;
  201. }
  202. int
  203. PySlice_Unpack(PyObject *_r,
  204. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
  205. {
  206. PySliceObject *r = (PySliceObject*)_r;
  207. /* this is harder to get right than you might think */
  208. static_assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX,
  209. "-PY_SSIZE_T_MAX < PY_SSIZE_T_MIN + 1");
  210. if (r->step == Py_None) {
  211. *step = 1;
  212. }
  213. else {
  214. if (!_PyEval_SliceIndex(r->step, step)) return -1;
  215. if (*step == 0) {
  216. PyErr_SetString(PyExc_ValueError,
  217. "slice step cannot be zero");
  218. return -1;
  219. }
  220. /* Here *step might be -PY_SSIZE_T_MAX-1; in this case we replace it
  221. * with -PY_SSIZE_T_MAX. This doesn't affect the semantics, and it
  222. * guards against later undefined behaviour resulting from code that
  223. * does "step = -step" as part of a slice reversal.
  224. */
  225. if (*step < -PY_SSIZE_T_MAX)
  226. *step = -PY_SSIZE_T_MAX;
  227. }
  228. if (r->start == Py_None) {
  229. *start = *step < 0 ? PY_SSIZE_T_MAX : 0;
  230. }
  231. else {
  232. if (!_PyEval_SliceIndex(r->start, start)) return -1;
  233. }
  234. if (r->stop == Py_None) {
  235. *stop = *step < 0 ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX;
  236. }
  237. else {
  238. if (!_PyEval_SliceIndex(r->stop, stop)) return -1;
  239. }
  240. return 0;
  241. }
  242. Py_ssize_t
  243. PySlice_AdjustIndices(Py_ssize_t length,
  244. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t step)
  245. {
  246. /* this is harder to get right than you might think */
  247. assert(step != 0);
  248. assert(step >= -PY_SSIZE_T_MAX);
  249. if (*start < 0) {
  250. *start += length;
  251. if (*start < 0) {
  252. *start = (step < 0) ? -1 : 0;
  253. }
  254. }
  255. else if (*start >= length) {
  256. *start = (step < 0) ? length - 1 : length;
  257. }
  258. if (*stop < 0) {
  259. *stop += length;
  260. if (*stop < 0) {
  261. *stop = (step < 0) ? -1 : 0;
  262. }
  263. }
  264. else if (*stop >= length) {
  265. *stop = (step < 0) ? length - 1 : length;
  266. }
  267. if (step < 0) {
  268. if (*stop < *start) {
  269. return (*start - *stop - 1) / (-step) + 1;
  270. }
  271. }
  272. else {
  273. if (*start < *stop) {
  274. return (*stop - *start - 1) / step + 1;
  275. }
  276. }
  277. return 0;
  278. }
  279. #undef PySlice_GetIndicesEx
  280. int
  281. PySlice_GetIndicesEx(PyObject *_r, Py_ssize_t length,
  282. Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
  283. Py_ssize_t *slicelength)
  284. {
  285. if (PySlice_Unpack(_r, start, stop, step) < 0)
  286. return -1;
  287. *slicelength = PySlice_AdjustIndices(length, start, stop, *step);
  288. return 0;
  289. }
  290. static PyObject *
  291. slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
  292. {
  293. PyObject *start, *stop, *step;
  294. start = stop = step = NULL;
  295. if (!_PyArg_NoKeywords("slice", kw))
  296. return NULL;
  297. if (!PyArg_UnpackTuple(args, "slice", 1, 3, &start, &stop, &step))
  298. return NULL;
  299. /* This swapping of stop and start is to maintain similarity with
  300. range(). */
  301. if (stop == NULL) {
  302. stop = start;
  303. start = NULL;
  304. }
  305. return PySlice_New(start, stop, step);
  306. }
  307. PyDoc_STRVAR(slice_doc,
  308. "slice(stop)\n\
  309. slice(start, stop[, step])\n\
  310. \n\
  311. Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
  312. static void
  313. slice_dealloc(PySliceObject *r)
  314. {
  315. PyInterpreterState *interp = _PyInterpreterState_GET();
  316. _PyObject_GC_UNTRACK(r);
  317. Py_DECREF(r->step);
  318. Py_DECREF(r->start);
  319. Py_DECREF(r->stop);
  320. if (interp->slice_cache == NULL) {
  321. interp->slice_cache = r;
  322. }
  323. else {
  324. PyObject_GC_Del(r);
  325. }
  326. }
  327. static PyObject *
  328. slice_repr(PySliceObject *r)
  329. {
  330. return PyUnicode_FromFormat("slice(%R, %R, %R)", r->start, r->stop, r->step);
  331. }
  332. static PyMemberDef slice_members[] = {
  333. {"start", T_OBJECT, offsetof(PySliceObject, start), READONLY},
  334. {"stop", T_OBJECT, offsetof(PySliceObject, stop), READONLY},
  335. {"step", T_OBJECT, offsetof(PySliceObject, step), READONLY},
  336. {0}
  337. };
  338. /* Helper function to convert a slice argument to a PyLong, and raise TypeError
  339. with a suitable message on failure. */
  340. static PyObject*
  341. evaluate_slice_index(PyObject *v)
  342. {
  343. if (_PyIndex_Check(v)) {
  344. return PyNumber_Index(v);
  345. }
  346. else {
  347. PyErr_SetString(PyExc_TypeError,
  348. "slice indices must be integers or "
  349. "None or have an __index__ method");
  350. return NULL;
  351. }
  352. }
  353. /* Compute slice indices given a slice and length. Return -1 on failure. Used
  354. by slice.indices and rangeobject slicing. Assumes that `len` is a
  355. nonnegative instance of PyLong. */
  356. int
  357. _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
  358. PyObject **start_ptr, PyObject **stop_ptr,
  359. PyObject **step_ptr)
  360. {
  361. PyObject *start=NULL, *stop=NULL, *step=NULL;
  362. PyObject *upper=NULL, *lower=NULL;
  363. int step_is_negative, cmp_result;
  364. /* Convert step to an integer; raise for zero step. */
  365. if (self->step == Py_None) {
  366. step = Py_NewRef(_PyLong_GetOne());
  367. step_is_negative = 0;
  368. }
  369. else {
  370. int step_sign;
  371. step = evaluate_slice_index(self->step);
  372. if (step == NULL)
  373. goto error;
  374. step_sign = _PyLong_Sign(step);
  375. if (step_sign == 0) {
  376. PyErr_SetString(PyExc_ValueError,
  377. "slice step cannot be zero");
  378. goto error;
  379. }
  380. step_is_negative = step_sign < 0;
  381. }
  382. /* Find lower and upper bounds for start and stop. */
  383. if (step_is_negative) {
  384. lower = PyLong_FromLong(-1L);
  385. if (lower == NULL)
  386. goto error;
  387. upper = PyNumber_Add(length, lower);
  388. if (upper == NULL)
  389. goto error;
  390. }
  391. else {
  392. lower = Py_NewRef(_PyLong_GetZero());
  393. upper = Py_NewRef(length);
  394. }
  395. /* Compute start. */
  396. if (self->start == Py_None) {
  397. start = Py_NewRef(step_is_negative ? upper : lower);
  398. }
  399. else {
  400. start = evaluate_slice_index(self->start);
  401. if (start == NULL)
  402. goto error;
  403. if (_PyLong_IsNegative((PyLongObject *)start)) {
  404. /* start += length */
  405. PyObject *tmp = PyNumber_Add(start, length);
  406. Py_SETREF(start, tmp);
  407. if (start == NULL)
  408. goto error;
  409. cmp_result = PyObject_RichCompareBool(start, lower, Py_LT);
  410. if (cmp_result < 0)
  411. goto error;
  412. if (cmp_result) {
  413. Py_SETREF(start, Py_NewRef(lower));
  414. }
  415. }
  416. else {
  417. cmp_result = PyObject_RichCompareBool(start, upper, Py_GT);
  418. if (cmp_result < 0)
  419. goto error;
  420. if (cmp_result) {
  421. Py_SETREF(start, Py_NewRef(upper));
  422. }
  423. }
  424. }
  425. /* Compute stop. */
  426. if (self->stop == Py_None) {
  427. stop = Py_NewRef(step_is_negative ? lower : upper);
  428. }
  429. else {
  430. stop = evaluate_slice_index(self->stop);
  431. if (stop == NULL)
  432. goto error;
  433. if (_PyLong_IsNegative((PyLongObject *)stop)) {
  434. /* stop += length */
  435. PyObject *tmp = PyNumber_Add(stop, length);
  436. Py_SETREF(stop, tmp);
  437. if (stop == NULL)
  438. goto error;
  439. cmp_result = PyObject_RichCompareBool(stop, lower, Py_LT);
  440. if (cmp_result < 0)
  441. goto error;
  442. if (cmp_result) {
  443. Py_SETREF(stop, Py_NewRef(lower));
  444. }
  445. }
  446. else {
  447. cmp_result = PyObject_RichCompareBool(stop, upper, Py_GT);
  448. if (cmp_result < 0)
  449. goto error;
  450. if (cmp_result) {
  451. Py_SETREF(stop, Py_NewRef(upper));
  452. }
  453. }
  454. }
  455. *start_ptr = start;
  456. *stop_ptr = stop;
  457. *step_ptr = step;
  458. Py_DECREF(upper);
  459. Py_DECREF(lower);
  460. return 0;
  461. error:
  462. *start_ptr = *stop_ptr = *step_ptr = NULL;
  463. Py_XDECREF(start);
  464. Py_XDECREF(stop);
  465. Py_XDECREF(step);
  466. Py_XDECREF(upper);
  467. Py_XDECREF(lower);
  468. return -1;
  469. }
  470. /* Implementation of slice.indices. */
  471. static PyObject*
  472. slice_indices(PySliceObject* self, PyObject* len)
  473. {
  474. PyObject *start, *stop, *step;
  475. PyObject *length;
  476. int error;
  477. /* Convert length to an integer if necessary; raise for negative length. */
  478. length = PyNumber_Index(len);
  479. if (length == NULL)
  480. return NULL;
  481. if (_PyLong_IsNegative((PyLongObject *)length)) {
  482. PyErr_SetString(PyExc_ValueError,
  483. "length should not be negative");
  484. Py_DECREF(length);
  485. return NULL;
  486. }
  487. error = _PySlice_GetLongIndices(self, length, &start, &stop, &step);
  488. Py_DECREF(length);
  489. if (error == -1)
  490. return NULL;
  491. else
  492. return Py_BuildValue("(NNN)", start, stop, step);
  493. }
  494. PyDoc_STRVAR(slice_indices_doc,
  495. "S.indices(len) -> (start, stop, stride)\n\
  496. \n\
  497. Assuming a sequence of length len, calculate the start and stop\n\
  498. indices, and the stride length of the extended slice described by\n\
  499. S. Out of bounds indices are clipped in a manner consistent with the\n\
  500. handling of normal slices.");
  501. static PyObject *
  502. slice_reduce(PySliceObject* self, PyObject *Py_UNUSED(ignored))
  503. {
  504. return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step);
  505. }
  506. PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
  507. static PyMethodDef slice_methods[] = {
  508. {"indices", (PyCFunction)slice_indices,
  509. METH_O, slice_indices_doc},
  510. {"__reduce__", (PyCFunction)slice_reduce,
  511. METH_NOARGS, reduce_doc},
  512. {NULL, NULL}
  513. };
  514. static PyObject *
  515. slice_richcompare(PyObject *v, PyObject *w, int op)
  516. {
  517. if (!PySlice_Check(v) || !PySlice_Check(w))
  518. Py_RETURN_NOTIMPLEMENTED;
  519. if (v == w) {
  520. PyObject *res;
  521. /* XXX Do we really need this shortcut?
  522. There's a unit test for it, but is that fair? */
  523. switch (op) {
  524. case Py_EQ:
  525. case Py_LE:
  526. case Py_GE:
  527. res = Py_True;
  528. break;
  529. default:
  530. res = Py_False;
  531. break;
  532. }
  533. return Py_NewRef(res);
  534. }
  535. PyObject *t1 = PyTuple_Pack(3,
  536. ((PySliceObject *)v)->start,
  537. ((PySliceObject *)v)->stop,
  538. ((PySliceObject *)v)->step);
  539. if (t1 == NULL) {
  540. return NULL;
  541. }
  542. PyObject *t2 = PyTuple_Pack(3,
  543. ((PySliceObject *)w)->start,
  544. ((PySliceObject *)w)->stop,
  545. ((PySliceObject *)w)->step);
  546. if (t2 == NULL) {
  547. Py_DECREF(t1);
  548. return NULL;
  549. }
  550. PyObject *res = PyObject_RichCompare(t1, t2, op);
  551. Py_DECREF(t1);
  552. Py_DECREF(t2);
  553. return res;
  554. }
  555. static int
  556. slice_traverse(PySliceObject *v, visitproc visit, void *arg)
  557. {
  558. Py_VISIT(v->start);
  559. Py_VISIT(v->stop);
  560. Py_VISIT(v->step);
  561. return 0;
  562. }
  563. /* code based on tuplehash() of Objects/tupleobject.c */
  564. #if SIZEOF_PY_UHASH_T > 4
  565. #define _PyHASH_XXPRIME_1 ((Py_uhash_t)11400714785074694791ULL)
  566. #define _PyHASH_XXPRIME_2 ((Py_uhash_t)14029467366897019727ULL)
  567. #define _PyHASH_XXPRIME_5 ((Py_uhash_t)2870177450012600261ULL)
  568. #define _PyHASH_XXROTATE(x) ((x << 31) | (x >> 33)) /* Rotate left 31 bits */
  569. #else
  570. #define _PyHASH_XXPRIME_1 ((Py_uhash_t)2654435761UL)
  571. #define _PyHASH_XXPRIME_2 ((Py_uhash_t)2246822519UL)
  572. #define _PyHASH_XXPRIME_5 ((Py_uhash_t)374761393UL)
  573. #define _PyHASH_XXROTATE(x) ((x << 13) | (x >> 19)) /* Rotate left 13 bits */
  574. #endif
  575. static Py_hash_t
  576. slicehash(PySliceObject *v)
  577. {
  578. Py_uhash_t acc = _PyHASH_XXPRIME_5;
  579. #define _PyHASH_SLICE_PART(com) { \
  580. Py_uhash_t lane = PyObject_Hash(v->com); \
  581. if(lane == (Py_uhash_t)-1) { \
  582. return -1; \
  583. } \
  584. acc += lane * _PyHASH_XXPRIME_2; \
  585. acc = _PyHASH_XXROTATE(acc); \
  586. acc *= _PyHASH_XXPRIME_1; \
  587. }
  588. _PyHASH_SLICE_PART(start);
  589. _PyHASH_SLICE_PART(stop);
  590. _PyHASH_SLICE_PART(step);
  591. #undef _PyHASH_SLICE_PART
  592. if(acc == (Py_uhash_t)-1) {
  593. return 1546275796;
  594. }
  595. return acc;
  596. }
  597. PyTypeObject PySlice_Type = {
  598. PyVarObject_HEAD_INIT(&PyType_Type, 0)
  599. "slice", /* Name of this type */
  600. sizeof(PySliceObject), /* Basic object size */
  601. 0, /* Item size for varobject */
  602. (destructor)slice_dealloc, /* tp_dealloc */
  603. 0, /* tp_vectorcall_offset */
  604. 0, /* tp_getattr */
  605. 0, /* tp_setattr */
  606. 0, /* tp_as_async */
  607. (reprfunc)slice_repr, /* tp_repr */
  608. 0, /* tp_as_number */
  609. 0, /* tp_as_sequence */
  610. 0, /* tp_as_mapping */
  611. (hashfunc)slicehash, /* tp_hash */
  612. 0, /* tp_call */
  613. 0, /* tp_str */
  614. PyObject_GenericGetAttr, /* tp_getattro */
  615. 0, /* tp_setattro */
  616. 0, /* tp_as_buffer */
  617. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  618. slice_doc, /* tp_doc */
  619. (traverseproc)slice_traverse, /* tp_traverse */
  620. 0, /* tp_clear */
  621. slice_richcompare, /* tp_richcompare */
  622. 0, /* tp_weaklistoffset */
  623. 0, /* tp_iter */
  624. 0, /* tp_iternext */
  625. slice_methods, /* tp_methods */
  626. slice_members, /* tp_members */
  627. 0, /* tp_getset */
  628. 0, /* tp_base */
  629. 0, /* tp_dict */
  630. 0, /* tp_descr_get */
  631. 0, /* tp_descr_set */
  632. 0, /* tp_dictoffset */
  633. 0, /* tp_init */
  634. 0, /* tp_alloc */
  635. slice_new, /* tp_new */
  636. };