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 540415 - G(S)List find_custom binding too restrictive
G(S)List find_custom binding too restrictive
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
0.3.x
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 492483
Blocks:
 
 
Reported: 2008-06-27 05:01 UTC by Michael Lawrence
Modified: 2014-01-29 05:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes g_(s)list_find_custom binding (770 bytes, patch)
2008-06-27 05:02 UTC, Michael Lawrence
rejected Details | Review

Description Michael Lawrence 2008-06-27 05:01:25 UTC
The g_list_find_custom and g_slist_find_custom bindings currently accept 'G' (the element type of the list) as the query, but since a custom CompareFunc is being applied, it is not necessary to restrict the query to type 'G'. It should just be a void* instead.

Patch on its way.
Comment 1 Michael Lawrence 2008-06-27 05:02:04 UTC
Created attachment 113506 [details] [review]
Fixes g_(s)list_find_custom binding
Comment 2 Jürg Billeter 2008-06-27 05:15:25 UTC
I see that you can theoretically pass a value of a different type to the `data' parameter, however, do we really need this? Can't you just store the value in a prototype object that has the same type as the list elements?

The issue with the proposed change is that e.g. int values are not compatible with void*, so you'd break searching for int values. The correct change would probably be something like:

    public weak SList<G> find_custom<K> (K data, CompareFunc<G,K> func);

However, this needs support for generic methods and generic delegates, which we don't have yet, and it might make it more complicated than necessary.

Can you provide a concrete use case?
Comment 3 Michael Lawrence 2008-06-27 05:45:14 UTC
Once generic methods/delegates are supported, the binding probably should be changed as you suggest. 
(In reply to comment #2)
> I see that you can theoretically pass a value of a different type to the `data'
> parameter, however, do we really need this? Can't you just store the value in a
> prototype object that has the same type as the list elements?
> 

Yes, but I just thought it would be easier this way, in general. It would be a lot of work to design everything to support various prototype forms just to support searching for them in a list.

> The issue with the proposed change is that e.g. int values are not compatible
> with void*, so you'd break searching for int values. The correct change would
> probably be something like:
> 
>     public weak SList<G> find_custom<K> (K data, CompareFunc<G,K> func);
> 
> However, this needs support for generic methods and generic delegates, which we
> don't have yet, and it might make it more complicated than necessary.
> 

I think that's a good idea once there is support for generic methods and delegates. In the mean time I'll just do something else.

> Can you provide a concrete use case?
> 

Comment 4 Qball Cow 2009-08-06 10:40:41 UTC
I think this is somewhat needed. 
I for example has a list<Client> clients;

Now I want to add a client with uid X. Before adding, I want to check if client X already exists. so I have to find a client with client.uid == X.
find_custom is perfectly capable of doing this in C, so why not in vala?

My compare function is then something like this:

private int custom_client_search(Client a, string uid)
{
    if(a.uid == uid){
        return 0;
    }
    return 1;
}
Comment 5 Jürg Billeter 2010-08-03 09:20:58 UTC
In my opinion, we should have two bindings for this function to satisfy the two use cases.
Comment 6 Evan Nemerson 2014-01-29 05:23:55 UTC
commit a4b869a6c5dd7763748acdca837149e924d02385
Author: Evan Nemerson <evan@coeus-group.com>
Date:   Tue Jan 28 21:22:01 2014 -0800

    glib-2.0: add search functions for (S)List and Queue
    
    Fixes bug 540415.