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

Side by Side Diff: Objects/rangeobject.c

Issue 28376: assertion failure in rangeobject.c
Patch Set: Created 3 years, 4 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_range.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 static PyMethodDef rangeiter_methods[] = { 822 static PyMethodDef rangeiter_methods[] = {
823 {"__length_hint__", (PyCFunction)rangeiter_len, METH_NOARGS, 823 {"__length_hint__", (PyCFunction)rangeiter_len, METH_NOARGS,
824 length_hint_doc}, 824 length_hint_doc},
825 {"__reduce__", (PyCFunction)rangeiter_reduce, METH_NOARGS, 825 {"__reduce__", (PyCFunction)rangeiter_reduce, METH_NOARGS,
826 reduce_doc}, 826 reduce_doc},
827 {"__setstate__", (PyCFunction)rangeiter_setstate, METH_O, 827 {"__setstate__", (PyCFunction)rangeiter_setstate, METH_O,
828 setstate_doc}, 828 setstate_doc},
829 {NULL, NULL} /* sentinel */ 829 {NULL, NULL} /* sentinel */
830 }; 830 };
831 831
832 static PyObject *rangeiter_new(PyTypeObject *, PyObject *args, PyObject *kw); 832 static PyObject *rangeiter_new(PyTypeObject *, PyObject *args, PyObject *kw);
storchaka 2016/10/08 21:08:46 warning: ‘rangeiter_new’ declared ‘static’ but nev
833 833
834 PyTypeObject PyRangeIter_Type = { 834 PyTypeObject PyRangeIter_Type = {
835 PyVarObject_HEAD_INIT(&PyType_Type, 0) 835 PyVarObject_HEAD_INIT(&PyType_Type, 0)
836 "range_iterator", /* tp_name */ 836 "range_iterator", /* tp_name */
837 sizeof(rangeiterobject), /* tp_basicsize */ 837 sizeof(rangeiterobject), /* tp_basicsize */
838 0, /* tp_itemsize */ 838 0, /* tp_itemsize */
839 /* methods */ 839 /* methods */
840 (destructor)PyObject_Del, /* tp_dealloc */ 840 (destructor)PyObject_Del, /* tp_dealloc */
841 0, /* tp_print */ 841 0, /* tp_print */
842 0, /* tp_getattr */ 842 0, /* tp_getattr */
(...skipping 12 matching lines...) Expand all
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 */
874 }; 865 };
875 866
876 /* Return number of items in range (lo, hi, step). step != 0 867 /* Return number of items in range (lo, hi, step). step != 0
877 * required. The result always fits in an unsigned long. 868 * required. The result always fits in an unsigned long.
878 */ 869 */
879 static unsigned long 870 static unsigned long
880 get_len_of_range(long lo, long hi, long step) 871 get_len_of_range(long lo, long hi, long step)
881 { 872 {
882 /* ------------------------------------------------------------- 873 /* -------------------------------------------------------------
883 If step > 0 and lo >= hi, or step < 0 and lo <= hi, the range is empty. 874 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
916 ulen = get_len_of_range(start, stop, step); 907 ulen = get_len_of_range(start, stop, step);
917 if (ulen > (unsigned long)LONG_MAX) { 908 if (ulen > (unsigned long)LONG_MAX) {
918 Py_DECREF(it); 909 Py_DECREF(it);
919 PyErr_SetString(PyExc_OverflowError, 910 PyErr_SetString(PyExc_OverflowError,
920 "range too large to represent as a range_iterator"); 911 "range too large to represent as a range_iterator");
921 return NULL; 912 return NULL;
922 } 913 }
923 it->len = (long)ulen; 914 it->len = (long)ulen;
924 it->index = 0; 915 it->index = 0;
925 return (PyObject *)it; 916 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 (!_PyArg_NoKeywords("rangeiter()", kw))
934 return NULL;
935
936 if (!PyArg_ParseTuple(args, "lll;rangeiter() requires 3 int arguments",
937 &start, &stop, &step))
938 return NULL;
939
940 return fast_range_iter(start, stop, step);
941 } 917 }
942 918
943 typedef struct { 919 typedef struct {
944 PyObject_HEAD 920 PyObject_HEAD
945 PyObject *index; 921 PyObject *index;
946 PyObject *start; 922 PyObject *start;
947 PyObject *step; 923 PyObject *step;
948 PyObject *len; 924 PyObject *len;
949 } longrangeiterobject; 925 } longrangeiterobject;
950 926
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 it->index = PyLong_FromLong(0); 1239 it->index = PyLong_FromLong(0);
1264 if (!it->index) 1240 if (!it->index)
1265 goto create_failure; 1241 goto create_failure;
1266 1242
1267 return (PyObject *)it; 1243 return (PyObject *)it;
1268 1244
1269 create_failure: 1245 create_failure:
1270 Py_DECREF(it); 1246 Py_DECREF(it);
1271 return NULL; 1247 return NULL;
1272 } 1248 }
OLDNEW
« no previous file with comments | « Lib/test/test_range.py ('k') | no next file » | no next file with comments »

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