@@ -147,8 +147,13 @@ static PyObject *
147147groupby_setstate (groupbyobject * lz , PyObject * state )
148148{
149149 PyObject * currkey , * currvalue , * tgtkey ;
150- if (!PyArg_ParseTuple (state , "OOO" , & currkey , & currvalue , & tgtkey ))
150+ if (!PyTuple_Check (state )) {
151+ PyErr_SetString (PyExc_TypeError , "state is not a tuple" );
151152 return NULL ;
153+ }
154+ if (!PyArg_ParseTuple (state , "OOO" , & currkey , & currvalue , & tgtkey )) {
155+ return NULL ;
156+ }
152157 Py_INCREF (currkey );
153158 Py_XSETREF (lz -> currkey , currkey );
154159 Py_INCREF (currvalue );
@@ -727,8 +732,13 @@ tee_setstate(teeobject *to, PyObject *state)
727732{
728733 teedataobject * tdo ;
729734 int index ;
730- if (!PyArg_ParseTuple (state , "O!i" , & teedataobject_type , & tdo , & index ))
735+ if (!PyTuple_Check (state )) {
736+ PyErr_SetString (PyExc_TypeError , "state is not a tuple" );
737+ return NULL ;
738+ }
739+ if (!PyArg_ParseTuple (state , "O!i" , & teedataobject_type , & tdo , & index )) {
731740 return NULL ;
741+ }
732742 if (index < 0 || index > LINKCELLS ) {
733743 PyErr_SetString (PyExc_ValueError , "Index out of range" );
734744 return NULL ;
@@ -971,9 +981,13 @@ cycle_setstate(cycleobject *lz, PyObject *state)
971981{
972982 PyObject * saved = NULL ;
973983 int firstpass ;
974-
975- if (!PyArg_ParseTuple (state , "O!i" , & PyList_Type , & saved , & firstpass ))
984+ if (!PyTuple_Check (state )) {
985+ PyErr_SetString (PyExc_TypeError , "state is not a tuple" );
986+ return NULL ;
987+ }
988+ if (!PyArg_ParseTuple (state , "O!i" , & PyList_Type , & saved , & firstpass )) {
976989 return NULL ;
990+ }
977991 Py_INCREF (saved );
978992 Py_XSETREF (lz -> saved , saved );
979993 lz -> firstpass = firstpass != 0 ;
@@ -1903,8 +1917,17 @@ chain_setstate(chainobject *lz, PyObject *state)
19031917{
19041918 PyObject * source , * active = NULL ;
19051919
1906- if (! PyArg_ParseTuple (state , "O|O" , & source , & active ))
1920+ if (!PyTuple_Check (state )) {
1921+ PyErr_SetString (PyExc_TypeError , "state is not a tuple" );
1922+ return NULL ;
1923+ }
1924+ if (!PyArg_ParseTuple (state , "O|O" , & source , & active )) {
1925+ return NULL ;
1926+ }
1927+ if (!PyIter_Check (source ) || (active != NULL && !PyIter_Check (active ))) {
1928+ PyErr_SetString (PyExc_TypeError , "Arguments must be iterators." );
19071929 return NULL ;
1930+ }
19081931
19091932 Py_INCREF (source );
19101933 Py_XSETREF (lz -> source , source );
@@ -3262,10 +3285,15 @@ permutations_setstate(permutationsobject *po, PyObject *state)
32623285 PyObject * indices , * cycles , * result ;
32633286 Py_ssize_t n , i ;
32643287
3288+ if (!PyTuple_Check (state )) {
3289+ PyErr_SetString (PyExc_TypeError , "state is not a tuple" );
3290+ return NULL ;
3291+ }
32653292 if (!PyArg_ParseTuple (state , "O!O!" ,
32663293 & PyTuple_Type , & indices ,
3267- & PyTuple_Type , & cycles ))
3294+ & PyTuple_Type , & cycles )) {
32683295 return NULL ;
3296+ }
32693297
32703298 n = PyTuple_GET_SIZE (po -> pool );
32713299 if (PyTuple_GET_SIZE (indices ) != n || PyTuple_GET_SIZE (cycles ) != po -> r ) {
0 commit comments