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

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