[PyQt] crash in sip.cast

Phil Thompson phil at riverbankcomputing.com
Wed Mar 17 09:33:28 GMT 2010


On Tue, 16 Mar 2010 18:32:57 -0700, Nathan Cournia <cournia at gmail.com>
wrote:
> Hi,
> 
> The following script segfaults:
> 
> import sys
> import sip
> from PyQt4.QtGui import *
> 
> a = QApplication(sys.argv)
> 
> # create a menu
> b = QMenu()
> 
> # cast it to a widget
> c = sip.cast(b, QWidget)
> 
> # cast the widget, which is really a menu, back to a menu.
> # this line crashes
> d = sip.cast(c, QMenu)
> 
> Here's the stack trace...
> 
> #0  0x5573cf09 in cast (self=0x0, args=0x83c570c) at siplib.c:907
> #1  0x555eccf0 in PyCFunction_Call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #2  0x5566465a in call_function () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #3  0x55660f83 in PyEval_EvalFrameEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #4  0x55662980 in PyEval_EvalCodeEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #5  0x5565b76c in PyEval_EvalCode () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #6  0x5568a3a2 in run_mod () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #7  0x5568a328 in PyRun_FileExFlags () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #8  0x556562f3 in builtin_execfile () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #9  0x555eccf0 in PyCFunction_Call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #10 0x5566465a in call_function () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #11 0x55660f83 in PyEval_EvalFrameEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #12 0x55662980 in PyEval_EvalCodeEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #13 0x5565b76c in PyEval_EvalCode () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #14 0x5566620a in exec_statement () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #15 0x5565ed88 in PyEval_EvalFrameEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #16 0x55662980 in PyEval_EvalCodeEx () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #17 0x555d61ca in function_call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #18 0x555a5810 in PyObject_Call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #19 0x555bbeae in instancemethod_call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #20 0x555a5810 in PyObject_Call () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> #21 0x555a5e03 in PyObject_CallMethodObjArgs () from
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> 
> The following line in siplib.c:907:cast() is crashing:
> 
>     if ((addr = sip_api_get_cpp_ptr(sw, type->type)) == NULL)
>         return NULL;
> 
> Above, "type" (the one left of ->) is NULL.
> 
> I'm using sip-4.10, PyQt-x11-gpl-4.7, and Qt 4.5.3.
> 
> Am I using sip.cast incorrectly?  Any help would be greatly appreciated.

It's a bug - fixed in tonight's snapshot...

...however it is very, very rare that you would need to use cast().

Phil


More information about the PyQt mailing list