gtype: Add macro to get instance from instance private field pointer
@jadahl
Submitted by Jonas Ådahl Link to original bug (#763489)
Description
This patch adds a macro G_PRIVATE_OWNER_FROM_FIELD() that gets the GObject instance pointer given a pointer to some field in the private data structure.
An example of when this is useful is when having a 'struct wl_listener listener' field (a listener to wl_signal signals, part of libwayland-*).
When the listener is invoked, one is passed a "user_data" pointer and poniter to the listener itself. Usually the listener uses wl_container_of() to get the container of the listener to get the context as it may not always be possible to control the passed user data.
If such a listener is added to a derivable GObject, one cannot add the struct wl_listener lvalue to the GObject instance struct; it is instead added to the associated private data structure. On invokation, one still may need to get the corresponding GObject instance pointer, and this can be done using this macro.
I currently have this macro defined (unprefixed) locally on a topic branch where I use it to do what is described above, and thought it could possibly be useful to include in glib.