aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-01-21 18:44:59 -0200
committerHugo Lima <hugo.lima@openbossa.org>2010-01-21 18:44:59 -0200
commit03287b8d01e4c0536425e8339f7af50066b06351 (patch)
tree1ef024499d532061f2f9782a7adbb142f23ad600 /PySide/QtCore/glue/qbytearray_bufferprotocol.cpp
parentd0cd206f37b707cf73a389d815080690082f70da (diff)
Add support fot buffer protocol for QByteArray.
Reviewed by Marcelo Lira <marcelo.lira@openbossa.org> and Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'PySide/QtCore/glue/qbytearray_bufferprotocol.cpp')
-rw-r--r--PySide/QtCore/glue/qbytearray_bufferprotocol.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp
new file mode 100644
index 000000000..f0d15048e
--- /dev/null
+++ b/PySide/QtCore/glue/qbytearray_bufferprotocol.cpp
@@ -0,0 +1,35 @@
+
+#if PY_VERSION_HEX < 0x03000000
+
+// QByteArray buffer protocol functions
+// see: http://www.python.org/dev/peps/pep-3118/
+
+extern "C" {
+
+static Py_ssize_t SbkQByteArray_segcountproc(PyObject* self, Py_ssize_t* lenp)
+{
+ if (lenp)
+ *lenp = self->ob_type->tp_as_sequence->sq_length(self);
+ return 1;
+}
+
+static Py_ssize_t SbkQByteArray_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr)
+{
+ if (segment || Shiboken::cppObjectIsInvalid(self))
+ return -1;
+
+ QByteArray* cppSelf = SbkQByteArray_cptr(self);
+ *ptrptr = reinterpret_cast<void*>(cppSelf->data());
+ return cppSelf->size();
+}
+
+PyBufferProcs SbkQByteArrayBufferProc = {
+ /*bf_getreadbuffer*/ &SbkQByteArray_readbufferproc,
+ /*bf_getwritebuffer*/ (writebufferproc) &SbkQByteArray_readbufferproc,
+ /*bf_getsegcount*/ &SbkQByteArray_segcountproc,
+ /*bf_getcharbuffer*/ (charbufferproc) &SbkQByteArray_readbufferproc
+};
+
+}
+
+#endif