GNOME Bugzilla – Bug 753522
Add replacement API for GValueArray
Last modified: 2018-05-24 18:02:24 UTC
GValueArray has been deprecated by bug 667228 because it's a terrible, terrible API that we cannot fix in any sensible way. Sadly, GValueArray *did* some things in an easy way, and dealing with GValues inside a GArray is not entirely fun and games. Instead of creating a new type, we should have additional methods, provided by GObject, to initialize and populate a GArray with GValues, thus closing the hole. We could have something like: GArray * g_value_init_array (GType value_type); GArray * g_value_init_array_sized (GType value_type, gsize n_values); to initialize a GArray-of-GValues and pre-initialize it; it would also add a clear function automatically; then you could simply get the pointer GValue at the wanted index, and populate it with the wanted value.
One thing that must be possible is to check the element type of an arbitrary "GArray with GValues" at runtime, even for an empty one.
Getting the value_type out of the GArray is going to be tricky. We could always allocate a GArray with at least 1 element, so that we can do something like: #define g_value_get_array_value_type(array) \ (G_VALUE_TYPE ((const GValue *) (array->data[0]))) Or we could fudge around with some alignment holes.
What you suggest with using GArray directly is not solving all problems though. You can't know when you get an GArray if it contains GValues or some other things... unless you look at the documentation or the GI annotations (which are not useable for GStreamer plugins!). I think this should be a GValueArrayNew (find a better name :) ) similar to GPtrArray and GByteArray. That can then also hold the element GType somewhere.
I would be happy to work on patches for GValueArrayNew, but before I'd like to check what would be a viable approach so it could be accepted to glib. From what I could read, a GValueArrayNew should: (1) define it's own GType, so it can be distinguished from a generic GArray (like GPtrArray GByteArray) (2) internally use GArray with GValue elements (3) have the constructor take a GType describing the content of its GValue elements. This optionally can be G_TYPE_NONE to allow arrays with non-homogeneous GValue types, i.e. to express something like GValue tuples. (4) store the GType somewhere. Since we'd like to allow G_TYPE_NONE, storing the type in a pre-allocated first element is not ideal. I'd probably just start having the private struct of GValueArrayNew store a GArray * and additionally a GType field. (5) add API that takes/gives GValue directly. If the array requires homogenous array types, have this API check that types are matching. what do you think?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1069.