@@ -3188,23 +3188,37 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
31883188{
31893189 char * name ;
31903190 int (* address )(void );
3191+ PyObject * ftuple ;
31913192 PyObject * dll ;
31923193 PyObject * obj ;
31933194 PyCFuncPtrObject * self ;
31943195 void * handle ;
31953196 PyObject * paramflags = NULL ;
31963197
3197- if (!PyArg_ParseTuple (args , "(O&O) |O" , _get_name , & name , & dll , & paramflags ))
3198+ if (!PyArg_ParseTuple (args , "O |O" , & ftuple , & paramflags ))
31983199 return NULL ;
31993200 if (paramflags == Py_None )
32003201 paramflags = NULL ;
32013202
3203+ ftuple = PySequence_Tuple (ftuple );
3204+ if (!ftuple )
3205+ /* Here ftuple is a borrowed reference */
3206+ return NULL ;
3207+
3208+ if (!PyArg_ParseTuple (ftuple , "O&O" , _get_name , & name , & dll )) {
3209+ Py_DECREF (ftuple );
3210+ return NULL ;
3211+ }
3212+
32023213 obj = PyObject_GetAttrString (dll , "_handle" );
3203- if (!obj )
3214+ if (!obj ) {
3215+ Py_DECREF (ftuple );
32043216 return NULL ;
3217+ }
32053218 if (!PyLong_Check (obj )) {
32063219 PyErr_SetString (PyExc_TypeError ,
32073220 "the _handle attribute of the second argument must be an integer" );
3221+ Py_DECREF (ftuple );
32083222 Py_DECREF (obj );
32093223 return NULL ;
32103224 }
@@ -3213,6 +3227,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32133227 if (PyErr_Occurred ()) {
32143228 PyErr_SetString (PyExc_ValueError ,
32153229 "could not convert the _handle attribute to a pointer" );
3230+ Py_DECREF (ftuple );
32163231 return NULL ;
32173232 }
32183233
@@ -3227,6 +3242,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32273242 PyErr_Format (PyExc_AttributeError ,
32283243 "function ordinal %d not found" ,
32293244 (WORD )(size_t )name );
3245+ Py_DECREF (ftuple );
32303246 return NULL ;
32313247 }
32323248#else
@@ -3240,9 +3256,12 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32403256#else
32413257 PyErr_SetString (PyExc_AttributeError , ctypes_dlerror ());
32423258#endif
3259+ Py_DECREF (ftuple );
32433260 return NULL ;
32443261 }
32453262#endif
3263+ Py_INCREF (dll ); /* for KeepRef */
3264+ Py_DECREF (ftuple );
32463265 if (!_validate_paramflags (type , paramflags ))
32473266 return NULL ;
32483267
@@ -3255,7 +3274,6 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32553274
32563275 * (void * * )self -> b_ptr = address ;
32573276
3258- Py_INCREF ((PyObject * )dll ); /* for KeepRef */
32593277 if (-1 == KeepRef ((CDataObject * )self , 0 , dll )) {
32603278 Py_DECREF ((PyObject * )self );
32613279 return NULL ;
0 commit comments