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 778290 - Gio.ListStore.insert_sorted() broken
Gio.ListStore.insert_sorted() broken
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2017-02-07 15:20 UTC by Cédric Bellegarde
Modified: 2018-04-20 08:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Cédric Bellegarde 2017-02-07 15:20:20 UTC
When using Gio.ListStore.insert_sorted() with a GLib.CompareDataFunc, liststore pass int as args to sort function instead of GObject.

 GLib.CompareDataFunc(a, b, user_data)
    Parameters:	
        a (object or None) – a value
        b (object or None) – a value to compare with
        user_data (object or None) – user data

Actual result:
$ python liststore.py 
12028736 12028768


#!/usr/bin/env python3

from gi.repository import Gio, GObject

class Item(GObject.GObject):
    name = GObject.Property(type=str,
                             default='')

def sort(row1, row2):
    print(row1, row2)
    return 0

model = Gio.ListStore()
item1 = Item()
item1.set_property('name', 'plop')
item2 = Item()
item2.set_property('name', 'plop')
model.insert_sorted(item1, sort)
model.insert_sorted(item2, sort)
Comment 1 Emmanuele Bassi (:ebassi) 2017-02-07 15:29:59 UTC
'ints' in this case are pointers to GObjects.

The GCompareFunc is part of GLib, so it has no idea what "GObject" is, and we cannot annotate it.

Maybe pygobject can provide an override for that, since it knows that the sorting function is going to get two GObject instances, but that may require some CPython trickery.

Let's re-assign this to pygobject; if there's no way to deal with this at the Python level, then we may need to add new API to GListStore:

 - a new comparison function, with correctly typed arguments
 - a new insert_sorted() variant that uses the new comparison function
Comment 2 Christoph Reiter (lazka) 2017-04-03 08:49:38 UTC
The code in bug 759646 could help with adding an override for this.
Comment 3 GNOME Infrastructure Team 2018-01-10 20:58:16 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/130.
Comment 4 Christoph Reiter (lazka) 2018-04-20 08:24:55 UTC
I've created a MR for this: https://gitlab.gnome.org/GNOME/pygobject/merge_requests/61