[pywin32-checkins] pywin32/win32/src PyWinObjects.h,1.8,1.9 win32file.i,1.46,1.47
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2005-06-02 00:03:55
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15608/src Modified Files: PyWinObjects.h win32file.i Log Message: Fix a bug regarding reference counting and OVERLAPPED objects, as reported on python-win32. Also borrowed the repro for the test suite. Index: PyWinObjects.h =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinObjects.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyWinObjects.h 10 Sep 2004 03:40:21 -0000 1.8 --- PyWinObjects.h 2 Jun 2005 00:03:33 -0000 1.9 *************** *** 135,139 **** PyObject *obState; DWORD dwValue; ! sMyOverlapped() {obState=NULL;dwValue=0;} sMyOverlapped(const OVERLAPPED &o) : OVERLAPPED(o) {obState=NULL;dwValue=0;} }; --- 135,142 ---- PyObject *obState; DWORD dwValue; ! // set to TRUE when we bump the reference count to keep the object ! // alive while it is sitting in a completion port. ! BOOL isArtificialReference; ! sMyOverlapped() {obState=NULL;dwValue=0;isArtificialReference=0;} sMyOverlapped(const OVERLAPPED &o) : OVERLAPPED(o) {obState=NULL;dwValue=0;} }; Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** win32file.i 12 Apr 2005 02:56:44 -0000 1.46 --- win32file.i 2 Jun 2005 00:03:33 -0000 1.47 *************** *** 1234,1238 **** size_t off = offsetof(PyOVERLAPPED, m_overlapped); PyOVERLAPPED *po = (PyOVERLAPPED *)(((LPBYTE)p) - off); ! // consume reference added when it was posted. return po; } --- 1234,1250 ---- size_t off = offsetof(PyOVERLAPPED, m_overlapped); PyOVERLAPPED *po = (PyOVERLAPPED *)(((LPBYTE)p) - off); ! // Hope like hell it hasn't already died on us (PostQueuedCompletionStatus ! // makes it impossible it has died, but other functions do not as they ! // don't know if the OVERLAPPED will end up in a IOCP) ! if (po->ob_refcnt<=0) { ! PyErr_SetString(PyExc_RuntimeError, "This overlapped object has lost all its references so was destroyed"); ! return NULL; ! } ! // consume reference added when it was posted, if added. ! if (po->m_overlapped.isArtificialReference) ! po->m_overlapped.isArtificialReference = FALSE; ! else ! // Overlapped we didn't actually queue so no artificial refcount ! Py_INCREF(po); return po; } *************** *** 1251,1256 **** return FALSE; PyOVERLAPPED::sMyOverlapped *pMyOverlapped = (PyOVERLAPPED::sMyOverlapped *)po; ! // Add a fake reference so the object lives while in the queue. Py_INCREF(ob); *ppOverlapped = po->GetOverlapped(); return TRUE; --- 1263,1269 ---- return FALSE; PyOVERLAPPED::sMyOverlapped *pMyOverlapped = (PyOVERLAPPED::sMyOverlapped *)po; ! // Add a fake reference so the object lives while in the queue, and add the flag Py_INCREF(ob); + pMyOverlapped->isArtificialReference = TRUE; *ppOverlapped = po->GetOverlapped(); return TRUE; |