[PyQt] Problems creating QApplication instance (backdoor in addTypeSlots)

Phil Thompson phil at riverbankcomputing.com
Thu Aug 5 18:16:38 BST 2010


On Wed, 4 Aug 2010 15:11:46 +0000, Marcin Cieslak <saper at saper.info>
wrote:
> Hello,
> 
> I am pretty new to Qt4 and SIP but I try to find a problem
> with the startup of the Py-Qt4 application (Hewlett Packard
> printer toolbox utility from hp-lip package) on my FreeBSD box.
> 
> My environment:
> 
> * FreeBSD 9.0-CURRENT #5 r206987: Tue Apr 27 20:45:03 CEST 2010
> * Qt 4.6.3
> * PyQt4 4.7.3 (configure options at the end of this email)
> * SIP 4.10.2 (configure options at the end of this email)
> * Python 2.5.5
> 
> Everything running on amd64 (64 bit), installed via FreeBSD
> ports from source.
> 
> Simple "from PyQt4.QtGui import QApplication" fails with SIGSEGV:
> 
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 800e041c0 (LWP 100167)]
> 0x00000008057a666e in addTypeSlots (heap_to=0x8010c3020, slots=0x53)
>      at siplib.c:9361
> 9361        while ((f = slots->psd_func) != NULL)
> (gdb) bt
> #0  0x00000008057a666e in addTypeSlots (heap_to=0x8010c3020, slots=0x53)
>      at siplib.c:9361
> #1  0x00000008057a790c in sipEnumType_alloc (self=0x8058acc20, nitems=0)
>      at siplib.c:10496
> #2  0x000000000044eeac in type_new ()
> #3  0x0000000000446c8a in type_call ()
> #4  0x0000000000414fef in PyObject_Call ()
> #5  0x000000080579fca8 in createContainerType (cod=0x801c89508,
>      td=0x801c894e0, bases=0x801082410, metatype=0x8058acc20,
>      mod_dict=0x800fb1160, client=0x801b3d300) at siplib.c:5231
> #6  0x00000008057a0059 in createClassType (client=0x801b3d300,
>      ctd=0x801c894e0, mod_dict=0x800fb1160) at siplib.c:5350
> #7  0x0000000805795ad1 in sip_api_init_module (client=0x801b3d300,
>      mod_dict=0x800fb1160) at siplib.c:1381
> #8  0x0000000801580db7 in initQtGui ()
>     from /usr/local/lib/python2.5/site-packages/PyQt4/QtGui.so
> 
> I have poked around a bit and I have trouble understanding one thing
> in siplib.c:
> 
> createContainerType() uses a "currentType" global variable to pass
> the QApplication class description to the object being created by
> Python. An "sip.enumtyp" Python object is being created and then
> sipEnumType_alloc() attempts to use currentType to fill in the slots
> of the object.  However, it assumes that the currentType passed is
> a pointer to (sipEnumTypeDef), while in this case it is
(sipClassTypeDef).
> Segmentation violation occurs when attepting to use illegal value of
> "etd_pyslots" as a pointer.
> 
> How is "currentType" supposed to work in case of metaclass
initialization?

I don't see how that backtrace could be produced in the first place as
sipEnumType_alloc() would never be called in that situation. I assume
something has already gone wrong before the call to PyObject_Call().

In tonight's snapshot I've changed things so that an assert() will fail if
there is an attempt to use the back door recursively - but it works fine
for me.

Phil


More information about the PyQt mailing list