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 670969 - GSequence lookup may fail if there was no sort prior to lookup
GSequence lookup may fail if there was no sort prior to lookup
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-02-28 12:05 UTC by shuerhaaken
Modified: 2012-03-02 14:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase (999 bytes, text/x-csrc)
2012-02-28 13:18 UTC, shuerhaaken
  Details
proposed patch (1.82 KB, patch)
2012-02-28 16:54 UTC, shuerhaaken
none Details | Review
GSequence: add note about lookup requiring sorting (3.38 KB, patch)
2012-02-29 17:38 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description shuerhaaken 2012-02-28 12:05:38 UTC
If you add e.g. strings to a GSequence with 
the append method, then using the lookup function may fail in many cases and return null, even though the data is there.
If a sort was done prior using lookup or the insertion of data was done using insert_sorted, it always works as expected.

I think prepending and appending data to a GSequence should internally mark the it as dirty and sorting should mark it as clean.
A lookup to a dirty sequence should lead to a sort, which is done before the actual lookup.
Comment 1 Allison Karlitskaya (desrt) 2012-02-28 12:48:57 UTC
not sure i agree with this.  how do we know the user is not taking care to append items in sorted order?
Comment 2 shuerhaaken 2012-02-28 13:17:01 UTC
Ok. Good point. 
I came across this because it is not documented anywhere. If it was mentioned somewhere, I could have taken care.
Want a patch?
Comment 3 shuerhaaken 2012-02-28 13:18:21 UTC
Created attachment 208575 [details]
Testcase

Here is a testcase. The lookup fails in 50%
Comment 4 shuerhaaken 2012-02-28 16:54:43 UTC
Created attachment 208612 [details] [review]
proposed patch

Added proposed patch for documenting this special behaviour of GSequence.
Comment 5 Allison Karlitskaya (desrt) 2012-02-29 17:38:59 UTC
Created attachment 208704 [details] [review]
GSequence: add note about lookup requiring sorting

Here's an updated patch.  I tweaked the wording a little and copied it to g_sequence_search() as well (which is also affected by the same problem).

Does this look okay to you?
Comment 6 shuerhaaken 2012-02-29 22:51:55 UTC
Yes, okay for me.
Comment 7 Allison Karlitskaya (desrt) 2012-03-02 14:09:05 UTC
Attachment 208704 [details] pushed as 00f1e1f - GSequence: add note about lookup requiring sorting


Thanks for the report.