On Mon, 29 Aug 2011 11:32:01 -0700, David Cortesi <davecort...@gmail.com>
wrote:
> The following code will reliably produce a crash on my Mac OS 10.6.8
(snow
> leopard) system. Python 2.6.1.
> 
> from __future__ import division
> from __future__ import print_function
> from __future__ import unicode_literals
> from future_builtins import *
> 
> from PyQt4.QtCore import (QFile, QTextStream, QString)
> 
> ts = QTextStream(QString(u"hello\n sailor\n"),QFile.ReadOnly)
> print(ts.atEnd())
> qs = ts.readAll()
> print(u'a. {0}:{1}'.format(qs.length(),qs))
> print(ts.atEnd())
> ts = QTextStream(QString(u"hello\n sailor\n"),QFile.ReadOnly)
> print(ts.atEnd())
> 
> The printed output preceding the crash is usually,
> False
> a. 0:
> True
> But sometimes the displayed data is longer and contains garbage
characters.
> 
> The crash report starts,
> Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
> Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000011
> Crashed Thread:  0  Dispatch queue: com.apple.main-thread
> 
> Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
> 0   QtCore                            0x000000010149d744
> QTextStream::atEnd() const + 20
> 1   QtCore.so                         0x000000010113d194
> meth_QTextStream_atEnd + 100
> 2   org.python.python                 0x0000000100089187
PyEval_EvalFrameEx
> + 15317

You need to keep a reference to the QString to make sure it doesn't get
garbage collected.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to