Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Delta Between Two Patch Sets: Objects/rangeobject.c

Issue 28376: assertion failure in rangeobject.c
Left Patch Set: Created 3 years, 6 months ago
Right Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_range.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* Range object implementation */ 1 /* Range object implementation */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "structmember.h" 4 #include "structmember.h"
5 5
6 /* Support objects whose length is > PY_SSIZE_T_MAX. 6 /* Support objects whose length is > PY_SSIZE_T_MAX.
7 7
8 This could be sped up for small PyLongs if they fit in a Py_ssize_t. 8 This could be sped up for small PyLongs if they fit in a Py_ssize_t.
9 This only matters on Win64. Though we could use long long which 9 This only matters on Win64. Though we could use long long which
10 would presumably help perf. 10 would presumably help perf.
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 Py_TPFLAGS_DEFAULT, /* tp_flags */ 855 Py_TPFLAGS_DEFAULT, /* tp_flags */
856 0, /* tp_doc */ 856 0, /* tp_doc */
857 0, /* tp_traverse */ 857 0, /* tp_traverse */
858 0, /* tp_clear */ 858 0, /* tp_clear */
859 0, /* tp_richcompare */ 859 0, /* tp_richcompare */
860 0, /* tp_weaklistoffset */ 860 0, /* tp_weaklistoffset */
861 PyObject_SelfIter, /* tp_iter */ 861 PyObject_SelfIter, /* tp_iter */
862 (iternextfunc)rangeiter_next, /* tp_iternext */ 862 (iternextfunc)rangeiter_next, /* tp_iternext */
863 rangeiter_methods, /* tp_methods */ 863 rangeiter_methods, /* tp_methods */
864 0, /* tp_members */ 864 0, /* tp_members */
865 0, /* tp_getset */
866 0, /* tp_base */
867 0, /* tp_dict */
868 0, /* tp_descr_get */
869 0, /* tp_descr_set */
870 0, /* tp_dictoffset */
871 0, /* tp_init */
872 0, /* tp_alloc */
873 rangeiter_new, /* tp_new */
865 }; 874 };
866 875
867 /* Return number of items in range (lo, hi, step). step != 0 876 /* Return number of items in range (lo, hi, step). step != 0
868 * required. The result always fits in an unsigned long. 877 * required. The result always fits in an unsigned long.
869 */ 878 */
870 static unsigned long 879 static unsigned long
871 get_len_of_range(long lo, long hi, long step) 880 get_len_of_range(long lo, long hi, long step)
872 { 881 {
873 /* ------------------------------------------------------------- 882 /* -------------------------------------------------------------
874 If step > 0 and lo >= hi, or step < 0 and lo <= hi, the range is empty. 883 If step > 0 and lo >= hi, or step < 0 and lo <= hi, the range is empty.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 ulen = get_len_of_range(start, stop, step); 916 ulen = get_len_of_range(start, stop, step);
908 if (ulen > (unsigned long)LONG_MAX) { 917 if (ulen > (unsigned long)LONG_MAX) {
909 Py_DECREF(it); 918 Py_DECREF(it);
910 PyErr_SetString(PyExc_OverflowError, 919 PyErr_SetString(PyExc_OverflowError,
911 "range too large to represent as a range_iterator"); 920 "range too large to represent as a range_iterator");
912 return NULL; 921 return NULL;
913 } 922 }
914 it->len = (long)ulen; 923 it->len = (long)ulen;
915 it->index = 0; 924 it->index = 0;
916 return (PyObject *)it; 925 return (PyObject *)it;
926 }
927
928 static PyObject *
929 rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kw)
930 {
931 long start, stop, step;
932
933 if (PyErr_WarnEx(PyExc_DeprecationWarning,
934 "range_iterator(): creating instances of range_iterator "
935 "by calling range_iterator type is deprecated",
936 1)) {
937 return NULL;
938 }
939
940 if (!_PyArg_NoKeywords("range_iterator()", kw)) {
941 return NULL;
942 }
943
944 if (!PyArg_ParseTuple(args,
945 "lll;range_iterator() requires 3 int arguments",
946 &start, &stop, &step)) {
947 return NULL;
948 }
949 if (step == 0) {
950 PyErr_SetString(PyExc_ValueError,
951 "range_iterator() arg 3 must not be zero");
952 return NULL;
953 }
954
955 return fast_range_iter(start, stop, step);
917 } 956 }
918 957
919 typedef struct { 958 typedef struct {
920 PyObject_HEAD 959 PyObject_HEAD
921 PyObject *index; 960 PyObject *index;
922 PyObject *start; 961 PyObject *start;
923 PyObject *step; 962 PyObject *step;
924 PyObject *len; 963 PyObject *len;
925 } longrangeiterobject; 964 } longrangeiterobject;
926 965
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 it->index = PyLong_FromLong(0); 1278 it->index = PyLong_FromLong(0);
1240 if (!it->index) 1279 if (!it->index)
1241 goto create_failure; 1280 goto create_failure;
1242 1281
1243 return (PyObject *)it; 1282 return (PyObject *)it;
1244 1283
1245 create_failure: 1284 create_failure:
1246 Py_DECREF(it); 1285 Py_DECREF(it);
1247 return NULL; 1286 return NULL;
1248 } 1287 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+