From dbbd9c60baa2892ee570aa7809b27c5f4d21e234 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sun, 31 Dec 2023 09:09:48 +0000 Subject: [PATCH] Add boxed GType for GRand Signed-off-by: Tanmay Patil --- gobject/gboxed.c | 1 + gobject/glib-types.h | 11 +++++++++++ gobject/tests/boxed.c | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/gobject/gboxed.c b/gobject/gboxed.c index 5a9cff85a..04cededa0 100644 --- a/gobject/gboxed.c +++ b/gobject/gboxed.c @@ -140,6 +140,7 @@ G_DEFINE_BOXED_TYPE (GMappedFile, g_mapped_file, g_mapped_file_ref, g_mapped_fil G_DEFINE_BOXED_TYPE (GBookmarkFile, g_bookmark_file, g_bookmark_file_copy, g_bookmark_file_free) G_DEFINE_BOXED_TYPE (GHmac, g_hmac, g_hmac_ref, g_hmac_unref) G_DEFINE_BOXED_TYPE (GDir, g_dir, g_dir_ref, g_dir_unref) +G_DEFINE_BOXED_TYPE (GRand, g_rand, g_rand_copy, g_rand_free) G_DEFINE_BOXED_TYPE (GMainLoop, g_main_loop, g_main_loop_ref, g_main_loop_unref) G_DEFINE_BOXED_TYPE (GMainContext, g_main_context, g_main_context_ref, g_main_context_unref) diff --git a/gobject/glib-types.h b/gobject/glib-types.h index 76f746cf2..e31baf144 100644 --- a/gobject/glib-types.h +++ b/gobject/glib-types.h @@ -354,6 +354,15 @@ typedef gsize GType; */ #define G_TYPE_DIR (g_dir_get_type ()) +/** + * G_TYPE_RAND: + * + * The #GType for a boxed type holding a #GRand. + * + * Since: 2.80 + */ +#define G_TYPE_RAND (g_rand_get_type ()) + /** * G_TYPE_STRV_BUILDER: * @@ -432,6 +441,8 @@ GType g_hmac_get_type (void) G_GNUC_CONST; GOBJECT_AVAILABLE_IN_2_80 GType g_dir_get_type (void) G_GNUC_CONST; GOBJECT_AVAILABLE_IN_2_80 +GType g_rand_get_type (void) G_GNUC_CONST; +GOBJECT_AVAILABLE_IN_2_80 GType g_strv_builder_get_type (void) G_GNUC_CONST; GOBJECT_DEPRECATED_FOR('G_TYPE_VARIANT') diff --git a/gobject/tests/boxed.c b/gobject/tests/boxed.c index 4d3f4ea6f..c683ed8d0 100644 --- a/gobject/tests/boxed.c +++ b/gobject/tests/boxed.c @@ -668,6 +668,28 @@ test_boxed_pattern_spec (void) g_value_unset (&value); } +static void +test_boxed_rand (void) +{ + GRand *r, *r2; + GValue value = G_VALUE_INIT; + + g_value_init (&value, G_TYPE_RAND); + g_assert_true (G_VALUE_HOLDS_BOXED (&value)); + + r = g_rand_new (); + g_value_take_boxed (&value, r); + + r2 = g_value_get_boxed (&value); + g_assert_true (r == r2); + + r2 = g_value_dup_boxed (&value); + g_assert_true (r != r2); + g_rand_free (r2); + + g_value_unset (&value); +} + int main (int argc, char *argv[]) { @@ -699,6 +721,7 @@ main (int argc, char *argv[]) g_test_add_func ("/boxed/checksum", test_boxed_checksum); g_test_add_func ("/boxed/tree", test_boxed_tree); g_test_add_func ("/boxed/patternspec", test_boxed_pattern_spec); + g_test_add_func ("/boxed/rand", test_boxed_rand); return g_test_run (); }