summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-01-13 17:51:14 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2011-01-14 13:58:10 -0200
commit530a3d23c58a9997106018a64624f4d654e6d6ea (patch)
tree44c8b23df3a892aadfee974126204d0f30079fd2
parent8243565f817d37ffc33a5c3eabdc6e7657b981e1 (diff)
downloadpyside-530a3d23c58a9997106018a64624f4d654e6d6ea.tar.gz
pyside-530a3d23c58a9997106018a64624f4d654e6d6ea.tar.xz
pyside-530a3d23c58a9997106018a64624f4d654e6d6ea.zip
Fix bug#584 - "python pickle module can't treat QByteArray object of PySide"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Lauro Moura <lauro.neto@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml36
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml6
-rw-r--r--PySide/typesystem_templates.xml5
-rw-r--r--tests/QtCore/qbytearray_test.py11
4 files changed, 33 insertions, 25 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 9f1600a..a739050 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -433,7 +433,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" />
</insert-template>
</inject-code>
@@ -451,7 +451,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dddd)" />
+ <replace from="%REDUCE_FORMAT" to="dddd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" />
</insert-template>
</inject-code>
@@ -504,7 +504,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iii)" />
+ <replace from="%REDUCE_FORMAT" to="iii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()" />
</insert-template>
</inject-code>
@@ -569,7 +569,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiiiiiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiiiiiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.date().year(), %CPPSELF.date().month(), %CPPSELF.date().day(), %CPPSELF.time().hour(), %CPPSELF.time().minute(), %CPPSELF.time().second(), %CPPSELF.time().msec(), (int)%CPPSELF.timeSpec()" />
</insert-template>
</inject-code>
@@ -581,7 +581,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.path())" />
</insert-template>
</inject-code>
@@ -593,7 +593,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(ii)" />
+ <replace from="%REDUCE_FORMAT" to="ii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
</insert-template>
</inject-code>
@@ -612,7 +612,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dd)" />
+ <replace from="%REDUCE_FORMAT" to="dd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
</insert-template>
</inject-code>
@@ -624,7 +624,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -689,7 +689,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dddd)" />
+ <replace from="%REDUCE_FORMAT" to="dddd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -743,7 +743,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(ii)" />
+ <replace from="%REDUCE_FORMAT" to="ii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -762,7 +762,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(dd)" />
+ <replace from="%REDUCE_FORMAT" to="dd" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" />
</insert-template>
</inject-code>
@@ -775,7 +775,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(iiii)" />
+ <replace from="%REDUCE_FORMAT" to="iiii" />
<replace from="%REDUCE_ARGS" to="%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()" />
</insert-template>
</inject-code>
@@ -795,7 +795,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" />
</insert-template>
</inject-code>
@@ -1224,7 +1224,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" />
</insert-template>
</inject-code>
@@ -1239,7 +1239,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(sii)" />
+ <replace from="%REDUCE_FORMAT" to="sii" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.pattern()), (int)%CPPSELF.caseSensitivity(), (int)%CPPSELF.patternSyntax()" />
</insert-template>
</inject-code>
@@ -1288,7 +1288,7 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
+ <replace from="%REDUCE_FORMAT" to="s" />
<replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.filePath())" />
</insert-template>
</inject-code>
@@ -1301,8 +1301,8 @@
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(s)" />
- <replace from="%REDUCE_ARGS" to="%CPPSELF.constData()" />
+ <replace from="%REDUCE_FORMAT" to="N" />
+ <replace from="%REDUCE_ARGS" to="PyString_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size())" />
</insert-template>
</inject-code>
</add-function>
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index e6dabc4..50247c3 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -499,14 +499,14 @@
</extra-includes>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
- PyObject *points = PyList_New(%CPPSELF.count());
- for (int i = 0; i &lt; %CPPSELF.count(); ++i){
+ PyObject* points = PyList_New(%CPPSELF.count());
+ for (int i = 0, max = %CPPSELF.count(); i &lt; max; ++i){
int x, y;
%CPPSELF.point(i, &amp;x, &amp;y);
PyList_SET_ITEM(points, i, %CONVERTTOPYTHON[QPoint](QPoint(x, y)));
}
<insert-template name="reduce_code">
- <replace from="%REDUCE_FORMAT" to="(N)" />
+ <replace from="%REDUCE_FORMAT" to="N" />
<replace from="%REDUCE_ARGS" to="points" />
</insert-template>
</inject-code>
diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml
index 4604fda..dd07459 100644
--- a/PySide/typesystem_templates.xml
+++ b/PySide/typesystem_templates.xml
@@ -188,10 +188,7 @@
</template>
<!-- templates for __reduce__ -->
<template name="reduce_code">
- PyObject *type = PyObject_Type(%PYSELF);
- PyObject *args = NULL;
- args = Py_BuildValue("%REDUCE_FORMAT", %REDUCE_ARGS);
- %PYARG_0 = Py_BuildValue("(NN)", type, args);
+ %PYARG_0 = Py_BuildValue("(N(%REDUCE_FORMAT))", PyObject_Type(%PYSELF), %REDUCE_ARGS);
</template>
<template name="reduce_code_matrix">
QList&lt; %MATRIX_TYPE &gt; cppArgs;
diff --git a/tests/QtCore/qbytearray_test.py b/tests/QtCore/qbytearray_test.py
index 34dc42f..f031332 100644
--- a/tests/QtCore/qbytearray_test.py
+++ b/tests/QtCore/qbytearray_test.py
@@ -4,6 +4,8 @@
import unittest
import ctypes
import sys
+import pickle
+import cStringIO
from PySide.QtCore import *
@@ -109,5 +111,14 @@ class QByteArrayBug514(unittest.TestCase):
self.assertEqual(type(a), QByteArray)
self.assertEqual(a.data(), data)
+class TestPickler(unittest.TestCase):
+ def testIt(self):
+ ba = QByteArray("321\x00123")
+ output = cStringIO.StringIO()
+ pickle.dump(ba, output)
+ ba2 = pickle.loads(output.getvalue())
+ self.assertEqual(ba, ba2)
+
+
if __name__ == '__main__':
unittest.main()