Update of /cvsroot/ctypes/ctypes/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2755
Modified Files:
Tag: branch_1_0
callbacks.c
Log Message:
Discovered and hacked around a problem with callback functions.
If the callback function has a return type other than void, py_object,
or an integral C type, it is impossible to either avoid a memory leak
or return a possibly invalid result. Previously, the possibly invalid
result has been returned, now the memory leak will appear but a
"RuntimeWarning: memory leak in callback function" will be emitted.
Index: callbacks.c
===================================================================
RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v
retrieving revision 1.71.2.8
retrieving revision 1.71.2.9
diff -C2 -d -r1.71.2.8 -r1.71.2.9
*** callbacks.c 2 Jan 2006 19:02:52 -0000 1.71.2.8
--- callbacks.c 22 Feb 2006 21:06:01 -0000 1.71.2.9
***************
*** 239,246 ****
break;
}
! /* assert (keep == Py_None); */
! /* XXX We have no way to keep the needed reference XXX */
! /* Should we emit a warning? */
! Py_XDECREF(keep);
}
Py_XDECREF(result);
--- 239,257 ----
break;
}
! /* keep is an object we have to keep alive so that the result
! stays valid. If there is no such object, the setfunc will
! have returned Py_None.
!
! If there is such an object, we have no choice than to keep
! it alive forever - but a refcount and/or memory leak will
! be the result. EXCEPT when restype is py_object - Python
! itself knows how to manage the refcount of these objects.
! */
! if (keep == NULL) /* Could not convert callback result. */
! PyErr_WriteUnraisable(Py_None);
! else if (keep == Py_None) /* Nothing to keep */
! Py_DECREF(keep);
! else if (setfunc != getentry("O")->setfunc)
! PyErr_Warn(PyExc_RuntimeWarning, "memory leak in callback function.");
}
Py_XDECREF(result);
|