[pywin32-checkins] pywin32/win32/src win32file.i,1.93,1.94
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-11-26 01:05:47
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12568 Modified Files: win32file.i Log Message: Prevent EncrytptedFile CObject destructor crashing on Vistax64. Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** win32file.i 30 Jun 2008 12:53:37 -0000 1.93 --- win32file.i 26 Nov 2008 01:05:36 -0000 1.94 *************** *** 44,47 **** --- 44,64 ---- %include "pywin32.i" + %{ + // older python version's don't get the PyCObject structure definition + // exposed, and we need it to cleanly zap our handles (see + // CloseEncryptedFileRaw below). + // Fortunately, the PyCObject structure has been identical from versions + // 2.3->2.6 - and 2.6 is where it is first made public. + #if (PY_VERSION_HEX < 0x02060000) + typedef struct { + PyObject_HEAD + void *cobject; + void *desc; + void (*destructor)(void *); + } PyCObject; + + #endif + %} + #define FILE_GENERIC_READ FILE_GENERIC_READ #define FILE_GENERIC_WRITE FILE_GENERIC_WRITE *************** *** 3875,3879 **** void encryptedfilecontextdestructor(void *ctxt){ ! if (pfnCloseEncryptedFileRaw) (*pfnCloseEncryptedFileRaw)(ctxt); } --- 3892,3896 ---- void encryptedfilecontextdestructor(void *ctxt){ ! if (pfnCloseEncryptedFileRaw && ctxt) (*pfnCloseEncryptedFileRaw)(ctxt); } *************** *** 4068,4080 **** CHECK_PFN(CloseEncryptedFileRaw); PyObject *obctxt; - PVOID ctxt; if (!PyArg_ParseTuple(args, "O:CloseEncryptedFileRaw", &obctxt)) // @pyparm PyCObject|Context||Context object returned from <om win32file.OpenEncryptedFileRaw> return NULL; ! ctxt=PyCObject_AsVoidPtr(obctxt); ! if (ctxt==NULL) ! return NULL; // function has no return value, make sure to check for memory leaks! ! (*pfnCloseEncryptedFileRaw)(ctxt); Py_INCREF(Py_None); return Py_None; --- 4085,4106 ---- CHECK_PFN(CloseEncryptedFileRaw); PyObject *obctxt; if (!PyArg_ParseTuple(args, "O:CloseEncryptedFileRaw", &obctxt)) // @pyparm PyCObject|Context||Context object returned from <om win32file.OpenEncryptedFileRaw> return NULL; ! // We must nuke our ctxt in the CObject afer closing, else when the ! // object destructs and we attempt to close it a second time, Vista x64 ! // crashes. ! // So must bypass the CObject API for this. ! if (!PyCObject_Check(obctxt)) ! return PyErr_Format(PyExc_TypeError, "param must be handle to an encrypted file (got type %s)", obctxt->ob_type->tp_name); ! PyCObject *pcobj = (PyCObject *)obctxt; ! if (pcobj->destructor != encryptedfilecontextdestructor) ! return PyErr_Format(PyExc_TypeError, "param must be handle to an encrypted file (got a CObject with invalid destructor)"); ! if (!pcobj->cobject) ! return PyErr_Format(PyExc_ValueError, "This handle has already been closed"); ! // ok - close it, then nuke it. // function has no return value, make sure to check for memory leaks! ! (*pfnCloseEncryptedFileRaw)(pcobj->cobject); ! pcobj->cobject = 0; Py_INCREF(Py_None); return Py_None; |