After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 629552 - Comparing GParamSpec objects is false for the same reference
Comparing GParamSpec objects is false for the same reference
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2010-09-13 18:15 UTC by Simon Pena
Modified: 2010-10-28 18:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase: library returning a constant GParamSpec (859 bytes, application/x-gzip)
2010-09-13 18:15 UTC, Simon Pena
  Details
Python script to test the library (398 bytes, text/plain)
2010-09-13 22:55 UTC, Simon Pena
  Details
Don't check the inner type when comparing gpointers (1.19 KB, patch)
2010-09-20 21:17 UTC, Simon Pena
committed Details | Review

Description Simon Pena 2010-09-13 18:15:56 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.
Comment 1 Simon Pena 2010-09-13 22:55:07 UTC
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.
Comment 2 Tomeu Vizoso 2010-09-14 07:03:12 UTC
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
Comment 3 Tomeu Vizoso 2010-09-14 07:13:57 UTC
(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.
Comment 4 Simon Pena 2010-09-16 16:51:40 UTC
(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.
Comment 5 Simon Pena 2010-09-20 21:17:07 UTC
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.