Changeset 86311 in vbox
- Timestamp:
- Sep 28, 2020 10:49:50 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/python/src/PyIID.cpp
r64330 r86311 68 68 #else 69 69 if (PyObject_CheckBuffer(obBuf)) { 70 void *buf = NULL; 71 Py_buffer view; 72 if (PyObject_GetBuffer(obBuf, &view, PyBUF_CONTIG_RO) != 0) 73 { 74 PyErr_Format(PyExc_ValueError, "Could not get contiguous buffer from object"); 75 return NULL; 76 } 77 Py_ssize_t size = view.len; 78 buf = view.buf; 70 Py_buffer view; 71 if (PyObject_GetBuffer(obBuf, &view, PyBUF_CONTIG_RO) != 0) { 72 PyErr_Format(PyExc_ValueError, "Could not get contiguous buffer from object"); 73 return NULL; 74 } 75 Py_ssize_t size = view.len; 76 const void *buf = view.buf; 79 77 #endif 80 78 if (size != sizeof(nsIID) || buf==NULL) { 81 #if PY_MAJOR_VERSION >= 3 82 PyBuffer_Release(&view); 83 #endif 79 PyBuffer_Release(&view); 84 80 #ifdef VBOX 85 81 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID)); 86 82 #else 87 83 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID)); … … 90 86 } 91 87 nsIID iid; 92 unsigned char *ptr = (unsigned char*)buf;88 unsigned char const *ptr = (unsigned char const *)buf; 93 89 iid.m0 = XPT_SWAB32(*((PRUint32 *)ptr)); 94 ptr = ((unsigned char *)buf) + offsetof(nsIID, m1);90 ptr = ((unsigned char const *)buf) + offsetof(nsIID, m1); 95 91 iid.m1 = XPT_SWAB16(*((PRUint16 *)ptr)); 96 ptr = ((unsigned char *)buf) + offsetof(nsIID, m2);92 ptr = ((unsigned char const *)buf) + offsetof(nsIID, m2); 97 93 iid.m2 = XPT_SWAB16(*((PRUint16 *)ptr)); 98 ptr = ((unsigned char *)buf) + offsetof(nsIID, m3);94 ptr = ((unsigned char const *)buf) + offsetof(nsIID, m3); 99 95 for (int i=0;i<8;i++) { 100 iid.m3[i] = *((PRUint8 *)ptr);96 iid.m3[i] = *((PRUint8 const *)ptr); 101 97 ptr += sizeof(PRUint8); 102 98 } 103 99 #if PY_MAJOR_VERSION >= 3 104 100 PyBuffer_Release(&view); 105 101 #endif 106 102 return new Py_nsIID(iid);
Note:
See TracChangeset
for help on using the changeset viewer.