[glib/wip/hadess/add-memory-monitor: 198/202] Add G_TYPE_UUID
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/hadess/add-memory-monitor: 198/202] Add G_TYPE_UUID
- Date: Thu, 19 Sep 2019 10:26:24 +0000 (UTC)
commit c0f1614bff9f8cc24e8ca0b5c978b736408c5d08
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Sat Jan 19 17:50:50 2013 +0100
Add G_TYPE_UUID
https://bugzilla.gnome.org/show_bug.cgi?id=639078
docs/reference/gobject/gobject-sections.txt | 1 +
gobject/gboxed.c | 9 +++++++++
gobject/glib-types.h | 11 +++++++++++
gobject/tests/boxed.c | 27 +++++++++++++++++++++++++++
4 files changed, 48 insertions(+)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index bed38e4c5..90cb39773 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -408,6 +408,7 @@ G_TYPE_SOURCE
G_TYPE_POLLFD
G_TYPE_THREAD
G_TYPE_OPTION_GROUP
+G_TYPE_UUID
<SUBSECTION Standard>
G_TYPE_IS_BOXED
diff --git a/gobject/gboxed.c b/gobject/gboxed.c
index 87cc5d2c2..005de6058 100644
--- a/gobject/gboxed.c
+++ b/gobject/gboxed.c
@@ -95,6 +95,14 @@ pollfd_copy (GPollFD *src)
return dest;
}
+static GUuid *
+uuid_copy (GUuid *src)
+{
+ GUuid *dest = g_new (GUuid, 1);
+ memcpy (dest, src, sizeof (GUuid));
+ return dest;
+}
+
void
_g_boxed_type_init (void)
{
@@ -169,6 +177,7 @@ G_DEFINE_BOXED_TYPE (GMarkupParseContext, g_markup_parse_context, g_markup_parse
G_DEFINE_BOXED_TYPE (GThread, g_thread, g_thread_ref, g_thread_unref)
G_DEFINE_BOXED_TYPE (GChecksum, g_checksum, g_checksum_copy, g_checksum_free)
+G_DEFINE_BOXED_TYPE (GUuid, g_uuid, uuid_copy, g_free)
G_DEFINE_BOXED_TYPE (GOptionGroup, g_option_group, g_option_group_ref, g_option_group_unref)
diff --git a/gobject/glib-types.h b/gobject/glib-types.h
index 78a199d1d..7190f2e4a 100644
--- a/gobject/glib-types.h
+++ b/gobject/glib-types.h
@@ -297,6 +297,15 @@ typedef gsize GType;
*/
#define G_TYPE_OPTION_GROUP (g_option_group_get_type ())
+/**
+ * G_TYPE_UUID:
+ *
+ * The #GType for a boxed type holding a #GUuid.
+ *
+ * Since: 2.48
+ */
+#define G_TYPE_UUID (g_uuid_get_type ())
+
GLIB_AVAILABLE_IN_ALL
GType g_date_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL
@@ -353,6 +362,8 @@ GLIB_AVAILABLE_IN_2_40
GType g_mapped_file_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_2_44
GType g_option_group_get_type (void) G_GNUC_CONST;
+GLIB_AVAILABLE_IN_2_48
+GType g_uuid_get_type (void) G_GNUC_CONST;
GLIB_DEPRECATED_FOR('G_TYPE_VARIANT')
GType g_variant_get_gtype (void) G_GNUC_CONST;
diff --git a/gobject/tests/boxed.c b/gobject/tests/boxed.c
index 70e3ea762..eff50346c 100644
--- a/gobject/tests/boxed.c
+++ b/gobject/tests/boxed.c
@@ -366,6 +366,32 @@ test_boxed_datetime (void)
g_value_unset (&value);
}
+static void
+test_boxed_uuid (void)
+{
+ GUuid v;
+ GUuid *v1;
+ GUuid *v2;
+ GValue value = G_VALUE_INIT;
+
+ g_value_init (&value, G_TYPE_UUID);
+ g_assert (G_VALUE_HOLDS_BOXED (&value));
+
+ g_uuid_generate_v4 (&v);
+ g_value_set_boxed (&value, &v);
+
+ v1 = g_value_dup_boxed (&value);
+ g_assert (v1 != &v); /* uuids are copied values */
+ g_assert (g_uuid_equal (v1, &v));
+ g_value_reset (&value);
+
+ g_value_take_boxed (&value, v1);
+ v2 = g_value_get_boxed (&value);
+ g_assert (v2 == v1);
+
+ g_value_unset (&value);
+}
+
static void
test_boxed_error (void)
{
@@ -644,6 +670,7 @@ main (int argc, char *argv[])
g_test_add_func ("/boxed/markup", test_boxed_markup);
g_test_add_func ("/boxed/thread", test_boxed_thread);
g_test_add_func ("/boxed/checksum", test_boxed_checksum);
+ g_test_add_func ("/boxed/uuid", test_boxed_uuid);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]