[pywin32-checkins] pywin32/win32/src PyIID.cpp,1.6,1.7
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2004-05-26 08:31:54
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5740 Modified Files: PyIID.cpp Log Message: Allow IIDs to be created from raw bytes, and supply a buffer interface so the GUID raw bytes are available. Index: PyIID.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/PyIID.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyIID.cpp 7 Nov 2003 03:58:17 -0000 1.6 --- PyIID.cpp 26 May 2004 08:31:44 -0000 1.7 *************** *** 16,21 **** // @pyparm string/Unicode|iidString||A string representation of an IID, or a ProgID. ! if ( !PyArg_ParseTuple(args, "O", &obIID) ) return NULL; // Already an IID? Return self. if ( PyIID_Check(obIID) ) { --- 16,37 ---- // @pyparm string/Unicode|iidString||A string representation of an IID, or a ProgID. ! // @pyparm bool|is_bytes|False|Indicates if the first param is actually the bytes of an IID structure. ! int isBytes = FALSE; ! if ( !PyArg_ParseTuple(args, "O|i", &obIID, &isBytes) ) return NULL; + if (isBytes) { + const void *buf; + int cb; + if (!PyObject_CheckReadBuffer(obIID)) + return PyErr_Format(PyExc_TypeError, "object must be a read-buffer to read the CLSID bytes"); + if (PyObject_AsReadBuffer(obIID, &buf, &cb)) + return NULL; + if (cb<sizeof(IID)) + return PyErr_Format(PyExc_ValueError, + "string too small - must be at least %d bytes (got %d)", + sizeof(IID), cb); + iid = *((IID *)buf); + return PyWinObject_FromIID(iid); + } // Already an IID? Return self. if ( PyIID_Check(obIID) ) { *************** *** 115,118 **** --- 131,159 ---- } + static int getreadbuf(PyObject *self, int index, const void **ptr) + { + if ( index != 0 ) { + PyErr_SetString(PyExc_SystemError, + "accessing non-existent IID segment"); + return -1; + } + PyIID *pyiid = (PyIID *)self; + *ptr = &pyiid->m_iid; + return sizeof(IID); + } + + static int getsegcount(PyObject *self, int *lenp) + { + if ( lenp ) + *lenp = sizeof(IID); + return 1; + } + + static PyBufferProcs PyIID_as_buffer = { + (getreadbufferproc)getreadbuf, + (getwritebufferproc)0, + (getsegcountproc)getsegcount, + (getcharbufferproc)0, + }; // @object PyIID|A Python object, representing an IID/CLSID. *************** *** 143,146 **** --- 184,191 ---- // @pymeth __str__|Used whenever a string representation of the IID is required. PyIID::strFunc, /* tp_str */ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + // @comm Note that IID objects support the buffer interface. Thus buffer(iid) can be used to obtain the raw bytes. + &PyIID_as_buffer, /*tp_as_buffer*/ }; |