@@ -1963,21 +1963,13 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
19631963 PyObject * state = NULL ;
19641964 PyObject * listitems = Py_None ;
19651965 PyObject * dictitems = Py_None ;
1966- Py_ssize_t size ;
19671966
19681967 int use_newobj = self -> proto >= 2 ;
19691968
19701969 const char reduce_op = REDUCE ;
19711970 const char build_op = BUILD ;
19721971 const char newobj_op = NEWOBJ ;
19731972
1974- size = PyTuple_Size (args );
1975- if (size < 2 || size > 5 ) {
1976- PyErr_SetString (PicklingError , "tuple returned by "
1977- "__reduce__ must contain 2 through 5 elements" );
1978- return -1 ;
1979- }
1980-
19811973 if (!PyArg_UnpackTuple (args , "save_reduce" , 2 , 5 ,
19821974 & callable , & argtup , & state , & listitems , & dictitems ))
19831975 return -1 ;
@@ -2154,6 +2146,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
21542146 PyObject * reduce_value = NULL ;
21552147 PyObject * memo_key = NULL ;
21562148 int status = 0 ;
2149+ Py_ssize_t size ;
21572150
21582151 if (Py_EnterRecursiveCall (" while pickling an object" ) < 0 )
21592152 return -1 ;
@@ -2332,6 +2325,13 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
23322325 goto error ;
23332326 }
23342327
2328+ size = PyTuple_Size (reduce_value );
2329+ if (size < 2 || size > 5 ) {
2330+ PyErr_SetString (PicklingError , "tuple returned by "
2331+ "__reduce__ must contain 2 through 5 elements" );
2332+ goto error ;
2333+ }
2334+
23352335 status = save_reduce (self , reduce_value , obj );
23362336
23372337 if (0 ) {
0 commit comments