@@ -133,14 +133,19 @@ static PyObject * execute_soft_switchable_func(PyFrameObject *, int, PyObject *)
133133SLP_DEF_INVALID_EXEC (execute_soft_switchable_func )
134134
135135static PyObject *
136- cframe_reduce (PyCFrameObject * cf )
136+ cframe_reduce (PyCFrameObject * cf , PyObject * value )
137137{
138138 PyObject * res = NULL , * exec_name = NULL ;
139139 PyObject * params = NULL ;
140140 int valid = 1 ;
141141 PyObject * obs [3 ];
142142 long i , n ;
143143
144+ if (value && !PyLong_Check (value )) {
145+ PyErr_SetString (PyExc_TypeError , "__reduce_ex__ argument should be an integer" );
146+ return NULL ;
147+ }
148+
144149 if (cf -> f_execute == execute_soft_switchable_func ) {
145150 exec_name = (PyObject * ) cf -> any2 ;
146151 assert (cf -> any2 );
@@ -240,7 +245,7 @@ cframe_setstate(PyObject *self, PyObject *args)
240245
241246static PyMethodDef cframe_methods [] = {
242247 {"__reduce__" , (PyCFunction )cframe_reduce , METH_NOARGS , NULL },
243- {"__reduce_ex__" , (PyCFunction )cframe_reduce , METH_VARARGS , NULL },
248+ {"__reduce_ex__" , (PyCFunction )cframe_reduce , METH_O , NULL },
244249 {"__setstate__" , (PyCFunction )cframe_setstate , METH_O , NULL },
245250 {NULL , NULL }
246251};
@@ -386,8 +391,13 @@ slp_cframe_fini(void)
386391 */
387392
388393static PyObject *
389- function_declaration_reduce (PyStacklessFunctionDeclarationObject * self )
394+ function_declaration_reduce (PyStacklessFunctionDeclarationObject * self , PyObject * value )
390395{
396+ if (value && !PyLong_Check (value )) {
397+ PyErr_SetString (PyExc_TypeError , "__reduce_ex__ argument should be an integer" );
398+ return NULL ;
399+ }
400+
391401 if (self -> name == NULL || * self -> name == '\0' ) {
392402 PyErr_SetString (PyExc_SystemError , "no function name" );
393403 return NULL ;
@@ -397,7 +407,7 @@ function_declaration_reduce(PyStacklessFunctionDeclarationObject *self)
397407
398408static PyMethodDef function_declaration_methods [] = {
399409 {"__reduce__" , (PyCFunction )function_declaration_reduce , METH_NOARGS , NULL },
400- {"__reduce_ex__" , (PyCFunction )function_declaration_reduce , METH_VARARGS , NULL },
410+ {"__reduce_ex__" , (PyCFunction )function_declaration_reduce , METH_O , NULL },
401411 {NULL , NULL }
402412};
403413
0 commit comments