Blame SOURCES/evolution-data-server-3.28.5-vcard-attr-param-struct-reff.patch

550ffc
diff --git a/src/addressbook/libebook-contacts/e-vcard.c b/src/addressbook/libebook-contacts/e-vcard.c
550ffc
index e44b7fdcf..680cf85af 100644
550ffc
--- a/src/addressbook/libebook-contacts/e-vcard.c
550ffc
+++ b/src/addressbook/libebook-contacts/e-vcard.c
550ffc
@@ -120,6 +120,14 @@
550ffc
 
550ffc
 G_DEFINE_TYPE (EVCard, e_vcard, G_TYPE_OBJECT)
550ffc
 
550ffc
+static EVCardAttribute *e_vcard_attribute_ref (EVCardAttribute *attr);
550ffc
+static void e_vcard_attribute_unref (EVCardAttribute *attr);
550ffc
+static EVCardAttributeParam *e_vcard_attribute_param_ref (EVCardAttributeParam *param);
550ffc
+static void e_vcard_attribute_param_unref (EVCardAttributeParam *param);
550ffc
+
550ffc
+G_DEFINE_BOXED_TYPE (EVCardAttribute, e_vcard_attribute, e_vcard_attribute_ref, e_vcard_attribute_unref)
550ffc
+G_DEFINE_BOXED_TYPE (EVCardAttributeParam, e_vcard_attribute_param, e_vcard_attribute_param_ref, e_vcard_attribute_param_unref)
550ffc
+
550ffc
 /* Encoding used in v-card
550ffc
  * Note: v-card spec defines additional 7BIT 8BIT and X- encoding
550ffc
  */
550ffc
@@ -135,6 +143,7 @@ struct _EVCardPrivate {
550ffc
 };
550ffc
 
550ffc
 struct _EVCardAttribute {
550ffc
+	gint ref_count;
550ffc
 	gchar  *group;
550ffc
 	gchar  *name;
550ffc
 	GList *params; /* EVCardParam */
550ffc
@@ -145,6 +154,7 @@ struct _EVCardAttribute {
550ffc
 };
550ffc
 
550ffc
 struct _EVCardAttributeParam {
550ffc
+	gint ref_count;
550ffc
 	gchar     *name;
550ffc
 	GList    *values;  /* GList of gchar *'s */
550ffc
 };
550ffc
@@ -1555,6 +1565,7 @@ e_vcard_attribute_new (const gchar *attr_group,
550ffc
 	if (attr_group != NULL && *attr_group == '\0')
550ffc
 		attr_group = NULL;
550ffc
 
550ffc
+	attr->ref_count = 1;
550ffc
 	attr->group = g_strdup (attr_group);
550ffc
 	attr->name = g_strdup (attr_name);
550ffc
 
550ffc
@@ -1572,14 +1583,34 @@ e_vcard_attribute_free (EVCardAttribute *attr)
550ffc
 {
550ffc
 	g_return_if_fail (attr != NULL);
550ffc
 
550ffc
-	g_free (attr->group);
550ffc
-	g_free (attr->name);
550ffc
+	e_vcard_attribute_unref (attr);
550ffc
+}
550ffc
 
550ffc
-	e_vcard_attribute_remove_values (attr);
550ffc
+static EVCardAttribute *
550ffc
+e_vcard_attribute_ref (EVCardAttribute *attr)
550ffc
+{
550ffc
+	g_return_val_if_fail (attr != NULL, NULL);
550ffc
 
550ffc
-	e_vcard_attribute_remove_params (attr);
550ffc
+	g_atomic_int_inc (&attr->ref_count);
550ffc
 
550ffc
-	g_slice_free (EVCardAttribute, attr);
550ffc
+	return attr;
550ffc
+}
550ffc
+
550ffc
+static void
550ffc
+e_vcard_attribute_unref (EVCardAttribute *attr)
550ffc
+{
550ffc
+	g_return_if_fail (attr != NULL);
550ffc
+
550ffc
+	if (g_atomic_int_dec_and_test (&attr->ref_count)) {
550ffc
+		g_free (attr->group);
550ffc
+		g_free (attr->name);
550ffc
+
550ffc
+		e_vcard_attribute_remove_values (attr);
550ffc
+
550ffc
+		e_vcard_attribute_remove_params (attr);
550ffc
+
550ffc
+		g_slice_free (EVCardAttribute, attr);
550ffc
+	}
550ffc
 }
550ffc
 
550ffc
 /**
550ffc
@@ -1609,25 +1640,6 @@ e_vcard_attribute_copy (EVCardAttribute *attr)
550ffc
 	return a;
550ffc
 }
550ffc
 
550ffc
-GType
550ffc
-e_vcard_attribute_get_type (void)
550ffc
-{
550ffc
-	static volatile gsize type_id__volatile = 0;
550ffc
-
550ffc
-	if (g_once_init_enter (&type_id__volatile)) {
550ffc
-		GType type_id;
550ffc
-
550ffc
-		type_id = g_boxed_type_register_static (
550ffc
-			"EVCardAttribute",
550ffc
-			(GBoxedCopyFunc) e_vcard_attribute_copy,
550ffc
-			(GBoxedFreeFunc) e_vcard_attribute_free);
550ffc
-
550ffc
-		g_once_init_leave (&type_id__volatile, type_id);
550ffc
-	}
550ffc
-
550ffc
-	return type_id__volatile;
550ffc
-}
550ffc
-
550ffc
 /**
550ffc
  * e_vcard_remove_attributes:
550ffc
  * @evc: vcard object
550ffc
@@ -2068,25 +2080,6 @@ e_vcard_attribute_remove_params (EVCardAttribute *attr)
550ffc
 	attr->encoding = EVC_ENCODING_RAW;
550ffc
 }
550ffc
 
550ffc
-GType
550ffc
-e_vcard_attribute_param_get_type (void)
550ffc
-{
550ffc
-	static volatile gsize type_id__volatile = 0;
550ffc
-
550ffc
-	if (g_once_init_enter (&type_id__volatile)) {
550ffc
-		GType type_id;
550ffc
-
550ffc
-		type_id = g_boxed_type_register_static (
550ffc
-			"EVCardAttributeParam",
550ffc
-			(GBoxedCopyFunc) e_vcard_attribute_param_copy,
550ffc
-			(GBoxedFreeFunc) e_vcard_attribute_param_free);
550ffc
-
550ffc
-		g_once_init_leave (&type_id__volatile, type_id);
550ffc
-	}
550ffc
-
550ffc
-	return type_id__volatile;
550ffc
-}
550ffc
-
550ffc
 /**
550ffc
  * e_vcard_attribute_param_new:
550ffc
  * @name: the name of the new parameter
550ffc
@@ -2099,6 +2092,8 @@ EVCardAttributeParam *
550ffc
 e_vcard_attribute_param_new (const gchar *name)
550ffc
 {
550ffc
 	EVCardAttributeParam *param = g_slice_new (EVCardAttributeParam);
550ffc
+
550ffc
+	param->ref_count = 1;
550ffc
 	param->values = NULL;
550ffc
 	param->name = g_strdup (name);
550ffc
 
550ffc
@@ -2116,11 +2111,31 @@ e_vcard_attribute_param_free (EVCardAttributeParam *param)
550ffc
 {
550ffc
 	g_return_if_fail (param != NULL);
550ffc
 
550ffc
-	g_free (param->name);
550ffc
+	e_vcard_attribute_param_unref (param);
550ffc
+}
550ffc
+
550ffc
+static EVCardAttributeParam *
550ffc
+e_vcard_attribute_param_ref (EVCardAttributeParam *param)
550ffc
+{
550ffc
+	g_return_val_if_fail (param != NULL, NULL);
550ffc
+
550ffc
+	g_atomic_int_inc (&param->ref_count);
550ffc
+
550ffc
+	return param;
550ffc
+}
550ffc
+
550ffc
+static void
550ffc
+e_vcard_attribute_param_unref (EVCardAttributeParam *param)
550ffc
+{
550ffc
+	g_return_if_fail (param != NULL);
550ffc
+
550ffc
+	if (g_atomic_int_dec_and_test (&param->ref_count)) {
550ffc
+		g_free (param->name);
550ffc
 
550ffc
-	e_vcard_attribute_param_remove_values (param);
550ffc
+		e_vcard_attribute_param_remove_values (param);
550ffc
 
550ffc
-	g_slice_free (EVCardAttributeParam, param);
550ffc
+		g_slice_free (EVCardAttributeParam, param);
550ffc
+	}
550ffc
 }
550ffc
 
550ffc
 /**