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 753522 - Add replacement API for GValueArray
Add replacement API for GValueArray
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-08-11 15:10 UTC by Emmanuele Bassi (:ebassi)
Modified: 2018-05-24 18:02 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Emmanuele Bassi (:ebassi) 2015-08-11 15:10:11 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.
Comment 1 Sebastian Dröge (slomo) 2015-08-11 15:20:55 UTC
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.
Comment 2 Emmanuele Bassi (:ebassi) 2015-08-11 15:22:10 UTC
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.
Comment 3 Sebastian Dröge (slomo) 2016-05-13 07:53:00 UTC
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.
Comment 4 Heinrich Fink 2016-05-13 09:03:23 UTC
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?
Comment 5 GNOME Infrastructure Team 2018-05-24 18:02:24 UTC
-- 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.