GNOME Bugzilla – Bug 628253
Interface properties not listed in a consistent order
Last modified: 2010-12-31 04:37:19 UTC
This is a curious bug... it seems that g_object_class_list_properties() no longer lists interface properties in a consistent order across invocations of libgobject. This is the root cause of Glade bug 626328 (some interface properties saved in an inconsistent order). Attached is a simple test case in C that should be compiled with GTK+ master for a demonstration of the problem. Just run the test a few times in a row and note that "use-action-appearance" and "related-action" dont always get listed in the same order.
You seem to have forgotten to attach the test case.
Created attachment 169010 [details] Test case
I don't think g_object_class_list_properties is meant to give you any guarantees about the order of properties. If you rely on an unchanging order, you should sort the returned list.
Could be it was not intended to be a consistent order, but we've been relying on the order being consistent... its also very curious (and even disturbing) that the exact same program performs differently across consecutive executions. Also, property ordering in GtkBuilder output is not 100% arbitrary (take GtkAdjustment:min/max/value for example) so using a new order; such as alphabetical order... could very well introduce some new bugs at GtkBuilder's show time (of course we try to special-case-order the output for cases where bug reports show that the natural order of _list_properties() is not good enough... but it's best to keep the special casing to a minimum). Ideally ... I think _list_properties() should return properties in the real order in which they were installed on the object class In this way a widget can intentionally install properties in the order in which it expects them to be set at g_object_new() time. (actually... I thought they were always returned in their natural order in the past... maybe something radically changed or they were always at least consistently ordered arbitrarily).
Hmmm I wonder if we can easily extract which numeric id was assigned to each property by each class... in this way Glade could sort in a meaningful order: ordered by id descending from the root class.
It becomes clear what is happening here if you make your testcase print out the owner_type and param_id: GtkActivatable 0 use-action-appearance GtkActivatable 0 related-action GtkObject 1 user-data GtkWidget 1 name GtkWidget 2 parent GtkWidget 3 width-request GtkWidget 4 height-request GtkWidget 5 visible GtkWidget 6 sensitive GtkWidget 7 app-paintable GtkWidget 8 can-focus GtkWidget 9 has-focus GtkWidget 10 is-focus GtkWidget 11 can-default GtkWidget 12 has-default GtkWidget 13 receives-default GtkWidget 14 composite-child GtkWidget 15 style GtkWidget 16 events GtkWidget 17 extension-events GtkWidget 18 no-show-all GtkWidget 19 has-tooltip GtkWidget 20 tooltip-markup GtkWidget 21 tooltip-text GtkWidget 22 window GtkWidget 23 double-buffered GtkContainer 1 border-width GtkContainer 2 resize-mode GtkContainer 3 child GtkButton 1 label ... g_object_class_list_properties actually sorts by 'type depth' and param_id. Unfortunately, overridden interface properties all get installed with param_id 0, so the sorting is noneffective for them.
commit c75429d0a0564c3620c6f72afea9838f661c4e88 Author: Matthias Clasen <mclasen@redhat.com> Date: Fri Sep 3 14:52:16 2010 -0400 Make ordering for overridden interface properties consistent g_object_class_list_properties tries to sort the returned list of paramspecs by 'type depth' and param_id. But all the overridden interface properties have a param_id of 0, so they come out in a random order. Bug 628253.
*** Bug 626328 has been marked as a duplicate of this bug. ***