Mercurial > cpython-lru_cache-weakref
annotate Objects/sliceobject.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 04ccb2e0307e |
| children |
| rev | line source |
|---|---|
| 3837 | 1 /* |
| 2 Written by Jim Hugunin and Chris Chase. | |
| 3 | |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
3861
diff
changeset
|
4 This includes both the singular ellipsis object and slice objects. |
| 3837 | 5 |
| 6 Guido, feel free to do whatever you want in the way of copyrights | |
| 7 for this file. | |
| 8 */ | |
| 9 | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
10 /* |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
3861
diff
changeset
|
11 Py_Ellipsis encodes the '...' rubber index token. It is similar to |
| 3837 | 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" | |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17080
diff
changeset
|
17 #include "structmember.h" |
| 3837 | 18 |
| 19 static PyObject * | |
|
71614
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
20 ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
21 { |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
22 if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_Size(kwargs))) { |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
23 PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments"); |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
24 return NULL; |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
25 } |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
26 Py_INCREF(Py_Ellipsis); |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
27 return Py_Ellipsis; |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
28 } |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
29 |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
30 static PyObject * |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
31 ellipsis_repr(PyObject *op) |
| 3837 | 32 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
33 return PyUnicode_FromString("Ellipsis"); |
| 3837 | 34 } |
| 35 | |
|
87494
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
36 static PyObject * |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
37 ellipsis_reduce(PyObject *op) |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
38 { |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
39 return PyUnicode_FromString("Ellipsis"); |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
40 } |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
41 |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
42 static PyMethodDef ellipsis_methods[] = { |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
43 {"__reduce__", (PyCFunction)ellipsis_reduce, METH_NOARGS, NULL}, |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
44 {NULL, NULL} |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
45 }; |
|
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
46 |
|
53368
b5e2bcbbfa74
Merged revisions 71757 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
47 PyTypeObject PyEllipsis_Type = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
48 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
49 "ellipsis", /* tp_name */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
50 0, /* tp_basicsize */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
51 0, /* tp_itemsize */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
52 0, /*never called*/ /* tp_dealloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
53 0, /* tp_print */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
54 0, /* tp_getattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
55 0, /* tp_setattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
56 0, /* tp_reserved */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
57 ellipsis_repr, /* tp_repr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
58 0, /* tp_as_number */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
59 0, /* tp_as_sequence */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
60 0, /* tp_as_mapping */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
61 0, /* tp_hash */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
62 0, /* tp_call */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
63 0, /* tp_str */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
64 PyObject_GenericGetAttr, /* tp_getattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
65 0, /* tp_setattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
66 0, /* tp_as_buffer */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
67 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
71614
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
68 0, /* tp_doc */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
69 0, /* tp_traverse */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
70 0, /* tp_clear */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
71 0, /* tp_richcompare */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
72 0, /* tp_weaklistoffset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
73 0, /* tp_iter */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
74 0, /* tp_iternext */ |
|
87494
04ccb2e0307e
Make Ellipsis and NotImplemented picklable through the reduce protocol.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
80477
diff
changeset
|
75 ellipsis_methods, /* tp_methods */ |
|
71614
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
76 0, /* tp_members */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
77 0, /* tp_getset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
78 0, /* tp_base */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
79 0, /* tp_dict */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
80 0, /* tp_descr_get */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
81 0, /* tp_descr_set */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
82 0, /* tp_dictoffset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
83 0, /* tp_init */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
84 0, /* tp_alloc */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
85 ellipsis_new, /* tp_new */ |
| 3837 | 86 }; |
| 87 | |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
3861
diff
changeset
|
88 PyObject _Py_EllipsisObject = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
89 _PyObject_EXTRA_INIT |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
90 1, &PyEllipsis_Type |
| 3837 | 91 }; |
| 92 | |
| 93 | |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
94 /* Slice object implementation */ |
| 3837 | 95 |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
96 /* Using a cache is very effective since typically only a single slice is |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
97 * created and then deleted again |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
98 */ |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
99 static PySliceObject *slice_cache = NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
100 void PySlice_Fini(void) |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
101 { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
102 PySliceObject *obj = slice_cache; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
103 if (obj != NULL) { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
104 slice_cache = NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
105 PyObject_Del(obj); |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
106 } |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
107 } |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
108 |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
109 /* start, stop, and step are python objects with None indicating no |
| 3837 | 110 index is present. |
| 111 */ | |
| 112 | |
| 113 PyObject * | |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
114 PySlice_New(PyObject *start, PyObject *stop, PyObject *step) |
| 3837 | 115 { |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
116 PySliceObject *obj; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
117 if (slice_cache != NULL) { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
118 obj = slice_cache; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
119 slice_cache = NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
120 _Py_NewReference((PyObject *)obj); |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
121 } else { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
122 obj = PyObject_New(PySliceObject, &PySlice_Type); |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
123 if (obj == NULL) |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
124 return NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
125 } |
|
15563
35e8a29e5488
Test for NULL returned from PyObject_NEW().
Guido van Rossum <guido@python.org>
parents:
13458
diff
changeset
|
126 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
127 if (step == NULL) step = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
128 Py_INCREF(step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
129 if (start == NULL) start = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
130 Py_INCREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
131 if (stop == NULL) stop = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
132 Py_INCREF(stop); |
| 3837 | 133 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
134 obj->step = step; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
135 obj->start = start; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
136 obj->stop = stop; |
| 3837 | 137 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
138 return (PyObject *) obj; |
| 3837 | 139 } |
| 140 | |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
141 PyObject * |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
142 _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
143 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
144 PyObject *start, *end, *slice; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
145 start = PyLong_FromSsize_t(istart); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
146 if (!start) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
147 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
148 end = PyLong_FromSsize_t(istop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
149 if (!end) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
150 Py_DECREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
151 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
152 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
153 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
154 slice = PySlice_New(start, end, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
155 Py_DECREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
156 Py_DECREF(end); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
157 return slice; |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
158 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
159 |
| 3837 | 160 int |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
161 PySlice_GetIndices(PyObject *_r, Py_ssize_t length, |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35450
diff
changeset
|
162 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) |
| 3837 | 163 { |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
164 PySliceObject *r = (PySliceObject*)_r; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
165 /* XXX support long ints */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
166 if (r->step == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
167 *step = 1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
168 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
169 if (!PyLong_Check(r->step)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
170 *step = PyLong_AsSsize_t(r->step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
171 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
172 if (r->start == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
173 *start = *step < 0 ? length-1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
174 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
175 if (!PyLong_Check(r->start)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
176 *start = PyLong_AsSsize_t(r->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
177 if (*start < 0) *start += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
178 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
179 if (r->stop == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
180 *stop = *step < 0 ? -1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
181 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
182 if (!PyLong_Check(r->stop)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
183 *stop = PyLong_AsSsize_t(r->stop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
184 if (*stop < 0) *stop += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
185 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
186 if (*stop > length) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
187 if (*start >= length) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
188 if (*step == 0) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
189 return 0; |
| 3837 | 190 } |
| 191 | |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
192 int |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
193 PySlice_GetIndicesEx(PyObject *_r, Py_ssize_t length, |
|
63775
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
194 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
195 Py_ssize_t *slicelength) |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
196 { |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
197 PySliceObject *r = (PySliceObject*)_r; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
198 /* this is harder to get right than you might think */ |
|
26035
6ed2e23aae45
Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents:
25228
diff
changeset
|
199 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
200 Py_ssize_t defstart, defstop; |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
201 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
202 if (r->step == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
203 *step = 1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
204 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
205 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
206 if (!_PyEval_SliceIndex(r->step, step)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
207 if (*step == 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
208 PyErr_SetString(PyExc_ValueError, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
209 "slice step cannot be zero"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
210 return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
211 } |
|
63775
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
212 /* Here *step might be -PY_SSIZE_T_MAX-1; in this case we replace it |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
213 * with -PY_SSIZE_T_MAX. This doesn't affect the semantics, and it |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
214 * guards against later undefined behaviour resulting from code that |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
215 * does "step = -step" as part of a slice reversal. |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
216 */ |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
217 if (*step < -PY_SSIZE_T_MAX) |
|
f7bd28b3c683
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Mark Dickinson <dickinsm@gmail.com>
parents:
61466
diff
changeset
|
218 *step = -PY_SSIZE_T_MAX; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
219 } |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
220 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
221 defstart = *step < 0 ? length-1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
222 defstop = *step < 0 ? -1 : length; |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
223 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
224 if (r->start == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
225 *start = defstart; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
226 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
227 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
228 if (!_PyEval_SliceIndex(r->start, start)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
229 if (*start < 0) *start += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
230 if (*start < 0) *start = (*step < 0) ? -1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
231 if (*start >= length) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
232 *start = (*step < 0) ? length - 1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
233 } |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
234 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
235 if (r->stop == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
236 *stop = defstop; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
237 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
238 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
239 if (!_PyEval_SliceIndex(r->stop, stop)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
240 if (*stop < 0) *stop += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
241 if (*stop < 0) *stop = (*step < 0) ? -1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
242 if (*stop >= length) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
243 *stop = (*step < 0) ? length - 1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
244 } |
|
26035
6ed2e23aae45
Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents:
25228
diff
changeset
|
245 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
246 if ((*step < 0 && *stop >= *start) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
247 || (*step > 0 && *start >= *stop)) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
248 *slicelength = 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
249 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
250 else if (*step < 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
251 *slicelength = (*stop-*start+1)/(*step)+1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
252 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
253 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
254 *slicelength = (*stop-*start-1)/(*step)+1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
255 } |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
256 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
257 return 0; |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
258 } |
|
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
259 |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
260 static PyObject * |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
261 slice_new(PyTypeObject *type, PyObject *args, PyObject *kw) |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
262 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
263 PyObject *start, *stop, *step; |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
264 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
265 start = stop = step = NULL; |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
266 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
267 if (!_PyArg_NoKeywords("slice()", kw)) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
268 return NULL; |
|
35450
97c97194e64b
Disallow keyword arguments for type constructors that don't use them
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
269 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
270 if (!PyArg_UnpackTuple(args, "slice", 1, 3, &start, &stop, &step)) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
271 return NULL; |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
272 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
273 /* This swapping of stop and start is to maintain similarity with |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
274 range(). */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
275 if (stop == NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
276 stop = start; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
277 start = NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
278 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
279 return PySlice_New(start, stop, step); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
280 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
281 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
282 PyDoc_STRVAR(slice_doc, |
|
79587
e4598364ea29
Issue #14783: Improve int() docstring and also str(), range(), and slice().
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
72957
diff
changeset
|
283 "slice(stop)\n\ |
|
e4598364ea29
Issue #14783: Improve int() docstring and also str(), range(), and slice().
Chris Jerdonek <chris.jerdonek@gmail.com>
parents:
72957
diff
changeset
|
284 slice(start, stop[, step])\n\ |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
285 \n\ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
286 Create a slice object. This is used for extended slicing (e.g. a[0:10:2])."); |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
287 |
| 3837 | 288 static void |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
289 slice_dealloc(PySliceObject *r) |
| 3837 | 290 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
291 Py_DECREF(r->step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
292 Py_DECREF(r->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
293 Py_DECREF(r->stop); |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
294 if (slice_cache == NULL) |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
295 slice_cache = r; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
296 else |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
297 PyObject_Del(r); |
| 3837 | 298 } |
| 299 | |
| 300 static PyObject * | |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
301 slice_repr(PySliceObject *r) |
| 3837 | 302 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
303 return PyUnicode_FromFormat("slice(%R, %R, %R)", r->start, r->stop, r->step); |
| 3837 | 304 } |
| 305 | |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
306 static PyMemberDef slice_members[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
307 {"start", T_OBJECT, offsetof(PySliceObject, start), READONLY}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
308 {"stop", T_OBJECT, offsetof(PySliceObject, stop), READONLY}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
309 {"step", T_OBJECT, offsetof(PySliceObject, step), READONLY}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
310 {0} |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17080
diff
changeset
|
311 }; |
| 3837 | 312 |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
313 /* Helper function to convert a slice argument to a PyLong, and raise TypeError |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
314 with a suitable message on failure. */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
315 |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
316 static PyObject* |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
317 evaluate_slice_index(PyObject *v) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
318 { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
319 if (PyIndex_Check(v)) { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
320 return PyNumber_Index(v); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
321 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
322 else { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
323 PyErr_SetString(PyExc_TypeError, |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
324 "slice indices must be integers or " |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
325 "None or have an __index__ method"); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
326 return NULL; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
327 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
328 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
329 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
330 /* Compute slice indices given a slice and length. Return -1 on failure. Used |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
331 by slice.indices and rangeobject slicing. Assumes that `len` is a |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
332 nonnegative instance of PyLong. */ |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
333 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
334 int |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
335 _PySlice_GetLongIndices(PySliceObject *self, PyObject *length, |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
336 PyObject **start_ptr, PyObject **stop_ptr, |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
337 PyObject **step_ptr) |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
338 { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
339 PyObject *start=NULL, *stop=NULL, *step=NULL; |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
340 PyObject *upper=NULL, *lower=NULL; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
341 int step_is_negative, cmp_result; |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
342 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
343 /* Convert step to an integer; raise for zero step. */ |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
344 if (self->step == Py_None) { |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
345 step = PyLong_FromLong(1L); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
346 if (step == NULL) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
347 goto error; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
348 step_is_negative = 0; |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
349 } |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
350 else { |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
351 int step_sign; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
352 step = evaluate_slice_index(self->step); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
353 if (step == NULL) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
354 goto error; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
355 step_sign = _PyLong_Sign(step); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
356 if (step_sign == 0) { |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
357 PyErr_SetString(PyExc_ValueError, |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
358 "slice step cannot be zero"); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
359 goto error; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
360 } |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
361 step_is_negative = step_sign < 0; |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
362 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
363 |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
364 /* Find lower and upper bounds for start and stop. */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
365 if (step_is_negative) { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
366 lower = PyLong_FromLong(-1L); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
367 if (lower == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
368 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
369 |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
370 upper = PyNumber_Add(length, lower); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
371 if (upper == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
372 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
373 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
374 else { |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
375 lower = PyLong_FromLong(0L); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
376 if (lower == NULL) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
377 goto error; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
378 |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
379 upper = length; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
380 Py_INCREF(upper); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
381 } |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
382 |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
383 /* Compute start. */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
384 if (self->start == Py_None) { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
385 start = step_is_negative ? upper : lower; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
386 Py_INCREF(start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
387 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
388 else { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
389 start = evaluate_slice_index(self->start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
390 if (start == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
391 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
392 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
393 if (_PyLong_Sign(start) < 0) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
394 /* start += length */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
395 PyObject *tmp = PyNumber_Add(start, length); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
396 Py_DECREF(start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
397 start = tmp; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
398 if (start == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
399 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
400 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
401 cmp_result = PyObject_RichCompareBool(start, lower, Py_LT); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
402 if (cmp_result < 0) |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
403 goto error; |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
404 if (cmp_result) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
405 Py_INCREF(lower); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
406 Py_DECREF(start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
407 start = lower; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
408 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
409 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
410 else { |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
411 cmp_result = PyObject_RichCompareBool(start, upper, Py_GT); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
412 if (cmp_result < 0) |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
413 goto error; |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
414 if (cmp_result) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
415 Py_INCREF(upper); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
416 Py_DECREF(start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
417 start = upper; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
418 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
419 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
420 } |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
421 |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
422 /* Compute stop. */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
423 if (self->stop == Py_None) { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
424 stop = step_is_negative ? lower : upper; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
425 Py_INCREF(stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
426 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
427 else { |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
428 stop = evaluate_slice_index(self->stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
429 if (stop == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
430 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
431 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
432 if (_PyLong_Sign(stop) < 0) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
433 /* stop += length */ |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
434 PyObject *tmp = PyNumber_Add(stop, length); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
435 Py_DECREF(stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
436 stop = tmp; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
437 if (stop == NULL) |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
438 goto error; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
439 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
440 cmp_result = PyObject_RichCompareBool(stop, lower, Py_LT); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
441 if (cmp_result < 0) |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
442 goto error; |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
443 if (cmp_result) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
444 Py_INCREF(lower); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
445 Py_DECREF(stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
446 stop = lower; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
447 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
448 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
449 else { |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
450 cmp_result = PyObject_RichCompareBool(stop, upper, Py_GT); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
451 if (cmp_result < 0) |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
452 goto error; |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
453 if (cmp_result) { |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
454 Py_INCREF(upper); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
455 Py_DECREF(stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
456 stop = upper; |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
457 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
458 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
459 } |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
460 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
461 *start_ptr = start; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
462 *stop_ptr = stop; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
463 *step_ptr = step; |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
464 Py_DECREF(upper); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
465 Py_DECREF(lower); |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
466 return 0; |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
467 |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
468 error: |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
469 *start_ptr = *stop_ptr = *step_ptr = NULL; |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
470 Py_XDECREF(start); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
471 Py_XDECREF(stop); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
472 Py_XDECREF(step); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
473 Py_XDECREF(upper); |
|
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
474 Py_XDECREF(lower); |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
475 return -1; |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
476 } |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
477 |
|
80477
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
478 /* Implementation of slice.indices. */ |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
479 |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
480 static PyObject* |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
481 slice_indices(PySliceObject* self, PyObject* len) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
482 { |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
483 PyObject *start, *stop, *step; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
484 PyObject *length; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
485 int error; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
486 |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
487 /* Convert length to an integer if necessary; raise for negative length. */ |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
488 length = PyNumber_Index(len); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
489 if (length == NULL) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
490 return NULL; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
491 |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
492 if (_PyLong_Sign(length) < 0) { |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
493 PyErr_SetString(PyExc_ValueError, |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
494 "length should not be negative"); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
495 Py_DECREF(length); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
496 return NULL; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
497 } |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
498 |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
499 error = _PySlice_GetLongIndices(self, length, &start, &stop, &step); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
500 Py_DECREF(length); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
501 if (error == -1) |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
502 return NULL; |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
503 else |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
504 return Py_BuildValue("(NNN)", start, stop, step); |
|
e9af9b1ca67e
Issue #16451: Refactor to remove duplication between range and slice in slice index computations.
Mark Dickinson <mdickinson@enthought.com>
parents:
80338
diff
changeset
|
505 } |
|
80338
9214f8440c44
Issue #14794: slice.indices no longer returns OverflowError for out-of-range start, stop, step or length.
Mark Dickinson <mdickinson@enthought.com>
parents:
79588
diff
changeset
|
506 |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
507 PyDoc_STRVAR(slice_indices_doc, |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
508 "S.indices(len) -> (start, stop, stride)\n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
509 \n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
510 Assuming a sequence of length len, calculate the start and stop\n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
511 indices, and the stride length of the extended slice described by\n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
512 S. Out of bounds indices are clipped in a manner consistent with the\n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
513 handling of normal slices."); |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
514 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
515 static PyObject * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
516 slice_reduce(PySliceObject* self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
517 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
518 return Py_BuildValue("O(OOO)", Py_TYPE(self), self->start, self->stop, self->step); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
519 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
520 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
521 PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
522 |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
523 static PyMethodDef slice_methods[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
524 {"indices", (PyCFunction)slice_indices, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
525 METH_O, slice_indices_doc}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
526 {"__reduce__", (PyCFunction)slice_reduce, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
527 METH_NOARGS, reduce_doc}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
528 {NULL, NULL} |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
529 }; |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
530 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
531 static PyObject * |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
532 slice_richcompare(PyObject *v, PyObject *w, int op) |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
533 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
534 PyObject *t1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
535 PyObject *t2; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
536 PyObject *res; |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
537 |
|
71810
d0b0fcbb40db
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
Brian Curtin <brian@python.org>
parents:
71614
diff
changeset
|
538 if (!PySlice_Check(v) || !PySlice_Check(w)) |
|
d0b0fcbb40db
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
Brian Curtin <brian@python.org>
parents:
71614
diff
changeset
|
539 Py_RETURN_NOTIMPLEMENTED; |
|
42955
30511068d3d4
Fix buglet in sliceobjects, they were not returning Py_NotImplemented when
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
540 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
541 if (v == w) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
542 /* XXX Do we really need this shortcut? |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
543 There's a unit test for it, but is that fair? */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
544 switch (op) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
545 case Py_EQ: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
546 case Py_LE: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
547 case Py_GE: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
548 res = Py_True; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
549 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
550 default: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
551 res = Py_False; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
552 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
553 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
554 Py_INCREF(res); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
555 return res; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
556 } |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
557 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
558 t1 = PyTuple_New(3); |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
559 if (t1 == NULL) |
|
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
560 return NULL; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
561 t2 = PyTuple_New(3); |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
562 if (t2 == NULL) { |
|
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
563 Py_DECREF(t1); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
564 return NULL; |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
565 } |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
566 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
567 PyTuple_SET_ITEM(t1, 0, ((PySliceObject *)v)->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
568 PyTuple_SET_ITEM(t1, 1, ((PySliceObject *)v)->stop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
569 PyTuple_SET_ITEM(t1, 2, ((PySliceObject *)v)->step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
570 PyTuple_SET_ITEM(t2, 0, ((PySliceObject *)w)->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
571 PyTuple_SET_ITEM(t2, 1, ((PySliceObject *)w)->stop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
572 PyTuple_SET_ITEM(t2, 2, ((PySliceObject *)w)->step); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
573 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
574 res = PyObject_RichCompare(t1, t2, op); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
575 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
576 PyTuple_SET_ITEM(t1, 0, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
577 PyTuple_SET_ITEM(t1, 1, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
578 PyTuple_SET_ITEM(t1, 2, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
579 PyTuple_SET_ITEM(t2, 0, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
580 PyTuple_SET_ITEM(t2, 1, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
581 PyTuple_SET_ITEM(t2, 2, NULL); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
582 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
583 Py_DECREF(t1); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
584 Py_DECREF(t2); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
585 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
586 return res; |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
587 } |
| 3837 | 588 |
| 589 PyTypeObject PySlice_Type = { | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
590 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
591 "slice", /* Name of this type */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
592 sizeof(PySliceObject), /* Basic object size */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
593 0, /* Item size for varobject */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
594 (destructor)slice_dealloc, /* tp_dealloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
595 0, /* tp_print */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
596 0, /* tp_getattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
597 0, /* tp_setattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
598 0, /* tp_reserved */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
599 (reprfunc)slice_repr, /* tp_repr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
600 0, /* tp_as_number */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
601 0, /* tp_as_sequence */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
602 0, /* tp_as_mapping */ |
|
65491
d1def7b2abd2
use helper hash unimplemented function
Benjamin Peterson <benjamin@python.org>
parents:
63775
diff
changeset
|
603 PyObject_HashNotImplemented, /* tp_hash */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
604 0, /* tp_call */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
605 0, /* tp_str */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
606 PyObject_GenericGetAttr, /* tp_getattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
607 0, /* tp_setattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
608 0, /* tp_as_buffer */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
609 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
610 slice_doc, /* tp_doc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
611 0, /* tp_traverse */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
612 0, /* tp_clear */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
613 slice_richcompare, /* tp_richcompare */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
614 0, /* tp_weaklistoffset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
615 0, /* tp_iter */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
616 0, /* tp_iternext */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
617 slice_methods, /* tp_methods */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
618 slice_members, /* tp_members */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
619 0, /* tp_getset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
620 0, /* tp_base */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
621 0, /* tp_dict */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
622 0, /* tp_descr_get */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
623 0, /* tp_descr_set */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
624 0, /* tp_dictoffset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
625 0, /* tp_init */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
626 0, /* tp_alloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
627 slice_new, /* tp_new */ |
| 3837 | 628 }; |
