Use G_DEFINE_[BOXED|POINTER]_TYPE instead of handwritten code

Now that we have convenience macros to implement boxed and pointer
types, use them.
This commit is contained in:
Christian Persch 2008-05-24 16:08:28 +02:00
parent dc1999316d
commit 71e73ffdfb
7 changed files with 51 additions and 264 deletions

View File

@ -45,21 +45,8 @@
/* ---------------------------------------------------------------------------------------------------- */
/* See also https://bugzilla.gnome.org/show_bug.cgi?id=449565 ... */
#define _MY_DEFINE_BOXED_TYPE(TypeName, type_name) \
GType \
type_name##_get_type (void) \
{ \
static volatile gsize type_volatile = 0; \
if (g_once_init_enter (&type_volatile)) \
{ \
GType type = g_boxed_type_register_static (g_intern_static_string (#TypeName), \
(GBoxedCopyFunc) type_name##_ref, \
(GBoxedFreeFunc) type_name##_unref); \
g_once_init_leave (&type_volatile, type); \
} \
return (GType) type_volatile; \
}
#define _MY_DEFINE_BOXED_TYPE(TypeName, type_name) \
G_DEFINE_BOXED_TYPE (TypeName, type_name, type_name##_ref, type_name##_unref)
_MY_DEFINE_BOXED_TYPE (GDBusNodeInfo, g_dbus_node_info);
_MY_DEFINE_BOXED_TYPE (GDBusInterfaceInfo, g_dbus_interface_info);

View File

@ -336,23 +336,9 @@ _g_file_attribute_value_dup (const GFileAttributeValue *other)
return attr;
}
GType
g_file_attribute_info_list_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 (I_("GFileAttributeInfoList"),
(GBoxedCopyFunc) g_file_attribute_info_list_dup,
(GBoxedFreeFunc) g_file_attribute_info_list_unref);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
return g_define_type_id__volatile;
}
G_DEFINE_BOXED_TYPE (GFileAttributeInfoList, g_file_attribute_info_list,
g_file_attribute_info_list_dup,
g_file_attribute_info_list_unref)
static gboolean
valid_char (char c)

View File

@ -2147,23 +2147,9 @@ matcher_add (GFileAttributeMatcher *matcher,
g_array_append_val (matcher->more_sub_matchers, s);
}
GType
g_file_attribute_matcher_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 (I_("GFileAttributeMatcher"),
(GBoxedCopyFunc) g_file_attribute_matcher_ref,
(GBoxedFreeFunc) g_file_attribute_matcher_unref);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
return g_define_type_id__volatile;
}
G_DEFINE_BOXED_TYPE (GFileAttributeMatcher, g_file_attribute_matcher,
g_file_attribute_matcher_ref,
g_file_attribute_matcher_unref)
/**
* g_file_attribute_matcher_new:

View File

@ -65,21 +65,8 @@ struct _GSrvTarget {
* A single target host/port that a network service is running on.
*/
GType
g_srv_target_get_type (void)
{
static volatile gsize type_volatile = 0;
if (g_once_init_enter (&type_volatile))
{
GType type = g_boxed_type_register_static (
g_intern_static_string ("GSrvTarget"),
(GBoxedCopyFunc) g_srv_target_copy,
(GBoxedFreeFunc) g_srv_target_free);
g_once_init_leave (&type_volatile, type);
}
return type_volatile;
}
G_DEFINE_BOXED_TYPE (GSrvTarget, g_srv_target,
g_srv_target_copy, g_srv_target_free)
/**
* g_srv_target_new:

View File

@ -53,10 +53,9 @@ value_meminit (GValue *value,
memset (value->data, 0, sizeof (value->data));
}
static gpointer
value_copy (gpointer boxed)
static GValue *
value_copy (GValue *src_value)
{
const GValue *src_value = boxed;
GValue *dest_value = g_new0 (GValue, 1);
if (G_VALUE_TYPE (src_value))
@ -68,10 +67,8 @@ value_copy (gpointer boxed)
}
static void
value_free (gpointer boxed)
value_free (GValue *value)
{
GValue *value = boxed;
if (G_VALUE_TYPE (value))
g_value_unset (value);
g_free (value);
@ -102,187 +99,64 @@ g_boxed_type_init (void)
g_assert (type == G_TYPE_BOXED);
}
GType
g_closure_get_type (void)
static GDate *
gdate_copy (GDate *date)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GClosure"),
(GBoxedCopyFunc) g_closure_ref,
(GBoxedFreeFunc) g_closure_unref);
return type_id;
}
GType
g_value_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GValue"),
value_copy,
value_free);
return type_id;
}
GType
g_value_array_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GValueArray"),
(GBoxedCopyFunc) g_value_array_copy,
(GBoxedFreeFunc) g_value_array_free);
return type_id;
}
static gpointer
gdate_copy (gpointer boxed)
{
const GDate *date = (const GDate*) boxed;
return g_date_new_julian (g_date_get_julian (date));
}
GType
g_date_get_type (void)
static GString *
gstring_copy (GString *src_gstring)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GDate"),
(GBoxedCopyFunc) gdate_copy,
(GBoxedFreeFunc) g_date_free);
return type_id;
}
GType
g_strv_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GStrv"),
(GBoxedCopyFunc) g_strdupv,
(GBoxedFreeFunc) g_strfreev);
return type_id;
}
static gpointer
gstring_copy (gpointer boxed)
{
const GString *src_gstring = boxed;
return g_string_new_len (src_gstring->str, src_gstring->len);
}
static void
gstring_free (gpointer boxed)
gstring_free (GString *gstring)
{
GString *gstring = boxed;
g_string_free (gstring, TRUE);
}
GType
g_gstring_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GString"),
/* the naming is a bit odd, but GString is obviously not G_TYPE_STRING */
gstring_copy,
gstring_free);
return type_id;
}
static gpointer
hash_table_copy (gpointer boxed)
{
GHashTable *hash_table = boxed;
return g_hash_table_ref (hash_table);
}
static void
hash_table_free (gpointer boxed)
{
GHashTable *hash_table = boxed;
g_hash_table_unref (hash_table);
}
GType
g_hash_table_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GHashTable"),
hash_table_copy, hash_table_free);
return type_id;
}
GType
g_regex_get_type (void)
{
static GType type_id = 0;
G_DEFINE_BOXED_TYPE (GClosure, g_closure, g_closure_ref, g_closure_unref)
G_DEFINE_BOXED_TYPE (GValue, g_value, value_copy, value_free)
G_DEFINE_BOXED_TYPE (GValueArray, g_value_array, g_value_array_copy, g_value_array_free)
G_DEFINE_BOXED_TYPE (GDate, g_date, gdate_copy, g_date_free)
/* the naming is a bit odd, but GString is obviously not G_TYPE_STRING */
G_DEFINE_BOXED_TYPE (GString, g_gstring, gstring_copy, gstring_free)
G_DEFINE_BOXED_TYPE (GHashTable, g_hash_table, g_hash_table_ref, g_hash_table_unref)
G_DEFINE_BOXED_TYPE (GArray, g_array, g_array_ref, g_array_unref)
G_DEFINE_BOXED_TYPE (GPtrArray, g_ptr_array,g_ptr_array_ref, g_ptr_array_unref)
G_DEFINE_BOXED_TYPE (GByteArray, g_byte_array, g_byte_array_ref, g_byte_array_unref)
#ifdef ENABLE_REGEX
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GRegex"),
(GBoxedCopyFunc) g_regex_ref,
(GBoxedFreeFunc) g_regex_unref);
#endif
G_DEFINE_BOXED_TYPE (GRegex, g_regex, g_regex_ref, g_regex_unref)
#else
GType g_regex_get_type (void) { return G_TYPE_INVALID; }
#endif /* ENABLE_REGEX */
return type_id;
}
#define g_variant_type_get_type g_variant_type_get_gtype
G_DEFINE_BOXED_TYPE (GVariantType, g_variant_type, g_variant_type_copy, g_variant_type_free)
#undef g_variant_type_get_type
G_DEFINE_BOXED_TYPE (GError, g_error, g_error_copy, g_error_free)
/* This one can't use G_DEFINE_BOXED_TYPE (GStrv, g_strv, g_strdupv, g_strfreev) */
GType
g_array_get_type (void)
g_strv_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GArray"),
(GBoxedCopyFunc) g_array_ref,
(GBoxedFreeFunc) g_array_unref);
return type_id;
}
static volatile gsize g_define_type_id__volatile = 0;
GType
g_ptr_array_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GPtrArray"),
(GBoxedCopyFunc) g_ptr_array_ref,
(GBoxedFreeFunc) g_ptr_array_unref);
return type_id;
}
if (g_once_init_enter (&g_define_type_id__volatile))
{
GType g_define_type_id =
g_boxed_type_register_static (g_intern_static_string ("GStrv"),
(GBoxedCopyFunc) g_strdupv,
(GBoxedFreeFunc) g_strfreev);
GType
g_byte_array_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GByteArray"),
(GBoxedCopyFunc) g_byte_array_ref,
(GBoxedFreeFunc) g_byte_array_unref);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
return type_id;
}
GType
g_variant_type_get_gtype (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GVariantType"),
(GBoxedCopyFunc) g_variant_type_copy,
(GBoxedFreeFunc) g_variant_type_free);
return type_id;
return g_define_type_id__volatile;
}
/**
@ -297,19 +171,6 @@ g_variant_get_gtype (void)
return G_TYPE_VARIANT;
}
GType
g_error_get_type (void)
{
static GType type_id = 0;
if (!type_id)
type_id = g_boxed_type_register_static (g_intern_static_string ("GError"),
(GBoxedCopyFunc) g_error_copy,
(GBoxedFreeFunc) g_error_free);
return type_id;
}
static void
boxed_proxy_value_init (GValue *value)
{

View File

@ -26,19 +26,7 @@
#include "gvalue.h"
#include "gvaluetypes.h"
GType
g_io_channel_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static ("GIOChannel",
(GBoxedCopyFunc) g_io_channel_ref,
(GBoxedFreeFunc) g_io_channel_unref);
return our_type;
}
G_DEFINE_BOXED_TYPE (GIOChannel, g_io_channel, g_io_channel_ref, g_io_channel_unref)
GType
g_io_condition_get_type (void)

View File

@ -1129,15 +1129,7 @@ g_value_get_pointer (const GValue *value)
return value->data[0].v_pointer;
}
GType
g_gtype_get_type (void)
{
static const GTypeInfo type_info = { 0, };
static GType type;
if (!type)
type = g_type_register_static (G_TYPE_POINTER, g_intern_static_string ("GType"), &type_info, 0);
return type;
}
G_DEFINE_POINTER_TYPE (GType, g_gtype)
/**
* g_value_set_gtype: