[pywin32-checkins] pywin32/com/win32com/src PyRecord.cpp,1.8,1.9 oleargs.cpp,1.21,1.22
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-20 05:19:53
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src In directory sc8-pr-cvs1:/tmp/cvs-serv19875 Modified Files: PyRecord.cpp oleargs.cpp Log Message: Get record objects working with copy/pickle again. Index: PyRecord.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyRecord.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyRecord.cpp 10 Jan 2003 02:42:46 -0000 1.8 --- PyRecord.cpp 20 Oct 2003 04:48:26 -0000 1.9 *************** *** 179,188 **** } // Creates a new Record by TAKING A COPY of the passed record. ! PyObject *PyObject_FromRecordInfo(IRecordInfo *ri, void *data) { ULONG cb; HRESULT hr = ri->GetSize(&cb); if (FAILED(hr)) return PyCom_BuildPyException(hr, ri, g_IID_IRecordInfo); PyRecordBuffer *owner = new PyRecordBuffer(cb); if (PyErr_Occurred()) { // must be mem error! --- 179,192 ---- } // Creates a new Record by TAKING A COPY of the passed record. ! PyObject *PyObject_FromRecordInfo(IRecordInfo *ri, void *data, ULONG cbData) { + if ((data != NULL && cbData==0) || (data==NULL && cbData != 0)) + return PyErr_Format(PyExc_RuntimeError, "Both or neither data and size must be given"); ULONG cb; HRESULT hr = ri->GetSize(&cb); if (FAILED(hr)) return PyCom_BuildPyException(hr, ri, g_IID_IRecordInfo); + if (cbData != 0 && cbData != cb) + return PyErr_Format(PyExc_ValueError, "Expecting a string of %d bytes (got %d)", cb, cbData); PyRecordBuffer *owner = new PyRecordBuffer(cb); if (PyErr_Occurred()) { // must be mem error! *************** *** 206,217 **** PyObject *pythoncom_GetRecordFromGuids(PyObject *self, PyObject *args) { PyObject *obGuid, *obInfoGuid; int maj, min, lcid; ! if (!PyArg_ParseTuple(args, "OiiiO:GetRecordFromGuids", &obGuid, // @pyparm <o PyIID>|iid||The GUID of the type library &maj, // @pyparm int|verMajor||The major version number of the type lib. &min, // @pyparm int|verMinor||The minor version number of the type lib. &lcid, // @pyparm int|lcid||The LCID of the type lib. ! &obInfoGuid)) // @pyparm <o PyIID>|infoIID||The GUID of the record info in the library return NULL; GUID guid, infoGuid; --- 210,224 ---- PyObject *pythoncom_GetRecordFromGuids(PyObject *self, PyObject *args) { + char *data = NULL; PyObject *obGuid, *obInfoGuid; int maj, min, lcid; ! int cb = 0; ! if (!PyArg_ParseTuple(args, "OiiiO|z#:GetRecordFromGuids", &obGuid, // @pyparm <o PyIID>|iid||The GUID of the type library &maj, // @pyparm int|verMajor||The major version number of the type lib. &min, // @pyparm int|verMinor||The minor version number of the type lib. &lcid, // @pyparm int|lcid||The LCID of the type lib. ! &obInfoGuid, // @pyparm <o PyIID>|infoIID||The GUID of the record info in the library ! &data, &cb)) // @pyparm string|data|None|The raw data to initialize the record with. return NULL; GUID guid, infoGuid; *************** *** 224,228 **** if (FAILED(hr)) return PyCom_BuildPyException(hr); ! PyObject *ret = PyObject_FromRecordInfo(i, NULL); i->Release(); return ret; --- 231,235 ---- if (FAILED(hr)) return PyCom_BuildPyException(hr); ! PyObject *ret = PyObject_FromRecordInfo(i, data, cb); i->Release(); return ret; *************** *** 268,277 **** }; ! static PyObject *PyRecord_copy(PyObject *self, PyObject *args) { ! if (!PyArg_ParseTuple(args, ":copy")) ! return NULL; PyRecord *pyrec = (PyRecord *)self; ! return PyObject_FromRecordInfo(pyrec->pri, pyrec->pdata); } // The object itself. --- 275,339 ---- }; ! static PyObject *PyRecord_reduce(PyObject *self, PyObject *args) { ! PyObject *ret = NULL; PyRecord *pyrec = (PyRecord *)self; ! PyObject *obModule = NULL, *obModDict = NULL, *obFunc = NULL; ! ITypeInfo *pti = NULL; ! TYPEATTR *pta = NULL; ! ULONG cb; ! HRESULT hr; ! GUID structguid; ! if (!PyArg_ParseTuple(args, ":reduce")) ! return NULL; ! hr = pyrec->pri->GetTypeInfo(&pti); ! if (FAILED(hr)||pti==NULL) { ! PyCom_BuildPyException(hr); ! goto done; ! } ! hr = pti->GetTypeAttr(&pta); ! if (FAILED(hr)||pta==NULL) { ! PyCom_BuildPyException(hr); ! goto done; ! } ! hr = pyrec->pri->GetGuid(&structguid); ! if (FAILED(hr)) { ! PyCom_BuildPyException(hr); ! goto done; ! } ! hr = pyrec->pri->GetSize(&cb); ! if (FAILED(hr)) { ! PyCom_BuildPyException(hr); ! goto done; ! } ! obModule = PyImport_ImportModule("pythoncom"); ! if (obModule) ! obModDict = PyModule_GetDict(obModule); // no ref added! ! if (obModDict) ! obFunc = PyDict_GetItemString(obModDict, "GetRecordFromGuids"); // no ref added! ! if (!obFunc) { ! PyErr_Clear(); ! PyErr_SetString(PyExc_RuntimeError, "pythoncom.GetRecordFromGuids() can't be located!"); ! goto done; ! } ! { // scope for locals avoiding goto ! PyObject *obtlbguid = PyWinObject_FromIID(pta->guid); ! PyObject *obstructguid = PyWinObject_FromIID(structguid); ! ret = Py_BuildValue("O(NiiiNs#)", ! obFunc, ! obtlbguid, ! pta->wMajorVerNum, ! pta->wMinorVerNum, ! pta->lcid, ! obstructguid, ! pyrec->pdata, cb); ! } // end scope ! done: ! if (pta&& pti) ! pti->ReleaseTypeAttr(pta); ! if (pti) pti->Release(); ! Py_XDECREF(obModule); ! // obModDict and obFunc have no new reference. ! return ret; } // The object itself. *************** *** 279,283 **** // structure names! static struct PyMethodDef PyRecord_methods[] = { ! {"__copy__", PyRecord_copy, 1}, // This allows the copy module to work! {NULL} }; --- 341,345 ---- // structure names! static struct PyMethodDef PyRecord_methods[] = { ! {"__reduce__", PyRecord_reduce, 1}, // This allows the copy module to work! {NULL} }; Index: oleargs.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/oleargs.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** oleargs.cpp 2 Jul 2003 03:42:27 -0000 1.21 --- oleargs.cpp 20 Oct 2003 04:48:26 -0000 1.22 *************** *** 7,11 **** extern void PyCom_LogF(const TCHAR *fmt, ...); ! extern PyObject *PyObject_FromRecordInfo(IRecordInfo *, void *); extern PyObject *PyObject_FromSAFEARRAYRecordInfo(SAFEARRAY *psa); extern BOOL PyObject_AsVARIANTRecordInfo(PyObject *ob, VARIANT *pv); --- 7,11 ---- extern void PyCom_LogF(const TCHAR *fmt, ...); ! extern PyObject *PyObject_FromRecordInfo(IRecordInfo *, void *, ULONG); extern PyObject *PyObject_FromSAFEARRAYRecordInfo(SAFEARRAY *psa); extern BOOL PyObject_AsVARIANTRecordInfo(PyObject *ob, VARIANT *pv); *************** *** 332,336 **** case VT_RECORD: ! result = PyObject_FromRecordInfo(V_RECORDINFO(&varValue), V_RECORD(&varValue)); break; default: --- 332,340 ---- case VT_RECORD: ! { ! ULONG cb; ! V_RECORDINFO(&varValue)->GetSize(&cb); ! result = PyObject_FromRecordInfo(V_RECORDINFO(&varValue), V_RECORD(&varValue), cb); ! } break; default: |