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

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