@@ -3184,23 +3184,37 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
31843184{
31853185 char * name ;
31863186 int (* address )(void );
3187+ PyObject * ftuple ;
31873188 PyObject * dll ;
31883189 PyObject * obj ;
31893190 PyCFuncPtrObject * self ;
31903191 void * handle ;
31913192 PyObject * paramflags = NULL ;
31923193
3193- if (!PyArg_ParseTuple (args , "(O&O) |O" , _get_name , & name , & dll , & paramflags ))
3194+ if (!PyArg_ParseTuple (args , "O |O" , & ftuple , & paramflags ))
31943195 return NULL ;
31953196 if (paramflags == Py_None )
31963197 paramflags = NULL ;
31973198
3199+ ftuple = PySequence_Tuple (ftuple );
3200+ if (!ftuple )
3201+ /* Here ftuple is a borrowed reference */
3202+ return NULL ;
3203+
3204+ if (!PyArg_ParseTuple (ftuple , "O&O" , _get_name , & name , & dll )) {
3205+ Py_DECREF (ftuple );
3206+ return NULL ;
3207+ }
3208+
31983209 obj = PyObject_GetAttrString (dll , "_handle" );
3199- if (!obj )
3210+ if (!obj ) {
3211+ Py_DECREF (ftuple );
32003212 return NULL ;
3213+ }
32013214 if (!PyLong_Check (obj )) {
32023215 PyErr_SetString (PyExc_TypeError ,
32033216 "the _handle attribute of the second argument must be an integer" );
3217+ Py_DECREF (ftuple );
32043218 Py_DECREF (obj );
32053219 return NULL ;
32063220 }
@@ -3209,6 +3223,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32093223 if (PyErr_Occurred ()) {
32103224 PyErr_SetString (PyExc_ValueError ,
32113225 "could not convert the _handle attribute to a pointer" );
3226+ Py_DECREF (ftuple );
32123227 return NULL ;
32133228 }
32143229
@@ -3223,6 +3238,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32233238 PyErr_Format (PyExc_AttributeError ,
32243239 "function ordinal %d not found" ,
32253240 (WORD )(size_t )name );
3241+ Py_DECREF (ftuple );
32263242 return NULL ;
32273243 }
32283244#else
@@ -3236,9 +3252,12 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32363252#else
32373253 PyErr_SetString (PyExc_AttributeError , ctypes_dlerror ());
32383254#endif
3255+ Py_DECREF (ftuple );
32393256 return NULL ;
32403257 }
32413258#endif
3259+ Py_INCREF (dll ); /* for KeepRef */
3260+ Py_DECREF (ftuple );
32423261 if (!_validate_paramflags (type , paramflags ))
32433262 return NULL ;
32443263
@@ -3251,7 +3270,6 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
32513270
32523271 * (void * * )self -> b_ptr = address ;
32533272
3254- Py_INCREF ((PyObject * )dll ); /* for KeepRef */
32553273 if (-1 == KeepRef ((CDataObject * )self , 0 , dll )) {
32563274 Py_DECREF ((PyObject * )self );
32573275 return NULL ;
0 commit comments