[glib] gmarkup: Make GMarkupParseContext a boxed type
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gmarkup: Make GMarkupParseContext a boxed type
- Date: Tue, 1 Jan 2013 16:02:45 +0000 (UTC)
commit 5e62827efdf8a6efbf48e5ed88e02ec4e3a40329
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Jul 3 15:14:18 2012 -0400
gmarkup: Make GMarkupParseContext a boxed type
At the same time, add a refcount and public ref/unref methods.
This makes it usable from introspectable.
https://bugzilla.gnome.org/show_bug.cgi?id=690084
docs/reference/glib/glib-sections.txt | 2 +
docs/reference/gobject/gobject-sections.txt | 1 +
glib/glib.symbols | 2 +
glib/gmarkup.c | 44 +++++++++++++++++++++++++++
glib/gmarkup.h | 4 ++
gobject/gboxed.c | 1 +
gobject/glib-types.h | 11 +++++++
gobject/gobject.symbols | 1 +
8 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index c3f694a..e12a855 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1127,6 +1127,8 @@ g_markup_parse_context_new
g_markup_parse_context_parse
g_markup_parse_context_push
g_markup_parse_context_pop
+g_markup_parse_context_ref
+g_markup_parse_context_unref
<SUBSECTION>
GMarkupCollectType
g_markup_collect_attributes
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 4b48e3e..a85699b 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -373,6 +373,7 @@ G_TYPE_VARIANT_BUILDER
G_TYPE_KEY_FILE
G_TYPE_MAIN_CONTEXT
G_TYPE_MAIN_LOOP
+G_TYPE_MARKUP_PARSE_CONTEXT
G_TYPE_SOURCE
G_TYPE_POLLFD
G_TYPE_THREAD
diff --git a/glib/glib.symbols b/glib/glib.symbols
index d48b39d..724e8d9 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -684,6 +684,8 @@ g_markup_parse_context_new
g_markup_parse_context_parse
g_markup_parse_context_push
g_markup_parse_context_pop
+g_markup_parse_context_ref
+g_markup_parse_context_unref
g_markup_printf_escaped
g_markup_vprintf_escaped
g_markup_collect_attributes
diff --git a/glib/gmarkup.c b/glib/gmarkup.c
index f424026..11f68de 100644
--- a/glib/gmarkup.c
+++ b/glib/gmarkup.c
@@ -29,6 +29,7 @@
#include "gmarkup.h"
+#include "gatomic.h"
#include "gslice.h"
#include "galloca.h"
#include "gstrfuncs.h"
@@ -117,6 +118,8 @@ struct _GMarkupParseContext
{
const GMarkupParser *parser;
+ volatile gint ref_count;
+
GMarkupParseFlags flags;
gint line_number;
@@ -224,6 +227,7 @@ g_markup_parse_context_new (const GMarkupParser *parser,
context = g_new (GMarkupParseContext, 1);
+ context->ref_count = 1;
context->parser = parser;
context->flags = flags;
context->user_data = user_data;
@@ -266,6 +270,46 @@ g_markup_parse_context_new (const GMarkupParser *parser,
return context;
}
+/**
+ * g_markup_parse_context_ref:
+ * @context: a #GMarkupParseContext
+ *
+ * Increases the reference count of @context.
+ *
+ * Returns: the same @context
+ *
+ * Since: 2.36
+ **/
+GMarkupParseContext *
+g_markup_parse_context_ref (GMarkupParseContext *context)
+{
+ g_return_val_if_fail (context != NULL, NULL);
+ g_return_val_if_fail (context->ref_count > 0, NULL);
+
+ g_atomic_int_inc (&context->ref_count);
+
+ return context;
+}
+
+/**
+ * g_markup_parse_context_unref:
+ * @context: a #GMarkupParseContext
+ *
+ * Decreases the reference count of @context. When its reference count
+ * drops to 0, it is freed.
+ *
+ * Since: 2.36
+ **/
+void
+g_markup_parse_context_unref (GMarkupParseContext *context)
+{
+ g_return_if_fail (context != NULL);
+ g_return_if_fail (context->ref_count > 0);
+
+ if (g_atomic_int_dec_and_test (&context->ref_count))
+ g_markup_parse_context_free (context);
+}
+
static void
string_full_free (gpointer ptr)
{
diff --git a/glib/gmarkup.h b/glib/gmarkup.h
index b50df4f..d26c2ad 100644
--- a/glib/gmarkup.h
+++ b/glib/gmarkup.h
@@ -182,6 +182,10 @@ GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
GMarkupParseFlags flags,
gpointer user_data,
GDestroyNotify user_data_dnotify);
+GLIB_AVAILABLE_IN_2_36
+GMarkupParseContext *g_markup_parse_context_ref (GMarkupParseContext *context);
+GLIB_AVAILABLE_IN_2_36
+void g_markup_parse_context_unref (GMarkupParseContext *context);
void g_markup_parse_context_free (GMarkupParseContext *context);
gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
diff --git a/gobject/gboxed.c b/gobject/gboxed.c
index 65e6bb4..7bac5e1 100644
--- a/gobject/gboxed.c
+++ b/gobject/gboxed.c
@@ -160,6 +160,7 @@ 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)
G_DEFINE_BOXED_TYPE (GSource, g_source, g_source_ref, g_source_unref)
G_DEFINE_BOXED_TYPE (GPollFD, g_pollfd, pollfd_copy, g_free)
+G_DEFINE_BOXED_TYPE (GMarkupParseContext, g_markup_parse_context, g_markup_parse_context_ref, g_markup_parse_context_unref)
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)
diff --git a/gobject/glib-types.h b/gobject/glib-types.h
index f36e21a..47382fa 100644
--- a/gobject/glib-types.h
+++ b/gobject/glib-types.h
@@ -237,6 +237,15 @@ typedef gsize GType;
#define G_TYPE_POLLFD (g_pollfd_get_type ())
/**
+ * G_TYPE_MARKUP_PARSE_CONTEXT:
+ *
+ * The #GType for a boxed type holding a #GMarkupParseContext.
+ *
+ * Since: 2.36
+ */
+#define G_TYPE_MARKUP_PARSE_CONTEXT (g_markup_parse_context_get_type ())
+
+/**
* G_TYPE_KEY_FILE:
*
* The #GType for a boxed type holding a #GKeyFile.
@@ -294,6 +303,8 @@ GLIB_AVAILABLE_IN_2_36
GType g_thread_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_2_36
GType g_checksum_get_type (void) G_GNUC_CONST;
+GLIB_AVAILABLE_IN_2_36
+GType g_markup_parse_context_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/gobject.symbols b/gobject/gobject.symbols
index 443cf5b..8dd69ba 100644
--- a/gobject/gobject.symbols
+++ b/gobject/gobject.symbols
@@ -32,6 +32,7 @@ g_variant_type_get_gtype
g_key_file_get_type
g_main_loop_get_type
g_main_context_get_type
+g_markup_parse_context_get_type
g_source_get_type
g_pollfd_get_type
g_closure_get_type
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]