Deprecate GValueArray

The GValueArray type was added in a time, during the Jurassic era or so,
when GArray did not have a representable GType. The GValueArray API has
various issues as well:

  - it doesn't match the other GLib array types;
  - it is not reference counted;
  - the structure is fully exposed on the stack, so it cannot be
    extended to add reference counting;
  - it cannot be forcibly resized.

The nice thing is that now we have a GArray type that can replace in
full GValueArray, so we can deprecate the latter, and reduce the
complexity in GLib, application code, and bindings.

https://bugzilla.gnome.org/show_bug.cgi?id=667228
This commit is contained in:
Emmanuele Bassi 2012-01-04 09:31:12 +00:00 committed by Matthias Clasen
parent c602a5f887
commit 0ac9ab4e27
7 changed files with 74 additions and 2 deletions

View File

@ -21,11 +21,14 @@
#include <string.h>
/* for GValueArray */
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include "gboxed.h"
#include "gclosure.h"
#include "gtype-private.h"
#include "gvalue.h"
#include "gvaluearray.h"
#include "gclosure.h"
#include "gvaluecollector.h"

View File

@ -111,11 +111,15 @@ GType g_boxed_type_register_static (const gchar *name,
*
* The type ID of the "GValueArray" type which is a boxed type,
* used to pass around pointers to GValueArrays.
*
* Deprecated: 2.32: Use #GArray instead of #GValueArray
*/
#define G_TYPE_VALUE_ARRAY (g_value_array_get_type ())
GType g_closure_get_type (void) G_GNUC_CONST;
GType g_value_get_type (void) G_GNUC_CONST;
GLIB_DEPRECATED
GType g_value_array_get_type (void) G_GNUC_CONST;
G_END_DECLS

View File

@ -26,9 +26,12 @@
#include <string.h>
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include "gparamspecs.h"
#include "gtype-private.h"
#include "gvaluecollector.h"
#include "gvaluearray.h"

View File

@ -451,6 +451,8 @@ G_BEGIN_DECLS
* G_TYPE_PARAM_VALUE_ARRAY:
*
* The #GType of #GParamSpecValueArray.
*
* Deprecated: 2.32: Use #GArray instead of #GValueArray
*/
#define G_TYPE_PARAM_VALUE_ARRAY (g_param_spec_types[18])
/**
@ -460,6 +462,8 @@ G_BEGIN_DECLS
* Checks whether the given #GParamSpec is of type %G_TYPE_PARAM_VALUE_ARRAY.
*
* Returns: %TRUE on success.
*
* Deprecated: 2.32: Use #GArray instead of #GValueArray
*/
#define G_IS_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM_VALUE_ARRAY))
/**
@ -467,6 +471,8 @@ G_BEGIN_DECLS
* @pspec: a valid #GParamSpec instance
*
* Cast a #GParamSpec instance into a #GParamSpecValueArray.
*
* Deprecated: 2.32: Use #GArray instead of #GValueArray
*/
#define G_PARAM_SPEC_VALUE_ARRAY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM_VALUE_ARRAY, GParamSpecValueArray))

View File

@ -40,6 +40,23 @@
* object property that holds an array of values. A #GValueArray wraps
* an array of #GValue elements in order for it to be used as a boxed
* type through %G_TYPE_VALUE_ARRAY.
*
* #GValueArray is deprecated in favour of #GArray since GLib 2.32. It
* is possible to create a #GArray that behaves like a #GValueArray by
* using the size of #GValue as the element size, and by setting
* g_value_unset() as the clear function using g_array_set_clear_func(),
* for instance, the following code:
*
* |[
* GValueArray *array = g_value_array_new (10);
* |]
*
* can be replaced by:
*
* |[
* GArray *array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 10);
* g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
* ]|
*/
@ -59,6 +76,8 @@
* Return a pointer to the value at @index_ containd in @value_array.
*
* Returns: (transfer none): pointer to a value at @index_ in @value_array
*
* Deprecated: 2.32: Use g_array_index() instead.
*/
GValue*
g_value_array_get_nth (GValueArray *value_array,
@ -112,6 +131,8 @@ value_array_shrink (GValueArray *value_array)
* regardless of the value of @n_prealloced.
*
* Returns: a newly allocated #GValueArray with 0 values
*
* Deprecated: 2.32: Use #GArray and g_array_sized_new() instead.
*/
GValueArray*
g_value_array_new (guint n_prealloced)
@ -132,6 +153,8 @@ g_value_array_new (guint n_prealloced)
* @value_array: #GValueArray to free
*
* Free a #GValueArray including its contents.
*
* Deprecated: 2.32: Use #GArray and g_array_unref() instead.
*/
void
g_value_array_free (GValueArray *value_array)
@ -159,6 +182,8 @@ g_value_array_free (GValueArray *value_array)
* contents.
*
* Returns: (transfer full): Newly allocated copy of #GValueArray
*
* Deprecated: 2.32: Use #GArray and g_array_ref() instead.
*/
GValueArray*
g_value_array_copy (const GValueArray *value_array)
@ -194,6 +219,8 @@ g_value_array_copy (const GValueArray *value_array)
*
*
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_prepend_val() instead.
*/
GValueArray*
g_value_array_prepend (GValueArray *value_array,
@ -213,6 +240,8 @@ g_value_array_prepend (GValueArray *value_array,
* %NULL, an uninitialized value is appended.
*
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_append_val() instead.
*/
GValueArray*
g_value_array_append (GValueArray *value_array,
@ -233,6 +262,8 @@ g_value_array_append (GValueArray *value_array,
* is %NULL, an uninitialized value is inserted.
*
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_insert_val() instead.
*/
GValueArray*
g_value_array_insert (GValueArray *value_array,
@ -268,6 +299,8 @@ g_value_array_insert (GValueArray *value_array,
* Remove the value at position @index_ from @value_array.
*
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_remove_index() instead.
*/
GValueArray*
g_value_array_remove (GValueArray *value_array,
@ -300,6 +333,8 @@ g_value_array_remove (GValueArray *value_array,
* The current implementation uses Quick-Sort as sorting algorithm.
*
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_sort().
*/
GValueArray*
g_value_array_sort (GValueArray *value_array,
@ -328,6 +363,8 @@ g_value_array_sort (GValueArray *value_array,
*
* Rename to: g_value_array_sort
* Returns: (transfer none): the #GValueArray passed in as @value_array
*
* Deprecated: 2.32: Use #GArray and g_array_sort_with_data().
*/
GValueArray*
g_value_array_sort_with_data (GValueArray *value_array,

View File

@ -27,7 +27,6 @@
#include <gobject/gvalue.h>
G_BEGIN_DECLS
@ -51,22 +50,41 @@ struct _GValueArray
/* --- prototypes --- */
GLIB_DEPRECATED_FOR(g_array_index)
GValue* g_value_array_get_nth (GValueArray *value_array,
guint index_);
GLIB_DEPRECATED_FOR(g_array_new)
GValueArray* g_value_array_new (guint n_prealloced);
GLIB_DEPRECATED_FOR(g_array_unref)
void g_value_array_free (GValueArray *value_array);
GLIB_DEPRECATED_FOR(g_array_ref)
GValueArray* g_value_array_copy (const GValueArray *value_array);
GLIB_DEPRECATED_FOR(g_array_prepend_vals)
GValueArray* g_value_array_prepend (GValueArray *value_array,
const GValue *value);
GLIB_DEPRECATED_FOR(g_array_append_vals)
GValueArray* g_value_array_append (GValueArray *value_array,
const GValue *value);
GLIB_DEPRECATED_FOR(g_array_insert_vals)
GValueArray* g_value_array_insert (GValueArray *value_array,
guint index_,
const GValue *value);
GLIB_DEPRECATED_FOR(g_array_remove_index)
GValueArray* g_value_array_remove (GValueArray *value_array,
guint index_);
GLIB_DEPRECATED_FOR(g_array_sort)
GValueArray* g_value_array_sort (GValueArray *value_array,
GCompareFunc compare_func);
GLIB_DEPRECATED_FOR(g_array_sort_with_data)
GValueArray* g_value_array_sort_with_data (GValueArray *value_array,
GCompareDataFunc compare_func,
gpointer user_data);

View File

@ -1,3 +1,4 @@
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include <glib-object.h>
static gint