Mercurial > cpython-lru_cache-weakref
annotate Objects/sliceobject.c @ 80779:10d04bdb05ab 3.3
Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python.
Patch by Zachary Ware.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sun, 09 Dec 2012 14:46:46 +0100 |
| parents | 365da47a6dc1 |
| children | 9214f8440c44 |
| 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 | |
|
53368
b5e2bcbbfa74
Merged revisions 71757 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51271
diff
changeset
|
36 PyTypeObject PyEllipsis_Type = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
37 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
38 "ellipsis", /* tp_name */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
39 0, /* tp_basicsize */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
40 0, /* tp_itemsize */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
41 0, /*never called*/ /* tp_dealloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
42 0, /* tp_print */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
43 0, /* tp_getattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
44 0, /* tp_setattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
45 0, /* tp_reserved */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
46 ellipsis_repr, /* tp_repr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
47 0, /* tp_as_number */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
48 0, /* tp_as_sequence */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
49 0, /* tp_as_mapping */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
50 0, /* tp_hash */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
51 0, /* tp_call */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
52 0, /* tp_str */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
53 PyObject_GenericGetAttr, /* tp_getattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
54 0, /* tp_setattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
55 0, /* tp_as_buffer */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
56 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
71614
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
57 0, /* tp_doc */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
58 0, /* tp_traverse */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
59 0, /* tp_clear */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
60 0, /* tp_richcompare */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
61 0, /* tp_weaklistoffset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
62 0, /* tp_iter */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
63 0, /* tp_iternext */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
64 0, /* tp_methods */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
65 0, /* tp_members */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
66 0, /* tp_getset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
67 0, /* tp_base */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
68 0, /* tp_dict */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
69 0, /* tp_descr_get */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
70 0, /* tp_descr_set */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
71 0, /* tp_dictoffset */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
72 0, /* tp_init */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
73 0, /* tp_alloc */ |
|
84c3be27b4c7
make the types of None and Ellipsis callable
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
74 ellipsis_new, /* tp_new */ |
| 3837 | 75 }; |
| 76 | |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
3861
diff
changeset
|
77 PyObject _Py_EllipsisObject = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
78 _PyObject_EXTRA_INIT |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
79 1, &PyEllipsis_Type |
| 3837 | 80 }; |
| 81 | |
| 82 | |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
83 /* Slice object implementation */ |
| 3837 | 84 |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
85 /* 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
|
86 * 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
|
87 */ |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
88 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
|
89 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
|
90 { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
91 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
|
92 if (obj != NULL) { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
93 slice_cache = NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
94 PyObject_Del(obj); |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
95 } |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
96 } |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
97 |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
98 /* start, stop, and step are python objects with None indicating no |
| 3837 | 99 index is present. |
| 100 */ | |
| 101 | |
| 102 PyObject * | |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
103 PySlice_New(PyObject *start, PyObject *stop, PyObject *step) |
| 3837 | 104 { |
|
73617
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
105 PySliceObject *obj; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
106 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
|
107 obj = slice_cache; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
108 slice_cache = NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
109 _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
|
110 } else { |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
111 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
|
112 if (obj == NULL) |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
113 return NULL; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
114 } |
|
15563
35e8a29e5488
Test for NULL returned from PyObject_NEW().
Guido van Rossum <guido@python.org>
parents:
13458
diff
changeset
|
115 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
116 if (step == NULL) step = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
117 Py_INCREF(step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
118 if (start == NULL) start = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
119 Py_INCREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
120 if (stop == NULL) stop = Py_None; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
121 Py_INCREF(stop); |
| 3837 | 122 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
123 obj->step = step; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
124 obj->start = start; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
125 obj->stop = stop; |
| 3837 | 126 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
127 return (PyObject *) obj; |
| 3837 | 128 } |
| 129 | |
|
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
|
130 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
|
131 _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
|
132 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
133 PyObject *start, *end, *slice; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
134 start = PyLong_FromSsize_t(istart); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
135 if (!start) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
136 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
137 end = PyLong_FromSsize_t(istop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
138 if (!end) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
139 Py_DECREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
140 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
141 } |
|
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
|
142 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
143 slice = PySlice_New(start, end, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
144 Py_DECREF(start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
145 Py_DECREF(end); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
146 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
|
147 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36501
diff
changeset
|
148 |
| 3837 | 149 int |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
150 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
|
151 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step) |
| 3837 | 152 { |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
153 PySliceObject *r = (PySliceObject*)_r; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
154 /* XXX support long ints */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
155 if (r->step == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
156 *step = 1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
157 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
158 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
|
159 *step = PyLong_AsSsize_t(r->step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
160 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
161 if (r->start == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
162 *start = *step < 0 ? length-1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
163 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
164 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
|
165 *start = PyLong_AsSsize_t(r->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
166 if (*start < 0) *start += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
167 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
168 if (r->stop == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
169 *stop = *step < 0 ? -1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
170 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
171 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
|
172 *stop = PyLong_AsSsize_t(r->stop); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
173 if (*stop < 0) *stop += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
174 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
175 if (*stop > length) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
176 if (*start >= length) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
177 if (*step == 0) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
178 return 0; |
| 3837 | 179 } |
| 180 | |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
181 int |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
182 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
|
183 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
|
184 Py_ssize_t *slicelength) |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
185 { |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
186 PySliceObject *r = (PySliceObject*)_r; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
187 /* 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
|
188 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
189 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
|
190 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
191 if (r->step == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
192 *step = 1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
193 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
194 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
195 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
|
196 if (*step == 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
197 PyErr_SetString(PyExc_ValueError, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
198 "slice step cannot be zero"); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
199 return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
200 } |
|
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
|
201 /* 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
|
202 * 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
|
203 * 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
|
204 * 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
|
205 */ |
|
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
|
206 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
|
207 *step = -PY_SSIZE_T_MAX; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
208 } |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
209 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
210 defstart = *step < 0 ? length-1 : 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
211 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
|
212 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
213 if (r->start == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
214 *start = defstart; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
215 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
216 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
217 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
|
218 if (*start < 0) *start += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
219 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
|
220 if (*start >= length) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
221 *start = (*step < 0) ? length - 1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
222 } |
|
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->stop == Py_None) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
225 *stop = defstop; |
|
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->stop, stop)) return -1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
229 if (*stop < 0) *stop += length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
230 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
|
231 if (*stop >= length) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
232 *stop = (*step < 0) ? length - 1 : length; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
233 } |
|
26035
6ed2e23aae45
Some days, I think my comment of
Michael W. Hudson <mwh@python.net>
parents:
25228
diff
changeset
|
234 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
235 if ((*step < 0 && *stop >= *start) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
236 || (*step > 0 && *start >= *stop)) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
237 *slicelength = 0; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
238 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
239 else if (*step < 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
240 *slicelength = (*stop-*start+1)/(*step)+1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
241 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
242 else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
243 *slicelength = (*stop-*start-1)/(*step)+1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
244 } |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
245 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
246 return 0; |
|
23778
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
247 } |
|
245224d1b8c9
This is my nearly two year old patch
Michael W. Hudson <mwh@python.net>
parents:
22978
diff
changeset
|
248 |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
249 static PyObject * |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
250 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
|
251 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
252 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
|
253 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
254 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
|
255 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
256 if (!_PyArg_NoKeywords("slice()", kw)) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
257 return NULL; |
|
35450
97c97194e64b
Disallow keyword arguments for type constructors that don't use them
Georg Brandl <georg@python.org>
parents:
30332
diff
changeset
|
258 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
259 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
|
260 return NULL; |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
261 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
262 /* 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
|
263 range(). */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
264 if (stop == NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
265 stop = start; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
266 start = NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
267 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
268 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
|
269 } |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
270 |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
271 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
|
272 "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
|
273 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
|
274 \n\ |
|
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23780
diff
changeset
|
275 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
|
276 |
| 3837 | 277 static void |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
278 slice_dealloc(PySliceObject *r) |
| 3837 | 279 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
280 Py_DECREF(r->step); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
281 Py_DECREF(r->start); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
282 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
|
283 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
|
284 slice_cache = r; |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
285 else |
|
fa2f8dd077e0
Issue #10227: Add an allocation cache for a single slice object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72958
diff
changeset
|
286 PyObject_Del(r); |
| 3837 | 287 } |
| 288 | |
| 289 static PyObject * | |
|
13458
7908ec855665
ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
290 slice_repr(PySliceObject *r) |
| 3837 | 291 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
292 return PyUnicode_FromFormat("slice(%R, %R, %R)", r->start, r->stop, r->step); |
| 3837 | 293 } |
| 294 | |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
295 static PyMemberDef slice_members[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
296 {"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
|
297 {"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
|
298 {"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
|
299 {0} |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17080
diff
changeset
|
300 }; |
| 3837 | 301 |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
302 static PyObject* |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
303 slice_indices(PySliceObject* self, PyObject* len) |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
304 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
305 Py_ssize_t ilen, start, stop, step, slicelength; |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
306 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
307 ilen = PyNumber_AsSsize_t(len, PyExc_OverflowError); |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
308 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
309 if (ilen == -1 && PyErr_Occurred()) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
310 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
311 } |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
312 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65491
diff
changeset
|
313 if (PySlice_GetIndicesEx((PyObject*)self, ilen, &start, &stop, |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
314 &step, &slicelength) < 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
315 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
316 } |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
317 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
318 return Py_BuildValue("(nnn)", start, stop, step); |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
319 } |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
320 |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
321 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
|
322 "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
|
323 \n\ |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
329 static PyObject * |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
330 slice_reduce(PySliceObject* self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
331 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
332 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
|
333 } |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
334 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39644
diff
changeset
|
335 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
|
336 |
|
24319
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
337 static PyMethodDef slice_methods[] = { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
338 {"indices", (PyCFunction)slice_indices, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
339 METH_O, slice_indices_doc}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
340 {"__reduce__", (PyCFunction)slice_reduce, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
341 METH_NOARGS, reduce_doc}, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
342 {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
|
343 }; |
|
c43466f7dae8
A few days ago, Guido said (in the thread "[Python-Dev] Python
Michael W. Hudson <mwh@python.net>
parents:
23868
diff
changeset
|
344 |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
345 static PyObject * |
|
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
346 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
|
347 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
348 PyObject *t1; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
349 PyObject *t2; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
350 PyObject *res; |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
351 |
|
71810
d0b0fcbb40db
Replace Py_NotImplemented returns with the macro form Py_RETURN_NOTIMPLEMENTED.
Brian Curtin <brian@python.org>
parents:
71614
diff
changeset
|
352 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
|
353 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
|
354 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
355 if (v == w) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
356 /* 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
|
357 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
|
358 switch (op) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
359 case Py_EQ: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
360 case Py_LE: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
361 case Py_GE: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
362 res = Py_True; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
363 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
364 default: |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
365 res = Py_False; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
366 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
367 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
368 Py_INCREF(res); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
369 return res; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
370 } |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
371 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
372 t1 = PyTuple_New(3); |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
373 if (t1 == NULL) |
|
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
374 return NULL; |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
375 t2 = PyTuple_New(3); |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
376 if (t2 == NULL) { |
|
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
377 Py_DECREF(t1); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
378 return NULL; |
|
72957
53c87a0275ab
plug possible refleak (closes #13199)
Benjamin Peterson <benjamin@python.org>
parents:
66664
diff
changeset
|
379 } |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
380 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
388 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
|
389 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
390 PyTuple_SET_ITEM(t1, 0, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
391 PyTuple_SET_ITEM(t1, 1, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
392 PyTuple_SET_ITEM(t1, 2, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
393 PyTuple_SET_ITEM(t2, 0, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
394 PyTuple_SET_ITEM(t2, 1, NULL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
395 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
|
396 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
397 Py_DECREF(t1); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
398 Py_DECREF(t2); |
|
39644
13d5e5f0e993
Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
399 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
400 return res; |
|
17080
52cb0c5fdf23
SF patch #408326 by Robin Thomas: slice objects comparable, not
Guido van Rossum <guido@python.org>
parents:
15563
diff
changeset
|
401 } |
| 3837 | 402 |
| 403 PyTypeObject PySlice_Type = { | |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
404 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
405 "slice", /* Name of this type */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
406 sizeof(PySliceObject), /* Basic object size */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
407 0, /* Item size for varobject */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
408 (destructor)slice_dealloc, /* tp_dealloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
409 0, /* tp_print */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
410 0, /* tp_getattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
411 0, /* tp_setattr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
412 0, /* tp_reserved */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
413 (reprfunc)slice_repr, /* tp_repr */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
414 0, /* tp_as_number */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
415 0, /* tp_as_sequence */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
416 0, /* tp_as_mapping */ |
|
65491
d1def7b2abd2
use helper hash unimplemented function
Benjamin Peterson <benjamin@python.org>
parents:
63775
diff
changeset
|
417 PyObject_HashNotImplemented, /* tp_hash */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
418 0, /* tp_call */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
419 0, /* tp_str */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
420 PyObject_GenericGetAttr, /* tp_getattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
421 0, /* tp_setattro */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
422 0, /* tp_as_buffer */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
423 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
424 slice_doc, /* tp_doc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
425 0, /* tp_traverse */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
426 0, /* tp_clear */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
427 slice_richcompare, /* tp_richcompare */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
428 0, /* tp_weaklistoffset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
429 0, /* tp_iter */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
430 0, /* tp_iternext */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
431 slice_methods, /* tp_methods */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
432 slice_members, /* tp_members */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
433 0, /* tp_getset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
434 0, /* tp_base */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
435 0, /* tp_dict */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
436 0, /* tp_descr_get */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
437 0, /* tp_descr_set */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
438 0, /* tp_dictoffset */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
439 0, /* tp_init */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
440 0, /* tp_alloc */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53368
diff
changeset
|
441 slice_new, /* tp_new */ |
| 3837 | 442 }; |
