summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-06-01 15:40:48 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-06-02 11:04:24 -0300
commit75154e2f2fe237d33438a4ce3730ced145c475e4 (patch)
tree95f62a3d7c403d85fd39d635de083c5f409da45d
parent606a90d4069bbad479216e4dc1dfa92ede39f2e9 (diff)
downloadpyside-75154e2f2fe237d33438a4ce3730ced145c475e4.tar.gz
pyside-75154e2f2fe237d33438a4ce3730ced145c475e4.tar.xz
pyside-75154e2f2fe237d33438a4ce3730ced145c475e4.zip
Port all buffer related code to the new Shiboken buffer interface.
Reviewer: Renato Ara├║jo <renato.filho@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml55
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml43
-rw-r--r--PySide/QtOpenGL/typesystem_opengl.xml4
3 files changed, 36 insertions, 66 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 285e6e6..1032b58 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -518,9 +518,9 @@
<replace-type modified-type="PyObject" />
</modify-argument>
<inject-code>
- const uchar* d = %CPPSELF.%FUNCTION_NAME();
+ const void* d = %CPPSELF.%FUNCTION_NAME();
if (d) {
- %PYARG_0 = PyBuffer_FromMemory(const_cast&lt;uchar*>(d), %CPPSELF.size());
+ %PYARG_0 = Shiboken::Buffer::newObject(d, %CPPSELF.size());
} else {
Py_INCREF(Py_None);
%PYARG_0 = Py_None;
@@ -528,21 +528,13 @@
</inject-code>
</modify-function>
<template name="QResource_registerResource">
- PyTypeObject* pyType = %PYARG_1->ob_type;
- if (pyType->tp_as_buffer
- &amp;&amp; pyType->tp_as_buffer->bf_getreadbuffer
- &amp;&amp; pyType->tp_as_buffer->bf_getsegcount(%PYARG_1, 0) == 1) {
- void* ptr;
- pyType->tp_as_buffer->bf_getreadbuffer(%PYARG_1, 0, &amp;ptr);
- %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(const_cast&lt;const uchar*>((uchar*)ptr), %2));
- } else {
- PyErr_SetString(PyExc_TypeError, "The object must support buffer protocol with just one segment.");
- }
+ uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(const_cast&lt;const uchar*>(ptr), %2));
</template>
<modify-function signature="unregisterResource(const uchar*, const QString&amp;)" rename="unregisterResourceData">
<modify-argument index="1">
- <replace-type modified-type="PyObject"/>
+ <replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
<insert-template name="QResource_registerResource" />
@@ -550,7 +542,7 @@
</modify-function>
<modify-function signature="registerResource(const uchar*, const QString&amp;)" rename="registerResourceData">
<modify-argument index="1">
- <replace-type modified-type="PyObject"/>
+ <replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
<insert-template name="QResource_registerResource" />
@@ -1976,15 +1968,13 @@
<replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
- const void* ptr;
- Py_ssize_t len;
- PyObject_AsReadBuffer(%PYARG_1, &amp;ptr, &amp;len);
- %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME((uchar*)ptr));
+ uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(ptr));
</inject-code>
</modify-function>
<modify-function signature="map(qint64,qint64,QFile::MemoryMapFlags)">
<inject-code>
- %PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2);
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite);
</inject-code>
</modify-function>
<modify-function signature="remove()" allow-thread="yes"/>
@@ -2183,22 +2173,15 @@
<object-type name="QTranslator">
<modify-function signature="load(const uchar*, int)">
<modify-argument index="1">
- <replace-type modified-type="PyObject" />
+ <replace-type modified-type="PyBuffer" />
</modify-argument>
<modify-argument index="2">
<remove-argument />
</modify-argument>
<inject-code>
- PyTypeObject* pyType = %PYARG_1->ob_type;
- if (pyType->tp_as_buffer
- &amp;&amp; pyType->tp_as_buffer->bf_getreadbuffer
- &amp;&amp; pyType->tp_as_buffer->bf_getsegcount(%PYARG_1, 0) == 1) {
- void* ptr;
- Py_ssize_t size = pyType->tp_as_buffer->bf_getreadbuffer(%PYARG_1, 0, &amp;ptr);
- %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(const_cast&lt;const uchar*>((uchar*)ptr), size));
- } else {
- PyErr_SetString(PyExc_TypeError, "The object must support buffer protocol with just one segment.");
- }
+ Py_ssize_t size;
+ uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1, &amp;size);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(const_cast&lt;const uchar*>(ptr), size));
</inject-code>
</modify-function>
</object-type>
@@ -2317,15 +2300,13 @@
<replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
- const void* ptr;
- Py_ssize_t len;
- PyObject_AsReadBuffer(%PYARG_1, &amp;ptr, &amp;len);
- %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME((uchar*)ptr));
+ uchar* ptr = (uchar*)Shiboken::Buffer::getPointer(%PYARG_1);
+ %PYARG_0 = %CONVERTTOPYTHON[bool](%CPPSELF.%FUNCTION_NAME(ptr));
</inject-code>
</modify-function>
<modify-function signature="map(qint64,qint64,QFile::MemoryMapFlags)">
<inject-code>
- %PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2);
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite);
</inject-code>
</modify-function>
@@ -2991,8 +2972,8 @@
</object-type>
<!-- We will use inject code to implement the function below -->
- <rejection class="QEasingCurve" function-name="setCustomType" />
- <rejection class="QEasingCurve" function-name="customType" />
+ <rejection class="QEasingCurve" function-name="setCustomType" />
+ <rejection class="QEasingCurve" function-name="customType" />
<value-type name="QEasingCurve" since="4.6">
<extra-includes>
<include file-name="pysideweakref.h" location="global"/>
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index 5ff06da..523dae9 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -415,13 +415,11 @@
<value-type name="QBitmap" >
<modify-function signature="fromData(QSize,const uchar*,QImage::Format)">
<modify-argument index="2">
- <replace-type modified-type="PyObject"/>
+ <replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
- const void* buffer;
- Py_ssize_t size;
- if (PyObject_AsReadBuffer(%PYARG_2, &amp;buffer, &amp;size) != -1)
- %PYARG_0 = %CONVERTTOPYTHON[QBitmap](QBitmap::fromData(%1, (const uchar*)buffer, %3));
+ uchar* buffer = (uchar*) Shiboken::Buffer::getPointer(%PYARG_2);
+ %PYARG_0 = %CONVERTTOPYTHON[QBitmap](QBitmap::fromData(%1, buffer, %3));
</inject-code>
</modify-function>
</value-type>
@@ -553,25 +551,24 @@
<replace-type modified-type="PyObject"/>
</modify-argument>
<inject-code>
- %PYARG_0 = PyBuffer_FromMemory(const_cast&lt;char*&gt;(%CPPSELF.data()), %CPPSELF.size());
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.data(), %CPPSELF.size());
</inject-code>
</modify-function>
<modify-function signature="setData(const char*,uint)">
<modify-argument index="1">
<replace-type modified-type="PyBuffer"/>
<conversion-rule class="target">
- PyObject *%out = PyBuffer_FromMemory(const_cast&lt;char*&gt;(%in), size);
+ PyObject* %out = Shiboken::Buffer::newObject(%in, size);
</conversion-rule>
<conversion-rule class="native">
- const char *%out;
- Py_ssize_t buffer_len;
- PyObject_AsCharBuffer(arg, &amp;%out, &amp;buffer_len);
+ Py_ssize_t bufferLen;
+ char* %out = (char*) Shiboken::Buffer::getPointer(arg, &amp;bufferLen);
</conversion-rule>
</modify-argument>
<modify-argument index="2">
<remove-argument/>
<conversion-rule class="native">
- uint %out = buffer_len;
+ uint %out = bufferLen;
</conversion-rule>
</modify-argument>
</modify-function>
@@ -975,20 +972,12 @@
</extra-includes>
<template name="qimage_buffer_constructor">
- PyTypeObject* pyType = reinterpret_cast&lt;PyTypeObject*>(%PYARG_1->ob_type);
- if (pyType->tp_as_buffer
- &amp;&amp; pyType->tp_as_buffer->bf_getreadbuffer
- &amp;&amp; pyType->tp_as_buffer->bf_getsegcount(%PYARG_1, 0) == 1) {
- void* ptr;
- pyType->tp_as_buffer->bf_getreadbuffer(%PYARG_1, 0, &amp;ptr);
- %0 = new %TYPE((uchar*)ptr, %ARGS);
- } else {
- PyErr_SetString(PyExc_TypeError, "The object must support buffer protocol with just one segment.");
- }
+ uchar* ptr = (uchar*) Shiboken::Buffer::getPointer(%PYARG_1);
+ %0 = new %TYPE(ptr, %ARGS);
</template>
<modify-function signature="QImage(uchar *,int,int,int,QImage::Format)">
<modify-argument index="1">
- <replace-type modified-type="PyObject"/>
+ <replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
<insert-template name="qimage_buffer_constructor">
@@ -998,7 +987,7 @@
</modify-function>
<modify-function signature="QImage(uchar*,int,int,QImage::Format)">
<modify-argument index="1">
- <replace-type modified-type="PyObject"/>
+ <replace-type modified-type="PyBuffer"/>
</modify-argument>
<inject-code>
<insert-template name="qimage_buffer_constructor">
@@ -1054,23 +1043,23 @@
<modify-function signature="constBits()const" since="4.7">
<inject-code>
- %PYARG_0 = PyBuffer_FromMemory(const_cast&lt;uchar*>(%CPPSELF.%FUNCTION_NAME()), %CPPSELF.byteCount());
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.byteCount());
</inject-code>
</modify-function>
<modify-function signature="bits()">
<inject-code>
// byteCount() is only available on Qt4.7, so we use bytesPerLine * height
- %PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height());
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height(), Shiboken::Buffer::ReadWrite);
</inject-code>
</modify-function>
<modify-function signature="constScanLine(int)const" since="4.7">
<inject-code>
- %PYARG_0 = PyBuffer_FromMemory(const_cast&lt;uchar*>(%CPPSELF.%FUNCTION_NAME(%1)), %CPPSELF.bytesPerLine());
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine());
</inject-code>
</modify-function>
<modify-function signature="scanLine(int)">
<inject-code>
- %PYARG_0 = PyBuffer_FromReadWriteMemory(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine());
+ %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine(), Shiboken::Buffer::ReadWrite);
</inject-code>
</modify-function>
<!--
diff --git a/PySide/QtOpenGL/typesystem_opengl.xml b/PySide/QtOpenGL/typesystem_opengl.xml
index b694400..abed718 100644
--- a/PySide/QtOpenGL/typesystem_opengl.xml
+++ b/PySide/QtOpenGL/typesystem_opengl.xml
@@ -130,9 +130,9 @@
Py_INCREF(Py_None);
%PYARG_0 = Py_None;
} else if (%1 == QGLBuffer::ReadOnly) {
- %PYARG_0 = PyBuffer_FromMemory(data, dataSize);
+ %PYARG_0 = Shiboken::Buffer::newObject(data, dataSize, Shiboken::Buffer::ReadOnly);
} else {
- %PYARG_0 = PyBuffer_FromReadWriteMemory(data, dataSize);
+ %PYARG_0 = Shiboken::Buffer::newObject(data, dataSize, Shiboken::Buffer::ReadWrite);
}
</inject-code>
</modify-function>