Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | Written by Jim Hugunin and Chris Chase. |
| 3 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 4 | This includes both the singular ellipsis object and slice objects. |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 5 | |
| 6 | Guido, feel free to do whatever you want in the way of copyrights |
| 7 | for this file. |
| 8 | */ |
| 9 | |
| 10 | /* |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 11 | Py_Ellipsis encodes the '...' rubber index token. It is similar to |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 12 | the Py_NoneStruct in that there is no way to create other objects of |
| 13 | this type and there is exactly one in existence. |
| 14 | */ |
| 15 | |
| 16 | #include "Python.h" |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 17 | #include "structmember.h" |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
Fred Drake | 45cfbcc | 2000-07-09 06:21:27 +0000 | [diff] [blame] | 20 | ellipsis_repr(PyObject *op) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 21 | { |
Walter Dörwald | 1ab8330 | 2007-05-18 17:15:44 +0000 | [diff] [blame] | 22 | return PyUnicode_FromString("Ellipsis"); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 25 | static PyTypeObject PyEllipsis_Type = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 26 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 27 | "ellipsis", /* tp_name */ |
| 28 | 0, /* tp_basicsize */ |
| 29 | 0, /* tp_itemsize */ |
| 30 | 0, /*never called*/ /* tp_dealloc */ |
| 31 | 0, /* tp_print */ |
| 32 | 0, /* tp_getattr */ |
| 33 | 0, /* tp_setattr */ |
| 34 | 0, /* tp_compare */ |
| 35 | ellipsis_repr, /* tp_repr */ |
| 36 | 0, /* tp_as_number */ |
| 37 | 0, /* tp_as_sequence */ |
| 38 | 0, /* tp_as_mapping */ |
| 39 | 0, /* tp_hash */ |
| 40 | 0, /* tp_call */ |
| 41 | 0, /* tp_str */ |
| 42 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 43 | 0, /* tp_setattro */ |
| 44 | 0, /* tp_as_buffer */ |
| 45 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 48 | PyObject _Py_EllipsisObject = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 49 | _PyObject_EXTRA_INIT |
| 50 | 1, &PyEllipsis_Type |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | |
| 54 | /* Slice object implementation |
| 55 | |
| 56 | start, stop, and step are python objects with None indicating no |
| 57 | index is present. |
| 58 | */ |
| 59 | |
| 60 | PyObject * |
Fred Drake | 45cfbcc | 2000-07-09 06:21:27 +0000 | [diff] [blame] | 61 | PySlice_New(PyObject *start, PyObject *stop, PyObject *step) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 62 | { |
Neil Schemenauer | 7465ad2 | 2002-04-12 03:05:37 +0000 | [diff] [blame] | 63 | PySliceObject *obj = PyObject_New(PySliceObject, &PySlice_Type); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 64 | |
Guido van Rossum | adf5410 | 2000-12-14 15:09:46 +0000 | [diff] [blame] | 65 | if (obj == NULL) |
| 66 | return NULL; |
| 67 | |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 68 | if (step == NULL) step = Py_None; |
| 69 | Py_INCREF(step); |
| 70 | if (start == NULL) start = Py_None; |
| 71 | Py_INCREF(start); |
| 72 | if (stop == NULL) stop = Py_None; |
| 73 | Py_INCREF(stop); |
| 74 | |
| 75 | obj->step = step; |
| 76 | obj->start = start; |
| 77 | obj->stop = stop; |
| 78 | |
| 79 | return (PyObject *) obj; |
| 80 | } |
| 81 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 82 | PyObject * |
| 83 | _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop) |
| 84 | { |
| 85 | PyObject *start, *end, *slice; |
| 86 | start = PyInt_FromSsize_t(istart); |
| 87 | if (!start) |
| 88 | return NULL; |
| 89 | end = PyInt_FromSsize_t(istop); |
| 90 | if (!end) { |
| 91 | Py_DECREF(start); |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | slice = PySlice_New(start, end, NULL); |
| 96 | Py_DECREF(start); |
| 97 | Py_DECREF(end); |
| 98 | return slice; |
| 99 | } |
| 100 | |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 101 | int |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 102 | PySlice_GetIndices(PySliceObject *r, Py_ssize_t length, |
| 103 | Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 104 | { |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 105 | /* XXX support long ints */ |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 106 | if (r->step == Py_None) { |
| 107 | *step = 1; |
| 108 | } else { |
Neal Norwitz | 1fe5f38 | 2007-08-31 04:32:55 +0000 | [diff] [blame^] | 109 | if (!PyLong_Check(r->step)) return -1; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 110 | *step = PyInt_AsSsize_t(r->step); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 111 | } |
| 112 | if (r->start == Py_None) { |
| 113 | *start = *step < 0 ? length-1 : 0; |
| 114 | } else { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 115 | if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1; |
| 116 | *start = PyInt_AsSsize_t(r->start); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 117 | if (*start < 0) *start += length; |
| 118 | } |
| 119 | if (r->stop == Py_None) { |
| 120 | *stop = *step < 0 ? -1 : length; |
| 121 | } else { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 122 | if (!PyInt_Check(r->stop) && !PyLong_Check(r->step)) return -1; |
| 123 | *stop = PyInt_AsSsize_t(r->stop); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 124 | if (*stop < 0) *stop += length; |
| 125 | } |
| 126 | if (*stop > length) return -1; |
| 127 | if (*start >= length) return -1; |
| 128 | if (*step == 0) return -1; |
| 129 | return 0; |
| 130 | } |
| 131 | |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 132 | int |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 133 | PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length, |
| 134 | Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength) |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 135 | { |
| 136 | /* this is harder to get right than you might think */ |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 137 | |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 138 | Py_ssize_t defstart, defstop; |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 139 | |
| 140 | if (r->step == Py_None) { |
| 141 | *step = 1; |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 142 | } |
| 143 | else { |
Michael W. Hudson | cbd6fb9 | 2002-11-06 15:17:32 +0000 | [diff] [blame] | 144 | if (!_PyEval_SliceIndex(r->step, step)) return -1; |
| 145 | if (*step == 0) { |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 146 | PyErr_SetString(PyExc_ValueError, |
| 147 | "slice step cannot be zero"); |
| 148 | return -1; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | defstart = *step < 0 ? length-1 : 0; |
| 153 | defstop = *step < 0 ? -1 : length; |
| 154 | |
| 155 | if (r->start == Py_None) { |
| 156 | *start = defstart; |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 157 | } |
| 158 | else { |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 159 | if (!_PyEval_SliceIndex(r->start, start)) return -1; |
| 160 | if (*start < 0) *start += length; |
| 161 | if (*start < 0) *start = (*step < 0) ? -1 : 0; |
| 162 | if (*start >= length) |
| 163 | *start = (*step < 0) ? length - 1 : length; |
| 164 | } |
| 165 | |
| 166 | if (r->stop == Py_None) { |
| 167 | *stop = defstop; |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 168 | } |
| 169 | else { |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 170 | if (!_PyEval_SliceIndex(r->stop, stop)) return -1; |
| 171 | if (*stop < 0) *stop += length; |
| 172 | if (*stop < 0) *stop = -1; |
| 173 | if (*stop > length) *stop = length; |
| 174 | } |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 175 | |
| 176 | if ((*step < 0 && *stop >= *start) |
| 177 | || (*step > 0 && *start >= *stop)) { |
Michael W. Hudson | 589dc93 | 2002-06-11 13:38:42 +0000 | [diff] [blame] | 178 | *slicelength = 0; |
| 179 | } |
| 180 | else if (*step < 0) { |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 181 | *slicelength = (*stop-*start+1)/(*step)+1; |
Michael W. Hudson | 173f11d | 2002-11-05 15:28:51 +0000 | [diff] [blame] | 182 | } |
| 183 | else { |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 184 | *slicelength = (*stop-*start-1)/(*step)+1; |
| 185 | } |
Michael W. Hudson | 5efaf7e | 2002-06-11 10:55:12 +0000 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 190 | static PyObject * |
| 191 | slice_new(PyTypeObject *type, PyObject *args, PyObject *kw) |
| 192 | { |
| 193 | PyObject *start, *stop, *step; |
| 194 | |
| 195 | start = stop = step = NULL; |
| 196 | |
Georg Brandl | 02c4287 | 2005-08-26 06:42:30 +0000 | [diff] [blame] | 197 | if (!_PyArg_NoKeywords("slice()", kw)) |
| 198 | return NULL; |
| 199 | |
Raymond Hettinger | ea3fdf4 | 2002-12-29 16:33:45 +0000 | [diff] [blame] | 200 | if (!PyArg_UnpackTuple(args, "slice", 1, 3, &start, &stop, &step)) |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 201 | return NULL; |
| 202 | |
| 203 | /* This swapping of stop and start is to maintain similarity with |
| 204 | range(). */ |
| 205 | if (stop == NULL) { |
| 206 | stop = start; |
| 207 | start = NULL; |
| 208 | } |
| 209 | return PySlice_New(start, stop, step); |
| 210 | } |
| 211 | |
| 212 | PyDoc_STRVAR(slice_doc, |
| 213 | "slice([start,] stop[, step])\n\ |
| 214 | \n\ |
| 215 | Create a slice object. This is used for extended slicing (e.g. a[0:10:2])."); |
| 216 | |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 217 | static void |
Fred Drake | 45cfbcc | 2000-07-09 06:21:27 +0000 | [diff] [blame] | 218 | slice_dealloc(PySliceObject *r) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 219 | { |
| 220 | Py_DECREF(r->step); |
| 221 | Py_DECREF(r->start); |
| 222 | Py_DECREF(r->stop); |
Neil Schemenauer | 7465ad2 | 2002-04-12 03:05:37 +0000 | [diff] [blame] | 223 | PyObject_Del(r); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static PyObject * |
Fred Drake | 45cfbcc | 2000-07-09 06:21:27 +0000 | [diff] [blame] | 227 | slice_repr(PySliceObject *r) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 228 | { |
Walter Dörwald | 7569dfe | 2007-05-19 21:49:49 +0000 | [diff] [blame] | 229 | return PyUnicode_FromFormat("slice(%R, %R, %R)", r->start, r->stop, r->step); |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 232 | static PyMemberDef slice_members[] = { |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 233 | {"start", T_OBJECT, offsetof(PySliceObject, start), READONLY}, |
| 234 | {"stop", T_OBJECT, offsetof(PySliceObject, stop), READONLY}, |
| 235 | {"step", T_OBJECT, offsetof(PySliceObject, step), READONLY}, |
| 236 | {0} |
| 237 | }; |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 238 | |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 239 | static PyObject* |
| 240 | slice_indices(PySliceObject* self, PyObject* len) |
| 241 | { |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 242 | Py_ssize_t ilen, start, stop, step, slicelength; |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 243 | |
Thomas Wouters | 00ee7ba | 2006-08-21 19:07:27 +0000 | [diff] [blame] | 244 | ilen = PyNumber_AsSsize_t(len, PyExc_OverflowError); |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 245 | |
| 246 | if (ilen == -1 && PyErr_Occurred()) { |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | if (PySlice_GetIndicesEx(self, ilen, &start, &stop, |
| 251 | &step, &slicelength) < 0) { |
| 252 | return NULL; |
| 253 | } |
| 254 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 255 | return Py_BuildValue("(nnn)", start, stop, step); |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | PyDoc_STRVAR(slice_indices_doc, |
| 259 | "S.indices(len) -> (start, stop, stride)\n\ |
| 260 | \n\ |
| 261 | Assuming a sequence of length len, calculate the start and stop\n\ |
| 262 | indices, and the stride length of the extended slice described by\n\ |
| 263 | S. Out of bounds indices are clipped in a manner consistent with the\n\ |
| 264 | handling of normal slices."); |
| 265 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 266 | static PyObject * |
| 267 | slice_reduce(PySliceObject* self) |
| 268 | { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 269 | return Py_BuildValue("O(OOO)", Py_Type(self), self->start, self->stop, self->step); |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); |
| 273 | |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 274 | static PyMethodDef slice_methods[] = { |
Michael W. Hudson | 206d8f8 | 2002-07-19 15:52:38 +0000 | [diff] [blame] | 275 | {"indices", (PyCFunction)slice_indices, |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 276 | METH_O, slice_indices_doc}, |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 277 | {"__reduce__", (PyCFunction)slice_reduce, |
| 278 | METH_NOARGS, reduce_doc}, |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 279 | {NULL, NULL} |
| 280 | }; |
| 281 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 282 | static PyObject * |
| 283 | slice_richcompare(PyObject *v, PyObject *w, int op) |
Guido van Rossum | a1351fb | 2001-03-20 12:41:34 +0000 | [diff] [blame] | 284 | { |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 285 | PyObject *t1; |
| 286 | PyObject *t2; |
| 287 | PyObject *res; |
Guido van Rossum | a1351fb | 2001-03-20 12:41:34 +0000 | [diff] [blame] | 288 | |
Thomas Wouters | 3e57b52 | 2007-08-28 23:07:26 +0000 | [diff] [blame] | 289 | if (!PySlice_Check(v) || !PySlice_Check(w)) { |
| 290 | Py_INCREF(Py_NotImplemented); |
| 291 | return Py_NotImplemented; |
| 292 | } |
| 293 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 294 | if (v == w) { |
| 295 | /* XXX Do we really need this shortcut? |
| 296 | There's a unit test for it, but is that fair? */ |
| 297 | switch (op) { |
| 298 | case Py_EQ: |
| 299 | case Py_LE: |
| 300 | case Py_GE: |
| 301 | res = Py_True; |
| 302 | break; |
| 303 | default: |
| 304 | res = Py_False; |
| 305 | break; |
| 306 | } |
| 307 | Py_INCREF(res); |
| 308 | return res; |
| 309 | } |
Guido van Rossum | a1351fb | 2001-03-20 12:41:34 +0000 | [diff] [blame] | 310 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 311 | t1 = PyTuple_New(3); |
| 312 | t2 = PyTuple_New(3); |
| 313 | if (t1 == NULL || t2 == NULL) |
| 314 | return NULL; |
| 315 | |
| 316 | PyTuple_SET_ITEM(t1, 0, ((PySliceObject *)v)->start); |
| 317 | PyTuple_SET_ITEM(t1, 1, ((PySliceObject *)v)->stop); |
| 318 | PyTuple_SET_ITEM(t1, 2, ((PySliceObject *)v)->step); |
| 319 | PyTuple_SET_ITEM(t2, 0, ((PySliceObject *)w)->start); |
| 320 | PyTuple_SET_ITEM(t2, 1, ((PySliceObject *)w)->stop); |
| 321 | PyTuple_SET_ITEM(t2, 2, ((PySliceObject *)w)->step); |
| 322 | |
| 323 | res = PyObject_RichCompare(t1, t2, op); |
| 324 | |
| 325 | PyTuple_SET_ITEM(t1, 0, NULL); |
| 326 | PyTuple_SET_ITEM(t1, 1, NULL); |
| 327 | PyTuple_SET_ITEM(t1, 2, NULL); |
| 328 | PyTuple_SET_ITEM(t2, 0, NULL); |
| 329 | PyTuple_SET_ITEM(t2, 1, NULL); |
| 330 | PyTuple_SET_ITEM(t2, 2, NULL); |
| 331 | |
| 332 | Py_DECREF(t1); |
| 333 | Py_DECREF(t2); |
| 334 | |
| 335 | return res; |
Guido van Rossum | a1351fb | 2001-03-20 12:41:34 +0000 | [diff] [blame] | 336 | } |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 337 | |
Raymond Hettinger | b859c07 | 2003-09-05 14:27:30 +0000 | [diff] [blame] | 338 | static long |
| 339 | slice_hash(PySliceObject *v) |
| 340 | { |
| 341 | PyErr_SetString(PyExc_TypeError, "unhashable type"); |
| 342 | return -1L; |
| 343 | } |
| 344 | |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 345 | PyTypeObject PySlice_Type = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 346 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 347 | "slice", /* Name of this type */ |
| 348 | sizeof(PySliceObject), /* Basic object size */ |
| 349 | 0, /* Item size for varobject */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 350 | (destructor)slice_dealloc, /* tp_dealloc */ |
| 351 | 0, /* tp_print */ |
| 352 | 0, /* tp_getattr */ |
| 353 | 0, /* tp_setattr */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 354 | 0, /* tp_compare */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 355 | (reprfunc)slice_repr, /* tp_repr */ |
| 356 | 0, /* tp_as_number */ |
| 357 | 0, /* tp_as_sequence */ |
| 358 | 0, /* tp_as_mapping */ |
Raymond Hettinger | b859c07 | 2003-09-05 14:27:30 +0000 | [diff] [blame] | 359 | (hashfunc)slice_hash, /* tp_hash */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 360 | 0, /* tp_call */ |
| 361 | 0, /* tp_str */ |
| 362 | PyObject_GenericGetAttr, /* tp_getattro */ |
| 363 | 0, /* tp_setattro */ |
| 364 | 0, /* tp_as_buffer */ |
| 365 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 366 | slice_doc, /* tp_doc */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 367 | 0, /* tp_traverse */ |
| 368 | 0, /* tp_clear */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 369 | slice_richcompare, /* tp_richcompare */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 370 | 0, /* tp_weaklistoffset */ |
| 371 | 0, /* tp_iter */ |
| 372 | 0, /* tp_iternext */ |
Michael W. Hudson | f0d777c | 2002-07-19 15:47:06 +0000 | [diff] [blame] | 373 | slice_methods, /* tp_methods */ |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 374 | slice_members, /* tp_members */ |
| 375 | 0, /* tp_getset */ |
| 376 | 0, /* tp_base */ |
| 377 | 0, /* tp_dict */ |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 378 | 0, /* tp_descr_get */ |
| 379 | 0, /* tp_descr_set */ |
| 380 | 0, /* tp_dictoffset */ |
| 381 | 0, /* tp_init */ |
| 382 | 0, /* tp_alloc */ |
| 383 | slice_new, /* tp_new */ |
Guido van Rossum | f2d125b | 1996-07-30 16:45:48 +0000 | [diff] [blame] | 384 | }; |