mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
Merge branch 'ebassi/garray-revert' into 'main'
Revert "garray: Add support adding literal values" Closes #2846 See merge request GNOME/glib!3154
This commit is contained in:
commit
e82a257db9
@ -509,14 +509,8 @@ array_free (GRealArray *array,
|
|||||||
* size automatically if necessary.
|
* size automatically if necessary.
|
||||||
*
|
*
|
||||||
* g_array_append_val() is a macro which uses a reference to the value
|
* g_array_append_val() is a macro which uses a reference to the value
|
||||||
* parameter @v.
|
* parameter @v. This means that you cannot use it with literal values
|
||||||
* Until version 2.76 this meant that you could not use it with literal
|
* such as "27". You must use variables.
|
||||||
* values such as `27`. You had to use variables.
|
|
||||||
*
|
|
||||||
* Starting with version 2.76, if the compiler supports the `typeof` operator
|
|
||||||
* you can use it with both variables and literal values.
|
|
||||||
* However, it may be required to use the proper suffix (such as `15L`
|
|
||||||
* or `55UL`) or to explicitly cast the value to the #GArray elements type.
|
|
||||||
*
|
*
|
||||||
* Returns: the #GArray
|
* Returns: the #GArray
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <glib/gtypes.h>
|
#include <glib/gtypes.h>
|
||||||
#include <glib/glib-typeof.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -64,35 +63,9 @@ struct _GPtrArray
|
|||||||
* order by moving the last element to the position of the removed.
|
* order by moving the last element to the position of the removed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined (glib_typeof) && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_76 && defined (__GNUC__)
|
#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
|
||||||
#define g_array_append_val(a, v) \
|
#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
|
||||||
(G_GNUC_EXTENSION ({ \
|
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
|
||||||
glib_typeof ((v)) gaa_val_ = (v); \
|
|
||||||
g_array_append_vals ((a), &gaa_val_, 1); \
|
|
||||||
}))
|
|
||||||
|
|
||||||
#define g_array_prepend_val(a, v) \
|
|
||||||
(G_GNUC_EXTENSION ({ \
|
|
||||||
glib_typeof ((v)) gap_val_ = (v); \
|
|
||||||
g_array_prepend_vals ((a), &gap_val_, 1); \
|
|
||||||
}))
|
|
||||||
|
|
||||||
#define g_array_insert_val(a, i, v) \
|
|
||||||
(G_GNUC_EXTENSION ({ \
|
|
||||||
glib_typeof ((v)) gai_val_ = (v); \
|
|
||||||
g_array_insert_vals ((a), (i), &gai_val_, 1); \
|
|
||||||
}))
|
|
||||||
#else /* !defined (glib_typeof) || GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_76 */
|
|
||||||
#define g_array_append_val(a, v) \
|
|
||||||
g_array_append_vals ((a), &((v)), 1)
|
|
||||||
|
|
||||||
#define g_array_prepend_val(a, v) \
|
|
||||||
g_array_prepend_vals ((a), &((v)), 1)
|
|
||||||
|
|
||||||
#define g_array_insert_val(a, i, v) \
|
|
||||||
g_array_insert_vals ((a), (i), &((v)), 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
|
#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
|
||||||
|
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
|
||||||
|
|
||||||
/* Test data to be passed to any function which calls g_array_new(), providing
|
/* Test data to be passed to any function which calls g_array_new(), providing
|
||||||
* the parameters for that call. Most #GArray tests should be repeated for all
|
* the parameters for that call. Most #GArray tests should be repeated for all
|
||||||
* possible values of #ArrayTestData. */
|
* possible values of #ArrayTestData. */
|
||||||
@ -205,16 +204,8 @@ array_append_val (gconstpointer test_data)
|
|||||||
gint *segment;
|
gint *segment;
|
||||||
|
|
||||||
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
||||||
for (i = 0; i < 10000 - 1; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
g_array_append_val (garray, i);
|
g_array_append_val (garray, i);
|
||||||
|
|
||||||
#if defined (glib_typeof)
|
|
||||||
g_array_append_val (garray, 10000 - 1);
|
|
||||||
#else
|
|
||||||
i = 10000 - 1;
|
|
||||||
g_array_append_val (garray, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
assert_int_array_zero_terminated (config, garray);
|
assert_int_array_zero_terminated (config, garray);
|
||||||
|
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
@ -227,17 +218,6 @@ array_append_val (gconstpointer test_data)
|
|||||||
g_assert_cmpint (segment[10000], ==, 0);
|
g_assert_cmpint (segment[10000], ==, 0);
|
||||||
|
|
||||||
g_free (segment);
|
g_free (segment);
|
||||||
|
|
||||||
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gsize));
|
|
||||||
#if defined (glib_typeof)
|
|
||||||
g_array_append_val (garray, (gsize) 123);
|
|
||||||
#else
|
|
||||||
i = 123;
|
|
||||||
g_array_append_val (garray, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_assert_cmpuint (g_array_index (garray, gsize, 0), ==, 123);
|
|
||||||
g_array_unref (garray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that g_array_prepend_val() works correctly for various #GArray
|
/* Check that g_array_prepend_val() works correctly for various #GArray
|
||||||
@ -250,16 +230,8 @@ array_prepend_val (gconstpointer test_data)
|
|||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
||||||
for (i = 0; i < 99; i++)
|
for (i = 0; i < 100; i++)
|
||||||
g_array_prepend_val (garray, i);
|
g_array_prepend_val (garray, i);
|
||||||
|
|
||||||
#if defined (glib_typeof)
|
|
||||||
g_array_prepend_val (garray, 99);
|
|
||||||
#else
|
|
||||||
i = 99;
|
|
||||||
g_array_prepend_val (garray, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
assert_int_array_zero_terminated (config, garray);
|
assert_int_array_zero_terminated (config, garray);
|
||||||
|
|
||||||
for (i = 0; i < 100; i++)
|
for (i = 0; i < 100; i++)
|
||||||
@ -330,7 +302,7 @@ array_insert_vals (gconstpointer test_data)
|
|||||||
const gint expected_vals2[] = { 0, 2, 3, 1 };
|
const gint expected_vals2[] = { 0, 2, 3, 1 };
|
||||||
const gint expected_vals3[] = { 0, 2, 3, 1, 4 };
|
const gint expected_vals3[] = { 0, 2, 3, 1, 4 };
|
||||||
const gint expected_vals4[] = { 5, 0, 2, 3, 1, 4 };
|
const gint expected_vals4[] = { 5, 0, 2, 3, 1, 4 };
|
||||||
const gint expected_vals5[] = { 5, 0, 2, 55, 3, 1, 4, 0, 0, 0, 0, 6, 7 };
|
const gint expected_vals5[] = { 5, 0, 2, 3, 1, 4, 0, 0, 0, 0, 6, 7 };
|
||||||
|
|
||||||
/* Set up an array. */
|
/* Set up an array. */
|
||||||
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
garray = g_array_new (config->zero_terminated, config->clear_, sizeof (gint));
|
||||||
@ -372,14 +344,6 @@ array_insert_vals (gconstpointer test_data)
|
|||||||
assert_int_array_equal (garray, expected_vals4, G_N_ELEMENTS (expected_vals4));
|
assert_int_array_equal (garray, expected_vals4, G_N_ELEMENTS (expected_vals4));
|
||||||
assert_int_array_zero_terminated (config, garray);
|
assert_int_array_zero_terminated (config, garray);
|
||||||
|
|
||||||
/* Insert an element in the middle */
|
|
||||||
#if defined (glib_typeof)
|
|
||||||
g_array_insert_val (garray, garray->len / 2, 55);
|
|
||||||
#else
|
|
||||||
i = 55;
|
|
||||||
g_array_insert_val (garray, garray->len / 2, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Insert some elements off the end of the array. The behaviour here depends
|
/* Insert some elements off the end of the array. The behaviour here depends
|
||||||
* on whether the array clears entries. */
|
* on whether the array clears entries. */
|
||||||
garray_out = g_array_insert_vals (garray, garray->len + 4, vals + 6, 2);
|
garray_out = g_array_insert_vals (garray, garray->len + 4, vals + 6, 2);
|
||||||
@ -769,13 +733,7 @@ test_array_binary_search (void)
|
|||||||
|
|
||||||
/* Testing array of size 1 */
|
/* Testing array of size 1 */
|
||||||
garray = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
|
garray = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
|
||||||
#if defined (glib_typeof)
|
|
||||||
g_array_prepend_val (garray, 1u);
|
|
||||||
#else
|
|
||||||
i = 1;
|
i = 1;
|
||||||
g_array_prepend_val (garray, i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_array_append_val (garray, i);
|
g_array_append_val (garray, i);
|
||||||
|
|
||||||
g_assert_true (g_array_binary_search (garray, &i, cmpint, NULL));
|
g_assert_true (g_array_binary_search (garray, &i, cmpint, NULL));
|
||||||
|
Loading…
Reference in New Issue
Block a user