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
This commit is contained in:
Jasper St. Pierre 2012-07-03 15:14:18 -04:00 committed by Matthias Clasen
parent 157f80c244
commit 5e62827efd
8 changed files with 66 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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,

View File

@ -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)

View File

@ -236,6 +236,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:
*
@ -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;

View File

@ -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