[glib/wip/refptr: 3/5] gobject: Add a boxed type for string references
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/refptr: 3/5] gobject: Add a boxed type for string references
- Date: Sun, 8 Feb 2015 13:41:15 +0000 (UTC)
commit 9541fbabeaa07a6b3ba20eb430f0569c5059126a
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Jan 27 11:08:28 2015 +0000
gobject: Add a boxed type for string references
Pretty simple boxed wrapper using the GRef API directly.
https://bugzilla.gnome.org/show_bug.cgi?id=622721
gobject/gboxed.c | 30 ++++++++++++++++++++++++++++++
gobject/glib-types.h | 20 ++++++++++++++++++++
gobject/gobject-autocleanups.h | 1 +
gobject/gvaluetypes.c | 6 ++++++
4 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/gobject/gboxed.c b/gobject/gboxed.c
index ca7f66c..5345eec 100644
--- a/gobject/gboxed.c
+++ b/gobject/gboxed.c
@@ -184,6 +184,36 @@ g_strv_get_type (void)
return g_define_type_id__volatile;
}
+/* This one can't use G_DEFINE_BOXED_TYPE (GStringRef, g_string_ref, g_string_ref, g_string_unref)
+ *
+ * We also use the g_ref_pointer_* API directly because the g_string_ref/unref
+ * functions are inlined and hidden by a macro, so we can't use them as function
+ * pointers.
+ */
+GType
+g_string_ref_get_type (void)
+{
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile))
+ {
+ GType g_define_type_id =
+ g_boxed_type_register_static (g_intern_static_string ("GStringRef"),
+ (GBoxedCopyFunc) g_ref_pointer_acquire,
+ (GBoxedFreeFunc) g_ref_pointer_release);
+
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+ }
+
+ return g_define_type_id__volatile;
+}
+
+/**
+ * g_variant_get_gtype:
+ *
+ * Since: 2.24
+ * Deprecated: 2.26
+ */
GType
g_variant_get_gtype (void)
{
diff --git a/gobject/glib-types.h b/gobject/glib-types.h
index e9f6472..75fc515 100644
--- a/gobject/glib-types.h
+++ b/gobject/glib-types.h
@@ -288,6 +288,15 @@ typedef gsize GType;
*/
#define G_TYPE_CHECKSUM (g_checksum_get_type ())
+/**
+ * G_TYPE_STRING_REF:
+ *
+ * The #GType for a boxed type holding a string reference.
+ *
+ * Since: 2.44
+ */
+#define G_TYPE_STRING_REF (g_string_ref_get_type ())
+
GLIB_AVAILABLE_IN_ALL
GType g_date_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL
@@ -342,6 +351,8 @@ GLIB_AVAILABLE_IN_2_36
GType g_markup_parse_context_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_2_40
GType g_mapped_file_get_type (void) G_GNUC_CONST;
+GLIB_AVAILABLE_IN_2_44
+GType g_string_ref_get_type (void) G_GNUC_CONST;
GLIB_DEPRECATED_FOR('G_TYPE_VARIANT')
GType g_variant_get_gtype (void) G_GNUC_CONST;
@@ -353,6 +364,15 @@ GType g_variant_get_gtype (void) G_GNUC_CONST;
*/
typedef gchar** GStrv;
+/**
+ * GStringRef:
+ *
+ * A C representable type for #G_TYPE_STRING_REF.
+ *
+ * Since: 2.44
+ */
+typedef char* GStringRef;
+
G_END_DECLS
#endif /* __GLIB_TYPES_H__ */
diff --git a/gobject/gobject-autocleanups.h b/gobject/gobject-autocleanups.h
index a871141..fea0985 100644
--- a/gobject/gobject-autocleanups.h
+++ b/gobject/gobject-autocleanups.h
@@ -22,5 +22,6 @@
#endif
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
+G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStringRef, g_string_unref, NULL)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref)
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GValue, g_value_unset)
diff --git a/gobject/gvaluetypes.c b/gobject/gvaluetypes.c
index 4b234a3..5a67b74 100644
--- a/gobject/gvaluetypes.c
+++ b/gobject/gvaluetypes.c
@@ -1397,6 +1397,12 @@ g_strdup_value_contents (const GValue *value)
g_string_append (tmp, "]");
contents = g_string_free (tmp, FALSE);
}
+ else if (G_VALUE_HOLDS (value, G_TYPE_STRING_REF))
+ {
+ GStringRef str = g_value_get_boxed (value);
+
+ contents = g_strdup_printf ("\"%s\"", str);
+ }
else if (G_VALUE_HOLDS_BOXED (value))
contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
else if (G_VALUE_HOLDS_POINTER (value))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]