[pywin32-checkins] pywin32/win32/src win32file.i,1.110,1.111
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2010-10-26 05:42:47
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv14335 Modified Files: win32file.i Log Message: Use PyBuffer_FillInfo to create Py_buffer struct (layout changed since 3.0) New Capsule API in 3.2 replaces PyCObject functions Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** win32file.i 27 Aug 2010 06:47:53 -0000 1.110 --- win32file.i 26 Oct 2010 05:42:39 -0000 1.111 *************** *** 356,373 **** // theoretically this could be in pywintypes, but this is the only place // it is called... static PyObject *PyBuffer_FromReadWriteMemory(void *buf, Py_ssize_t size){ ! Py_buffer info={ ! buf, ! NULL, // obj added in 3.0b3 ! size, ! FALSE, // readonly ! 0, // ndim ! NULL, // format ! NULL, // shape ! NULL, // strides ! NULL, // suboffsets ! 0, // itemsize ! NULL, // internal ! }; return PyMemoryView_FromBuffer(&info); } --- 356,370 ---- // theoretically this could be in pywintypes, but this is the only place // it is called... + static PyObject *PyBuffer_FromReadWriteMemory(void *buf, Py_ssize_t size){ ! Py_buffer info; ! /* PyBUF_CONTIG contains PyBUF_ND, so that Py_buffer.shape is filled in. ! Apparently the shape is now required for even simple contiguous byte ! buffers. (see get_shape0 in memoryobject.c) ! Since PyBuffer_FillInfo is specifically for this case, it should probably ! set the shape unconditionally. ! */ ! if (PyBuffer_FillInfo(&info, NULL, buf, size, 0, PyBUF_CONTIG) == -1) ! return NULL; return PyMemoryView_FromBuffer(&info); } *************** *** 1017,1021 **** PyObject *obWriteData; PyObject *obOverlapped = NULL; - PyBufferProcs *pb = NULL; if (!PyArg_ParseTuple(args, "OO|O:WriteFile", --- 1014,1017 ---- *************** *** 1935,1939 **** WSAPROTOCOL_INFO wsProtInfo; UINT cbSize = sizeof(wsProtInfo); - PyBufferProcs *pb = NULL; if (!PyArg_ParseTuple( --- 1931,1934 ---- *************** *** 2128,2132 **** int rc; DWORD dwBufSize; - PyBufferProcs *pb = NULL; if (!PyArg_ParseTuple( --- 2123,2126 ---- *************** *** 2410,2414 **** PyObject *obOverlapped = NULL; DWORD dwFlags = 0; - PyBufferProcs *pb = NULL; if (!PyArg_ParseTuple( --- 2404,2407 ---- *************** *** 2506,2510 **** PyObject *obOverlapped = NULL; DWORD dwFlags = 0; - PyBufferProcs *pb = NULL; if (!PyArg_ParseTuple( --- 2499,2502 ---- *************** *** 4228,4235 **** --- 4220,4243 ---- } + #if PY_VERSION_HEX > 0x03010000 + // Capsule API replaced PyCObject in 3.2. + void encryptedfilecontextdestructor(PyObject *obctxt){ + if (!PyCapsule_IsValid(obctxt, NULL)) + return; // should not happen, but maybe print a warning just in case ? + // Check if context has already been explicitely destroyed + // The capsule's context is set to this value in CloseEncryptedFileRaw + if (PyCapsule_GetContext(obctxt) == INVALID_HANDLE_VALUE) + return; + void *ctxt = PyCapsule_GetPointer(obctxt, NULL); + if (pfnCloseEncryptedFileRaw) + (*pfnCloseEncryptedFileRaw)(ctxt); + } + #else void encryptedfilecontextdestructor(void *ctxt){ if (pfnCloseEncryptedFileRaw && ctxt) (*pfnCloseEncryptedFileRaw)(ctxt); } + #endif + // @pyswig PyCObject|OpenEncryptedFileRaw|Initiates a backup or restore operation on an encrypted file *************** *** 4259,4263 **** --- 4267,4275 ---- PyWin_SetAPIError("OpenEncryptedFileRaw", err); else{ + #if PY_VERSION_HEX > 0x03010000 + ret=PyCapsule_New(ctxt, NULL, encryptedfilecontextdestructor); + #else ret=PyCObject_FromVoidPtr(ctxt, encryptedfilecontextdestructor); + #endif if (ret==NULL) (*pfnCloseEncryptedFileRaw)(ctxt); *************** *** 4315,4319 **** --- 4327,4335 ---- &obctxt)) // @pyparm PyCObject|Context||Context object returned from <om win32file.OpenEncryptedFileRaw> return NULL; + #if PY_VERSION_HEX > 0x03010000 + ctxt=PyCapsule_GetPointer(obctxt, NULL); + #else ctxt=PyCObject_AsVoidPtr(obctxt); + #endif if (ctxt==NULL) return NULL; *************** *** 4392,4396 **** --- 4408,4416 ---- &obctxt)) // @pyparm PyCObject|Context||Context object returned from <om win32file.OpenEncryptedFileRaw> return NULL; + #if PY_VERSION_HEX > 0x03010000 + ctxt=PyCapsule_GetPointer(obctxt, NULL); + #else ctxt=PyCObject_AsVoidPtr(obctxt); + #endif if (ctxt==NULL) return NULL; *************** *** 4429,4432 **** --- 4449,4467 ---- // crashes. // So must bypass the CObject API for this. + #if PY_VERSION_HEX > 0x03010000 + if (!PyCapsule_IsValid(obctxt, NULL)) + return PyErr_Format(PyExc_TypeError, "param must be handle to an encrypted file (got type %s)", obctxt->ob_type->tp_name); + if (PyCapsule_GetDestructor(obctxt) != encryptedfilecontextdestructor) + return PyErr_Format(PyExc_TypeError, "param must be handle to an encrypted file (got a CObject with invalid destructor)"); + /* PyCapsule will *not* allow you to set the pointer to NULL, so use its extra context pointer + to signal that we have already destroyed our context. + ??? Maybe just set the pointer itself to INVALID_HANDLE_VALUE ??? + */ + if (PyCapsule_GetContext(obctxt) == INVALID_HANDLE_VALUE) + return PyErr_Format(PyExc_ValueError, "This handle has already been closed"); + void *ctxt = PyCapsule_GetPointer(obctxt, NULL); + (*pfnCloseEncryptedFileRaw)(ctxt); + PyCapsule_SetContext(obctxt, INVALID_HANDLE_VALUE); + #else 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); *************** *** 4440,4443 **** --- 4475,4479 ---- (*pfnCloseEncryptedFileRaw)(pcobj->cobject); pcobj->cobject = 0; + #endif Py_INCREF(Py_None); return Py_None; |