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 592817 - Inserting into HashMap creates copy of the key before insertion (conflict with g_direct_{hash,equal})
Inserting into HashMap creates copy of the key before insertion (conflict wit...
Status: RESOLVED FIXED
Product: libgee
Classification: Platform
Component: general
git master
Other All
: Normal blocker
: ---
Assigned To: libgee-maint
libgee-maint
Depends on:
Blocks:
 
 
Reported: 2009-08-23 18:25 UTC by Sebastian Dröge (slomo)
Modified: 2009-09-28 17:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Sebastian Dröge (slomo) 2009-08-23 18:25:08 UTC
Quoting http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=543249:

If I use HashMap.get() in the Vala program, it returns null. The
attached Vala code can be used to reproduce the bug.

http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=map-get-always-null.vala;att=1;bug=543249
Comment 1 Sebastian Dröge (slomo) 2009-08-24 07:33:23 UTC
The problem apparently is, that vala compiles this to a hashmap that uses the pointer to the key as hash and comparing it as equality function.

Now the hashmap internally strdups the key, resulting in a new pointer that is not known outside the hashmap. Asking for the old key will never give a result because new_key != old_key
Comment 2 Sebastian Dröge (slomo) 2009-08-24 07:39:51 UTC
Changing it to
Gee.HashMap<string,string> map = new Gee.HashMap<string,string>(GLib.str_hash, GLib.str_equal, GLib.str_equal);

makes it work. Not sure if there's anything to fix here
Comment 3 Sebastian Dröge (slomo) 2009-08-24 09:26:33 UTC
Maybe the HashMap should assume that the keys passed are transfered ownership to the HashMap. This problem is not only specific to strings but to everything (except scalar types) because in any case the copy function is called for the keys before storing them. And a copy function will change the output of a direct hash (unless the copy really is a g_object_ref() ).
Comment 4 Maciej (Matthew) Piechotka 2009-09-21 19:35:30 UTC
Current implementation special cases the strings.
Comment 5 Didier "Ptitjes" 2009-09-28 17:50:11 UTC
commit 23721f320c6cd3a13e54731ddcfe28442cfa2b63
Author: Didier 'Ptitjes <ptitjes@free.fr>
Date:   Mon Sep 28 19:44:32 2009 +0200

    Fix the documentation of all implementations' constructor
    
    Fixes bug 592817.

Now the constructors of all implementations and the Functions function factory are well documented. Sane defaults are provided for (non-boxed) primitive, string and object types (with a special care for those inheriting Gee.Comparable) as explained in the documentation.

Closing the bug. Could you, Sebastian, please close the one of Debian ? Thank you.