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 669730 - actor: Fix and improve add_child_at_index()
actor: Fix and improve add_child_at_index()
Status: RESOLVED FIXED
Product: clutter
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: clutter-maint
clutter-maint
Depends on:
Blocks:
 
 
Reported: 2012-02-09 08:29 UTC by Florian Müllner
Modified: 2012-02-13 23:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
actor: Fix add_child_at_index() for negative index (1008 bytes, patch)
2012-02-09 08:29 UTC, Florian Müllner
committed Details | Review
actor: Improve appending actors in add_child_at_index() (1.07 KB, patch)
2012-02-09 08:29 UTC, Florian Müllner
needs-work Details | Review
actor: Improve appending actors in add_child_at_index() (1.62 KB, patch)
2012-02-13 22:28 UTC, Florian Müllner
none Details | Review

Description Florian Müllner 2012-02-09 08:29:11 UTC
See patches - it might make sense to use

  index_ >= self->priv->n_children

in the last patch, though requesting an index of e.g. 4 and ending up with 3 might be confusing.
Comment 1 Florian Müllner 2012-02-09 08:29:15 UTC
Created attachment 207162 [details] [review]
actor: Fix add_child_at_index() for negative index

There is a typo in the check for a negative index: the index variable
should be index_, not index - unfortunately, the latter can still be
resolved to index(3), so compiler and linker are perfectly happy.
Comment 2 Florian Müllner 2012-02-09 08:29:18 UTC
Created attachment 207163 [details] [review]
actor: Improve appending actors in add_child_at_index()

Currently, add_child_at_index() allows to pass an index of 0 to
prepend, a negative index to append, or an existing position to
insert. Using an index of "last position + 1" (a.k.a. number of
elements) to append seems natural, so allow that as well.
Comment 3 Emmanuele Bassi (:ebassi) 2012-02-09 09:28:53 UTC
Review of attachment 207162 [details] [review]:

how on earth did that even manage to sneak in? damn and blast.
Comment 4 Emmanuele Bassi (:ebassi) 2012-02-09 09:42:06 UTC
Review of attachment 207163 [details] [review]:

I'm not overly convinced about this; it may mask off-by-one errors, and I haven't seen many cases of API actually allow this.

plus, it needs:

  - a check on the input, to ensure that only len, and not len + arbitrary number can be used
  - a note inside the documentation on the acceptable range

and probably set_child_at_index() should be modified as well to accept n_children as a valid value for appending.
Comment 5 Florian Müllner 2012-02-09 11:20:45 UTC
Comment on attachment 207162 [details] [review]
actor: Fix add_child_at_index() for negative index

Attachment 207162 [details] pushed as a023bb3 - actor: Fix add_child_at_index() for negative index

(In reply to comment #3)
> how on earth did that even manage to sneak in? damn and blast.

I guess there's type safety and C type safety (when in doubt, everything is an int) ...
Comment 6 Florian Müllner 2012-02-09 11:35:24 UTC
(In reply to comment #4)
> Review of attachment 207163 [details] [review]:
> 
> I'm not overly convinced about this; it may mask off-by-one errors, and I
> haven't seen many cases of API actually allow this.

We do in StBoxLayout :-)

(To be fair, our method is implemented as "add_child(); move_child();", so it's a lot more natural than this patch).

Also note that so far I only found a single place where we actually rely on that behavior, so it wouldn't be a big deal to treat that case in the shell. So feel free to reject the patch - it's not like I spent hours writing it ...



> plus, it needs:
> 
>   - a check on the input, to ensure that only len, and not len + arbitrary
> number can be used

I don't understand that comment - how could "input == len" match len + arbitrary number?


>   - a note inside the documentation on the acceptable range

Fair point.


> and probably set_child_at_index() should be modified as well to accept
> n_children as a valid value for appending.

Dito.
Comment 7 Emmanuele Bassi (:ebassi) 2012-02-09 12:11:06 UTC
I noticed that ClutterBox uses g_list_insert() directly, which allows appending by simply using an index >= than the list length - so at least there's prior art.

if you updated the documentation and set_child_at_index(), I'd accept the patch.
Comment 8 Emmanuele Bassi (:ebassi) 2012-02-13 22:14:54 UTC
after discussing about it, set_child_at_index() can stay as it is. the patch in attachment 207163 [details] [review] is just missing the documentation update.
Comment 9 Florian Müllner 2012-02-13 22:28:03 UTC
Created attachment 207499 [details] [review]
actor: Improve appending actors in add_child_at_index()

Sorry, I thought I had attached the fpasted version from IRC ...
Comment 10 Jasper St. Pierre (not reading bugmail) 2012-02-13 22:59:41 UTC
Sigh. Sorry, we're both working on removing deprecation errors from Clutter. I just pushed http://git.gnome.org/browse/clutter/commit/?id=e3151228958e66fc8a0271c6cffd26234aa9ab69 after IRC review from ebassi.

( For reference, my branch is at http://github.com/magcius/gnome-shell/tree/cb2 )