diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-04-06 18:35:49 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:54:08 -0300 |
commit | 6ef7460a47674072b2dd2f8521bea8c84f7153d5 (patch) | |
tree | b7abb2be3d19f92f619f0f6c92b3da130ecc6c6b | |
parent | 0cb14ebf352b4174be9e60f47574aee432e35a1d (diff) |
Fix bug 721 - "QFile doesn't support map and unmap functions."
-rw-r--r-- | PySide/QtCore/typesystem_core.xml | 21 | ||||
-rw-r--r-- | tests/QtCore/qfile_test.py | 11 |
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, &ptr, &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&)" allow-thread="yes"/> <modify-function signature="rename(const QString&)" 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() |