aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PySide/QtCore/typesystem_core.xml21
-rw-r--r--tests/QtCore/qfile_test.py11
2 files changed, 27 insertions, 5 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index d11d196fe..4a7456bd3 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -1782,11 +1782,22 @@
<extra-includes>
<include file-name="QAbstractFileEngine" location="global"/>
</extra-includes>
- <!-- ### See bug 721 -->
- <modify-function signature="unmap(uchar*)" remove="all"/>
- <modify-function signature="map(qint64,qint64,QFile::MemoryMapFlags)" remove="all"/>
- <!-- ### -->
-
+ <modify-function signature="unmap(uchar*)">
+ <modify-argument index="1">
+ <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));
+ </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);
+ </inject-code>
+ </modify-function>
<modify-function signature="remove()" allow-thread="yes"/>
<modify-function signature="remove(const QString&amp;)" allow-thread="yes"/>
<modify-function signature="rename(const QString&amp;)" allow-thread="yes"/>
diff --git a/tests/QtCore/qfile_test.py b/tests/QtCore/qfile_test.py
index adbdd68b7..898e5746b 100644
--- a/tests/QtCore/qfile_test.py
+++ b/tests/QtCore/qfile_test.py
@@ -27,5 +27,16 @@ class GetCharTest(unittest.TestCase):
self.assert_(not obj.getChar()[0])
obj.close()
+ def testBug721(self):
+ obj = QFile(self.filename)
+ obj.open(QIODevice.ReadOnly)
+ memory = obj.map(0, 1)
+ self.assertEqual(len(memory), 1)
+ self.assertEqual(memory[0], 'a')
+ obj.unmap(memory)
+ # now memory points to wild bytes... :-)
+ # uncommenting this must cause a segfault.
+ # self.assertEqual(memory[0], 'a')
+
if __name__ == '__main__':
unittest.main()