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

Side by Side Diff: Modules/itertoolsmodule.c

Issue 28261: wrong error messages when using PyArg_ParseTuple to parse normal tuples
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:
View unified diff | Download patch
OLDNEW
1 1
2 #define PY_SSIZE_T_CLEAN 2 #define PY_SSIZE_T_CLEAN
3 #include "Python.h" 3 #include "Python.h"
4 #include "structmember.h" 4 #include "structmember.h"
5 5
6 /* Itertools module written and maintained 6 /* Itertools module written and maintained
7 by Raymond D. Hettinger <python@rcn.com> 7 by Raymond D. Hettinger <python@rcn.com>
8 */ 8 */
9 9
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 return value; 141 return value;
142 } 142 }
143 143
144 PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); 144 PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
145 145
146 static PyObject * 146 static PyObject *
147 groupby_setstate(groupbyobject *lz, PyObject *state) 147 groupby_setstate(groupbyobject *lz, PyObject *state)
148 { 148 {
149 PyObject *currkey, *currvalue, *tgtkey; 149 PyObject *currkey, *currvalue, *tgtkey;
150 if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) 150 if (!PyArg_ParseTuple(state,
151 "OOO;groupby.__setstate__: illegal state argument",
152 &currkey, &currvalue, &tgtkey)) {
151 return NULL; 153 return NULL;
154 }
152 Py_INCREF(currkey); 155 Py_INCREF(currkey);
153 Py_XSETREF(lz->currkey, currkey); 156 Py_XSETREF(lz->currkey, currkey);
154 Py_INCREF(currvalue); 157 Py_INCREF(currvalue);
155 Py_XSETREF(lz->currvalue, currvalue); 158 Py_XSETREF(lz->currvalue, currvalue);
156 Py_INCREF(tgtkey); 159 Py_INCREF(tgtkey);
157 Py_XSETREF(lz->tgtkey, tgtkey); 160 Py_XSETREF(lz->tgtkey, tgtkey);
158 Py_RETURN_NONE; 161 Py_RETURN_NONE;
159 } 162 }
160 163
161 PyDoc_STRVAR(setstate_doc, "Set state information for unpickling."); 164 PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 tee_reduce(teeobject *to) 723 tee_reduce(teeobject *to)
721 { 724 {
722 return Py_BuildValue("O(())(Oi)", Py_TYPE(to), to->dataobj, to->index); 725 return Py_BuildValue("O(())(Oi)", Py_TYPE(to), to->dataobj, to->index);
723 } 726 }
724 727
725 static PyObject * 728 static PyObject *
726 tee_setstate(teeobject *to, PyObject *state) 729 tee_setstate(teeobject *to, PyObject *state)
727 { 730 {
728 teedataobject *tdo; 731 teedataobject *tdo;
729 int index; 732 int index;
730 if (!PyArg_ParseTuple(state, "O!i", &teedataobject_type, &tdo, &index)) 733 if (!PyArg_ParseTuple(state,
734 "O!i;_tee.__setstate__: illegal state argument",
735 &teedataobject_type, &tdo, &index)) {
731 return NULL; 736 return NULL;
737 }
732 if (index < 0 || index > LINKCELLS) { 738 if (index < 0 || index > LINKCELLS) {
733 PyErr_SetString(PyExc_ValueError, "Index out of range"); 739 PyErr_SetString(PyExc_ValueError, "Index out of range");
734 return NULL; 740 return NULL;
735 } 741 }
736 Py_INCREF(tdo); 742 Py_INCREF(tdo);
737 Py_XSETREF(to->dataobj, tdo); 743 Py_XSETREF(to->dataobj, tdo);
738 to->index = index; 744 to->index = index;
739 Py_RETURN_NONE; 745 Py_RETURN_NONE;
740 } 746 }
741 747
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), lz->it, lz->saved, 971 return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), lz->it, lz->saved,
966 lz->firstpass); 972 lz->firstpass);
967 } 973 }
968 974
969 static PyObject * 975 static PyObject *
970 cycle_setstate(cycleobject *lz, PyObject *state) 976 cycle_setstate(cycleobject *lz, PyObject *state)
971 { 977 {
972 PyObject *saved=NULL; 978 PyObject *saved=NULL;
973 int firstpass; 979 int firstpass;
974 980
975 if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass)) 981 if (!PyArg_ParseTuple(state,
982 "O!i;cycle.__setstate__: illegal state argument",
983 &PyList_Type, &saved, &firstpass)) {
976 return NULL; 984 return NULL;
985 }
977 Py_INCREF(saved); 986 Py_INCREF(saved);
978 Py_XSETREF(lz->saved, saved); 987 Py_XSETREF(lz->saved, saved);
979 lz->firstpass = firstpass != 0; 988 lz->firstpass = firstpass != 0;
980 lz->index = 0; 989 lz->index = 0;
981 Py_RETURN_NONE; 990 Py_RETURN_NONE;
982 } 991 }
983 992
984 static PyMethodDef cycle_methods[] = { 993 static PyMethodDef cycle_methods[] = {
985 {"__reduce__", (PyCFunction)cycle_reduce, METH_NOARGS, 994 {"__reduce__", (PyCFunction)cycle_reduce, METH_NOARGS,
986 reduce_doc}, 995 reduce_doc},
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 return Py_BuildValue("O()", Py_TYPE(lz)); /* exhausted */ 1905 return Py_BuildValue("O()", Py_TYPE(lz)); /* exhausted */
1897 } 1906 }
1898 return NULL; 1907 return NULL;
1899 } 1908 }
1900 1909
1901 static PyObject * 1910 static PyObject *
1902 chain_setstate(chainobject *lz, PyObject *state) 1911 chain_setstate(chainobject *lz, PyObject *state)
1903 { 1912 {
1904 PyObject *source, *active=NULL; 1913 PyObject *source, *active=NULL;
1905 1914
1906 if (! PyArg_ParseTuple(state, "O|O", &source, &active)) 1915 if (!PyArg_ParseTuple(state,
1916 "O|O;chain.__setstate__: illegal state argument",
1917 &source, &active)) {
1907 return NULL; 1918 return NULL;
1919 }
1908 1920
1909 Py_INCREF(source); 1921 Py_INCREF(source);
1910 Py_XSETREF(lz->source, source); 1922 Py_XSETREF(lz->source, source);
1911 Py_XINCREF(active); 1923 Py_XINCREF(active);
1912 Py_XSETREF(lz->active, active); 1924 Py_XSETREF(lz->active, active);
1913 Py_RETURN_NONE; 1925 Py_RETURN_NONE;
1914 } 1926 }
1915 1927
1916 PyDoc_STRVAR(chain_doc, 1928 PyDoc_STRVAR(chain_doc,
1917 "chain(*iterables) --> chain object\n\ 1929 "chain(*iterables) --> chain object\n\
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 return NULL; 3267 return NULL;
3256 } 3268 }
3257 } 3269 }
3258 3270
3259 static PyObject * 3271 static PyObject *
3260 permutations_setstate(permutationsobject *po, PyObject *state) 3272 permutations_setstate(permutationsobject *po, PyObject *state)
3261 { 3273 {
3262 PyObject *indices, *cycles, *result; 3274 PyObject *indices, *cycles, *result;
3263 Py_ssize_t n, i; 3275 Py_ssize_t n, i;
3264 3276
3265 if (!PyArg_ParseTuple(state, "O!O!", 3277 if (!PyArg_ParseTuple(state,
3266 &PyTuple_Type, &indices, 3278 "O!O!;permutations.__setstate__: illegal state "
3267 &PyTuple_Type, &cycles)) 3279 "argument", &PyTuple_Type, &indices,
3280 &PyTuple_Type, &cycles)) {
3268 return NULL; 3281 return NULL;
3282 }
3269 3283
3270 n = PyTuple_GET_SIZE(po->pool); 3284 n = PyTuple_GET_SIZE(po->pool);
3271 if (PyTuple_GET_SIZE(indices) != n || PyTuple_GET_SIZE(cycles) != po->r) { 3285 if (PyTuple_GET_SIZE(indices) != n || PyTuple_GET_SIZE(cycles) != po->r) {
3272 PyErr_SetString(PyExc_ValueError, "invalid arguments"); 3286 PyErr_SetString(PyExc_ValueError, "invalid arguments");
3273 return NULL; 3287 return NULL;
3274 } 3288 }
3275 3289
3276 for (i=0; i<n; i++) { 3290 for (i=0; i<n; i++) {
3277 PyObject* indexObject = PyTuple_GET_ITEM(indices, i); 3291 PyObject* indexObject = PyTuple_GET_ITEM(indices, i);
3278 Py_ssize_t index = PyLong_AsSsize_t(indexObject); 3292 Py_ssize_t index = PyLong_AsSsize_t(indexObject);
(...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 if (PyType_Ready(typelist[i]) < 0) 4653 if (PyType_Ready(typelist[i]) < 0)
4640 return NULL; 4654 return NULL;
4641 name = strchr(typelist[i]->tp_name, '.'); 4655 name = strchr(typelist[i]->tp_name, '.');
4642 assert (name != NULL); 4656 assert (name != NULL);
4643 Py_INCREF(typelist[i]); 4657 Py_INCREF(typelist[i]);
4644 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]); 4658 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]);
4645 } 4659 }
4646 4660
4647 return m; 4661 return m;
4648 } 4662 }
OLDNEW

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