PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 1029 - qmlRegisterType Fails to Increase the Ref Count
: qmlRegisterType Fails to Increase the Ref Count
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtDeclarative
: 1.0.7
: Other meego
: P2 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-10-21 01:48 EEST by se_police
Modified: 2011-11-29 21:28 EET (History)
9 users (show)

See Also:


Attachments
Python Script to Demonstrate the Bug (899 bytes, text/x-python-script)
2011-10-21 01:48 EEST, se_police
Details
Qml File to Demonstrate the Bug (147 bytes, application/octet-stream)
2011-10-21 01:49 EEST, se_police
Details

Note You need to log in before you can comment on or make changes to this bug.
Description se_police 2011-10-21 01:48:50 EEST
Created attachment 436 [details]
Python Script to Demonstrate the Bug

Probably qmlRegisterType fails to increase the ref count of the class object
being registered. When classes are created dynamically this may lead to the
collection of said classes. Trying to create an instance of this class, may
then result in a segmentation fault.

A demonstration of the behavior is attached. Setting trigger_bug to False
prevents the segmentation fault.

Tested with
    Qt version: 4.7.4
    PySide: 1.0.7
    Python: 2.7.2
    Os: Mac OSX 10.6.8
Comment 1 se_police 2011-10-21 01:49:36 EEST
Created attachment 437 [details]
Qml File to Demonstrate the Bug
Comment 2 Anatoly 2011-10-21 11:30:09 EEST
On the platform MeeGo (Nokia N950 Harmattan) I get the same error in my code. I
registered a new type of QML, and get a "segmentation fault".
  I tried to run files that are attached here, and also get the error
segmentation.

# dpkg -l | grep -i pyside
ii  libpyside1.0                   1.0.7-1maemo2+0m6
ii  python-pyside                  1.0.7-1maemo2+0m6
ii  python-pyside.qtcore           1.0.7-1maemo2+0m6
ii  python-pyside.qtdeclarative    1.0.7-1maemo2+0m6
ii  python-pyside.qtgui            1.0.7-1maemo2+0m6
...

# python --version
Python 2.6.6

# dpkg -l | grep -i pyside
libqt4      4.7.4~git20110728-pr11-0maemo11+0m6

OS: MeeGo 1.2 Harmattan (Nokia N950)
Comment 3 Hugo Parente Lima 2011-10-31 19:25:00 EET
qmlRegisterType doesn't create a class object, we did a lot of ugly hacks to
make qmlRegisterType work on PySide, the problem may be in those ugly hacks.
Comment 4 se_police 2011-11-01 01:12:45 EET
So without knowing anything about the implementation. I would guess, that it is
intended for qmlRegisterType to increase the refcount as long as the PySide
module is alive. So that the internal reference to the class registered with
the qml system is always valid. The current implementation does not do this.
For example the following piece of code prints two times the same number.

print sys.getrefcount(TestClass)
QtDeclarative.qmlRegisterType(TestClass, "UserTypes", 1, 0, "TestClass")
print sys.getrefcount(TestClass)

If you are up for one more ugly hack, simply using a global list and adding any
registered class objects would suffice. Something along the lines of the
following code:

global _registeredTypes = list()
def newQmlRegisterType(klass, module, major, minor, name):
 global _registeredTypes
 _registeredTypes.append(klass)
 oldQmlRegisterType(klass, module, major, minor, name)

I guess, since qmlRegisterType is essentially anyway using some hidden global
object, it wouldn't be so hackish after all. The Alternative would be to put
somewhere on the C-side a Py_INCREF and probably also a Py_DECREF, when Qt
shuts down.
Comment 5 Hugo Parente Lima 2011-11-01 22:11:16 EET
You are right about the reference count, the ugly hacks has nothing to do with
this crash.
Comment 6 Hugo Parente Lima 2011-11-01 23:15:02 EET
Fixed in commit:

pyside/8e5f57067e076eec733ee9540602db10714496aa
Comment 7 Luciano Wolf 2011-11-29 21:28:45 EET
Released on PySide 1.0.9. Closing.