GNOME Bugzilla – Bug 629552
Comparing GParamSpec objects is false for the same reference
Last modified: 2010-10-28 18:25:45 UTC
Created attachment 170181 [details] Testcase: library returning a constant GParamSpec Two references for the same constant GParamSpec return False when being compared in Python. The testcase attached provides a test library with a static function returning a constant GParamSpec. Successive calls to the function return the same object, but when compared from Python (accessing via GObject Introspection) the result is False.
Created attachment 170198 [details] Python script to test the library The attached file imports the Test library from the gi.repository (the environment has to be set as explained in the README), and invokes the static method get_spec(). Successive calls to the method, even if they return the same object, return False when being compared to each other.
Thanks for spotting this. About the C part of the test case, we already have an object with properties in GIMarshallingTests-1.0.typelib, this typelib is generated in gobject-introspection and pygobject tests it in tests/test_gi.py. About the fix itself, we probably could override tp_new here: http://git.gnome.org/browse/pygobject/tree/gi/pygi-boxed.c#n176
(In reply to comment #2) > > About the fix itself, we probably could override tp_new here: > http://git.gnome.org/browse/pygobject/tree/gi/pygi-boxed.c#n176 Note that we don't have any way to compare the private fields nor introspection nor gtype will tell us which is the compare function so we probably can just say that two python objects are equal if they point to the same C structure.
(In reply to comment #2) > Thanks for spotting this. About the C part of the test case, we already have an > object with properties in GIMarshallingTests-1.0.typelib, this typelib is > generated in gobject-introspection and pygobject tests it in tests/test_gi.py. That typelib you point out doesn't contain any function returning a const GParamSpec. I don't know if it is a good idea, but at Grilo we're using a GParamSpecs to store information about the media (different kinds of metadata). The problem comes when we retrieve those ParamSpecs, as successive calls to a function returning the same ParamSpec (a constant one) provides Python objects which, when compared, don't evaluate to the same one. The C part of the test case I provided tries to simulate that: there's a constant ParamSpec which gets initialized in the first call, and the next calls always return the same one. However, when testing it from Python, the comparison fails.
Created attachment 170713 [details] [review] Don't check the inner type when comparing gpointers When using pyg_pointer_richcompare to compare two objects, don't check their inner types. As we can't compare their private fields, nor get a proper compare function, we can consider them gpointers and compare them that way.