Skip to content

Fix GtkWidgetClassPrivate data usage

Before this commit, adding GtkWidgetAction to class private data would require copying the actions to each subclass as they were built or modified. This was convenient in that it is a sort of "copy on write" semantic.

However, due to the way that GTypeInstance works with base _init() functions, the "g_class" pointer in GTypeInstance is updated as each _init() function is called. That means you cannot access the subclasses class private data, but only the parent class private data.

If instead we use a singly linked list of GtkWidgetAction, each subclass has their own "head" yet all subclasses share the tail of the GtkWidgetAction chain.

This creates one bit of complexity though. You need a stable way to know which "bit" is the "enabled" bit of the action so we can track enabled GAction state. That is easily solved by calculating the distance to the end of the chain for a given action so that base classes sort ahead of subclasses. Since the parent class always knows its parent's actions, the position is stable.

A new dynamic bitarray helper also helps us avoid allocations in all the current cases (up to 64 actions per widget) and dynamically switches to malloc if that is to ever be exceeded.

Merge request reports