summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2021-11-07 15:35:05 -0500
committerAllen Winter <allen.winter@kdab.com>2021-11-07 15:35:05 -0500
commit2605580b7f3aa6d24157bb4e3fdb4bc1d15e03d7 (patch)
tree3658352c0c9fd18f145eed5f90d925f11815015e /src
parent386a21c6d047adcc1b50a101e850f6b16541efcc (diff)
parente535a73fbabc46abf3d87e3245335ab66d00f432 (diff)
downloadlibical-git-2605580b7f3aa6d24157bb4e3fdb4bc1d15e03d7.tar.gz
Merge branch '3.0'
Diffstat (limited to 'src')
-rw-r--r--src/libical-glib/api/i-cal-component.xml77
-rw-r--r--src/libical-glib/i-cal-object.c.in89
-rw-r--r--src/libical-glib/i-cal-object.h.in4
-rwxr-xr-xsrc/test/libical-glib/component.py4
-rw-r--r--src/test/regression.c26
5 files changed, 170 insertions, 30 deletions
diff --git a/src/libical-glib/api/i-cal-component.xml b/src/libical-glib/api/i-cal-component.xml
index 29d13e53..bb262dde 100644
--- a/src/libical-glib/api/i-cal-component.xml
+++ b/src/libical-glib/api/i-cal-component.xml
@@ -182,32 +182,89 @@
<returns type="ICalComponent *" annotation="transfer full, nullable" translator_argus="(GObject *)component" comment="The next #ICalComponent."/>
<comment xml:space="preserve">Gets the next #ICalComponent with specific kind in #ICalComponent.</comment>
</method>
- <method name="i_cal_component_begin_component" corresponds="icalcomponent_begin_component" since="1.0">
+ <method name="i_cal_component_begin_component" corresponds="CUSTOM" since="1.0">
<parameter type="ICalComponent *" name="component" comment="A #ICalComponent"/>
<parameter type="ICalComponentKind" name="kind" comment="A #ICalComponentKind"/>
<returns type="ICalCompIter *" annotation="transfer full" comment="A #ICalCompIter"/>
- <comment xml:space="preserve">Gets the #ICalCompIter pointing to the first child #ICalComponent. Use #ICalCompIter when you need remove the child component from the parent. For traversing, i_cal_object_set_owner needs to be called after this API. See component.py in tests for details.</comment>
+ <comment xml:space="preserve">Gets the #ICalCompIter pointing to the first child #ICalComponent.</comment>
+ <custom> ICalCompIter *iter;
+
+ g_return_val_if_fail (I_CAL_IS_COMPONENT (component), NULL);
+
+ iter = i_cal_comp_iter_new_full(icalcomponent_begin_component((icalcomponent *)i_cal_object_get_native(I_CAL_OBJECT (component)), (icalcomponent_kind) (kind)));
+ if (iter) {
+ i_cal_object_set_owner(I_CAL_OBJECT(iter), G_OBJECT(component));
+ i_cal_object_set_always_destroy(I_CAL_OBJECT(iter), TRUE);
+ }
+
+ return iter;</custom>
</method>
- <method name="i_cal_component_end_component" corresponds="icalcomponent_end_component" since="1.0">
+ <method name="i_cal_component_end_component" corresponds="CUSTOM" since="1.0">
<parameter type="ICalComponent *" name="component" comment="A #ICalComponent"/>
<parameter type="ICalComponentKind" name="kind" comment="A #ICalComponentKind"/>
<returns type="ICalCompIter *" annotation="transfer full" comment="A #ICalCompIter"/>
- <comment xml:space="preserve">Gets the #ICalCompIter pointing to the end child #ICalComponent. Use #ICalCompIter when you need remove the child component from the parent. For traversing, i_cal_object_set_owner needs to be called after this API. See component.py in tests for details.</comment>
+ <comment xml:space="preserve">Gets the #ICalCompIter pointing to the end child #ICalComponent.</comment>
+ <custom> ICalCompIter *iter;
+ g_return_val_if_fail (I_CAL_IS_COMPONENT (component), NULL);
+
+ iter = i_cal_comp_iter_new_full(icalcomponent_end_component((icalcomponent *)i_cal_object_get_native(I_CAL_OBJECT (component)), (icalcomponent_kind) (kind)));
+ if (iter) {
+ i_cal_object_set_owner(I_CAL_OBJECT(iter), G_OBJECT(component));
+ i_cal_object_set_always_destroy(I_CAL_OBJECT(iter), TRUE);
+ }
+
+ return iter;</custom>
</method>
- <method name="i_cal_comp_iter_next" corresponds="icalcompiter_next" since="1.0">
+ <method name="i_cal_comp_iter_next" corresponds="CUSTOM" since="1.0">
<parameter type="ICalCompIter *" name="i" native_op="POINTER" comment="A #ICalCompIter"/>
<returns type="ICalComponent *" annotation="transfer full" comment="A #ICalCompIter"/>
- <comment xml:space="preserve">Gets the next #ICalComponent pointed by #ICalCompIter. Use #ICalCompIter when you need remove the child component from the parent. For traversing, i_cal_object_set_owner needs to be called after this API. See component.py in tests for details.</comment>
+ <comment xml:space="preserve">Gets the next #ICalComponent pointed by #ICalCompIter.</comment>
+ <custom> ICalComponent *comp;
+
+ g_return_val_if_fail (I_CAL_IS_COMP_ITER (i), NULL);
+
+ comp = i_cal_component_new_full(icalcompiter_next((struct icalcompiter *)i_cal_object_get_native(I_CAL_OBJECT (i))), NULL);
+ if (comp) {
+ GObject *owner = i_cal_object_ref_owner(I_CAL_OBJECT(i));
+ i_cal_object_set_owner(I_CAL_OBJECT(comp), owner);
+ g_clear_object(&amp;owner);
+ }
+
+ return comp;</custom>
</method>
- <method name="i_cal_comp_iter_prior" corresponds="icalcompiter_prior" since="1.0">
+ <method name="i_cal_comp_iter_prior" corresponds="CUSTOM" since="1.0">
<parameter type="ICalCompIter *" name="i" native_op="POINTER" comment="A #ICalCompIter"/>
<returns type="ICalComponent *" annotation="transfer full" comment="A #ICalCompIter"/>
- <comment xml:space="preserve">Gets the prior #ICalComponent pointed by #ICalCompIter. Use #ICalCompIter when you need remove the child component from the parent. For traversing, i_cal_object_set_owner needs to be called after this API. See component.py in tests for details.</comment>
+ <comment xml:space="preserve">Gets the prior #ICalComponent pointed by #ICalCompIter.</comment>
+ <custom> ICalComponent *comp;
+
+ g_return_val_if_fail (I_CAL_IS_COMP_ITER (i), NULL);
+
+ comp = i_cal_component_new_full(icalcompiter_prior((struct icalcompiter *)i_cal_object_get_native(I_CAL_OBJECT (i))), NULL);
+ if (comp) {
+ GObject *owner = i_cal_object_ref_owner(I_CAL_OBJECT(i));
+ i_cal_object_set_owner(I_CAL_OBJECT(comp), owner);
+ g_clear_object(&amp;owner);
+ }
+
+ return comp;</custom>
</method>
- <method name="i_cal_comp_iter_deref" corresponds="icalcompiter_deref" since="1.0">
+ <method name="i_cal_comp_iter_deref" corresponds="CUSTOM" since="1.0">
<parameter type="ICalCompIter *" name="i" native_op="POINTER" comment="A #ICalCompIter"/>
<returns type="ICalComponent *" annotation="transfer full" comment="A #ICalComponent"/>
- <comment xml:space="preserve">Gets the current #ICalComponent pointed by #ICalCompIter. Use #ICalCompIter when you need remove the child component from the parent. For traversing, i_cal_object_set_owner needs to be called after this API. See component.py in tests for details.</comment>
+ <comment xml:space="preserve">Gets the current #ICalComponent pointed by #ICalCompIter.</comment>
+ <custom> ICalComponent *comp;
+
+ g_return_val_if_fail (I_CAL_IS_COMP_ITER (i), NULL);
+
+ comp = i_cal_component_new_full(icalcompiter_deref((struct icalcompiter *)i_cal_object_get_native(I_CAL_OBJECT (i))), NULL);
+ if (comp) {
+ GObject *owner = i_cal_object_ref_owner(I_CAL_OBJECT(i));
+ i_cal_object_set_owner(I_CAL_OBJECT(comp), owner);
+ g_clear_object(&amp;owner);
+ }
+
+ return comp;</custom>
</method>
<method name="i_cal_component_check_restrictions" corresponds="icalcomponent_check_restrictions" kind="other" since="1.0">
<parameter type="ICalComponent *" name="comp" comment="The #ICalComponent to be checked"/>
diff --git a/src/libical-glib/i-cal-object.c.in b/src/libical-glib/i-cal-object.c.in
index 4b2fa34e..a06d29d4 100644
--- a/src/libical-glib/i-cal-object.c.in
+++ b/src/libical-glib/i-cal-object.c.in
@@ -107,6 +107,7 @@ typedef struct
gpointer native;
GDestroyNotify native_destroy_func;
gboolean is_global_memory;
+ gboolean always_destroy;
GObject *owner;
GSList *dependers; /* referenced GObject-s */
} ICalObjectPrivate;
@@ -122,6 +123,7 @@ enum
PROP_NATIVE,
PROP_NATIVE_DESTROY_FUNC,
PROP_IS_GLOBAL_MEMORY,
+ PROP_ALWAYS_DESTROY,
PROP_OWNER
};
@@ -149,6 +151,10 @@ static void i_cal_object_set_property(GObject *object, guint property_id,
priv->is_global_memory = g_value_get_boolean(value);
return;
+ case PROP_ALWAYS_DESTROY:
+ i_cal_object_set_always_destroy(iobject, g_value_get_boolean(value));
+ return;
+
case PROP_OWNER:
i_cal_object_set_owner(iobject, g_value_get_object(value));
return;
@@ -177,6 +183,10 @@ static void i_cal_object_get_property(GObject *object, guint property_id,
g_value_set_boolean(value, i_cal_object_get_is_global_memory(iobject));
return;
+ case PROP_ALWAYS_DESTROY:
+ g_value_set_boolean(value, i_cal_object_get_always_destroy(iobject));
+ return;
+
case PROP_OWNER:
g_value_take_object(value, i_cal_object_ref_owner(iobject));
return;
@@ -190,9 +200,10 @@ static void i_cal_object_finalize(GObject *object)
ICalObject *iobject = I_CAL_OBJECT(object);
ICalObjectPrivate *priv = i_cal_object_get_instance_private(iobject);
- if (!priv->owner && !priv->is_global_memory &&
- priv->native && priv->native_destroy_func) {
- g_clear_pointer(&priv->native, priv->native_destroy_func);
+ if ((iobject->priv->always_destroy || !iobject->priv->owner) &&
+ !iobject->priv->is_global_memory &&
+ iobject->priv->native && iobject->priv->native_destroy_func) {
+ iobject->priv->native_destroy_func(iobject->priv->native);
}
g_clear_object(&priv->owner);
@@ -264,6 +275,25 @@ static void i_cal_object_class_init(ICalObjectClass * class)
G_PARAM_STATIC_STRINGS));
/**
+ * ICalObject:always-destroy:
+ *
+ * Whether free the native libical structure on #ICalObject's finalize even
+ * if the object has set an owner.
+ *
+ * Since: 3.0.11
+ **/
+ g_object_class_install_property(
+ object_class,
+ PROP_ALWAYS_DESTROY,
+ g_param_spec_boolean(
+ "always-destroy",
+ "Always-Destroy",
+ "Whether the native libical structure is freed even when the owner is set",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* ICalObject:owner:
*
* Owner of the native libical structure. If set, then it is
@@ -663,3 +693,56 @@ void i_cal_object_remove_depender(ICalObject *iobject, GObject *depender)
UNLOCK_PROPS(priv);
}
+
+/**
+ * i_cal_object_set_always_destroy:
+ * @iobject: an #ICalObject
+ * @value: value to set
+ *
+ * Sets the @ICalObject::always-destroy property value. When %TRUE, the native
+ * libical structure is always freed, even when an owner of the @iobject is set.
+ *
+ * Since: 3.0.11
+ **/
+void i_cal_object_set_always_destroy(ICalObject *iobject, gboolean value)
+{
+ gboolean changed;
+
+ g_return_if_fail(I_CAL_IS_OBJECT(iobject));
+
+ LOCK_PROPS(iobject);
+
+ changed = (value ? 1 : 0) != (iobject->priv->always_destroy ? 1 : 0);
+ if (changed)
+ iobject->priv->always_destroy = value;
+
+ UNLOCK_PROPS(iobject);
+
+ if (changed)
+ g_object_notify(G_OBJECT(iobject), "always-destroy");
+}
+
+/**
+ * i_cal_object_get_always_destroy:
+ * @iobject: an #ICalObject
+ *
+ * Obtain the @ICalObject::always-destroy property value.
+ *
+ * Returns: Whether the native libical structure is freed even when an owner is set.
+ *
+ * Since: 3.0.11
+ **/
+gboolean i_cal_object_get_always_destroy(ICalObject *iobject)
+{
+ gboolean value;
+
+ g_return_val_if_fail(I_CAL_IS_OBJECT(iobject), FALSE);
+
+ LOCK_PROPS(iobject);
+
+ value = iobject->priv->always_destroy;
+
+ UNLOCK_PROPS(iobject);
+
+ return value;
+}
diff --git a/src/libical-glib/i-cal-object.h.in b/src/libical-glib/i-cal-object.h.in
index 799e3112..a39ebddd 100644
--- a/src/libical-glib/i-cal-object.h.in
+++ b/src/libical-glib/i-cal-object.h.in
@@ -77,6 +77,10 @@ LIBICAL_ICAL_EXPORT void i_cal_object_add_depender(ICalObject *iobject, GObject
LIBICAL_ICAL_EXPORT void i_cal_object_remove_depender(ICalObject *iobject, GObject *depender);
+LIBICAL_ICAL_EXPORT void i_cal_object_set_always_destroy(ICalObject *iobject, gboolean value);
+
+LIBICAL_ICAL_EXPORT gboolean i_cal_object_get_always_destroy(ICalObject *iobject);
+
LIBICAL_ICAL_EXPORT void i_cal_object_free_global_objects(void);
G_END_DECLS
diff --git a/src/test/libical-glib/component.py b/src/test/libical-glib/component.py
index cbdb097e..cc6cfa6a 100755
--- a/src/test/libical-glib/component.py
+++ b/src/test/libical-glib/component.py
@@ -183,25 +183,21 @@ def main():
#Traverse with external API.
iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
child_component = iter.deref();
- child_component.set_owner(parent);
for i in range(0, count):
prefix = "test"
index = i+2;
assert(child_component.get_summary() == prefix + str(index));
if (i != count-1):
child_component = iter.next();
- child_component.set_owner(parent);
iter = parent.end_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
child_component = iter.prior();
- child_component.set_owner(parent);
for i in range(0, count):
prefix = "test"
index = count + 1 - i;
assert(child_component.get_summary() == prefix + str(index));
if (i != count - 1):
child_component = iter.prior();
- child_component.set_owner(parent);
#Traverse and remove with external API.
iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
diff --git a/src/test/regression.c b/src/test/regression.c
index e0de9e9e..656ca30b 100644
--- a/src/test/regression.c
+++ b/src/test/regression.c
@@ -4623,7 +4623,7 @@ void test_timezone_from_builtin(void)
icaltimezone *zone;
struct icaltimetype dtstart, dtend, due;
char *strcomp, *tzidprefix, *prevslash = NULL, *prevprevslash = NULL, *p;
- int len;
+ size_t len;
zone = icaltimezone_get_builtin_timezone("America/New_York");
tzidprefix = strdup(icaltimezone_get_tzid (zone));
@@ -4879,7 +4879,7 @@ static void test_builtin_compat_tzid (void)
icaltimezone_free_builtin_timezones();
}
-static void test_vcc_vcard_parse (void)
+static void test_vcc_vcard_parse(void)
{
/* Two VCARD-s, because some arches can parse the first and some the second. */
const char *vcard1 =
@@ -4911,40 +4911,40 @@ static void test_vcc_vcard_parse (void)
"END:VCALENDAR\r\n";
VObject *vcal;
- vcal = Parse_MIME(vcard1, strlen(vcard1));
+ vcal = Parse_MIME(vcard1, (unsigned long)strlen(vcard1));
if(vcal) {
icalcomponent *icalcomp;
- icalcomp = icalvcal_convert (vcal);
+ icalcomp = icalvcal_convert(vcal);
ok("vCard1 is not iCalendar", (icalcomp == NULL));
if(icalcomp)
- icalcomponent_free (icalcomp);
+ icalcomponent_free(icalcomp);
cleanVObject (vcal);
} else {
ok("vCard1 cannot be parsed", (vcal == NULL));
}
- vcal = Parse_MIME(vcard2, strlen(vcard2));
+ vcal = Parse_MIME(vcard2, (unsigned long)strlen(vcard2));
if(vcal) {
icalcomponent *icalcomp;
- icalcomp = icalvcal_convert (vcal);
+ icalcomp = icalvcal_convert(vcal);
ok("vCard2 is not iCalendar", (icalcomp == NULL));
if(icalcomp)
- icalcomponent_free (icalcomp);
+ icalcomponent_free(icalcomp);
- cleanVObject (vcal);
+ cleanVObject(vcal);
} else {
ok("vCard2 cannot be parsed", (vcal == NULL));
}
- vcal = Parse_MIME(vcalendar, strlen(vcalendar));
+ vcal = Parse_MIME(vcalendar, (unsigned long)strlen(vcalendar));
ok("vCalendar can be parsed", (vcal != NULL));
if(vcal) {
icalcomponent *icalcomp;
- icalcomp = icalvcal_convert (vcal);
+ icalcomp = icalvcal_convert(vcal);
ok("vCalendar can be converted", (icalcomp != NULL));
if(icalcomp) {
icalcomponent *child;
@@ -4956,10 +4956,10 @@ static void test_vcc_vcard_parse (void)
ok("vCalendar child is VEVENT", (icalcomponent_isa(child) == ICAL_VEVENT_COMPONENT));
ok("vCalendar child UID matches", (strcmp(icalcomponent_get_uid(child), "123") == 0));
ok("vCalendar child SUMMARY matches", (strcmp(icalcomponent_get_summary(child), "Summary") == 0));
- icalcomponent_free (icalcomp);
+ icalcomponent_free(icalcomp);
}
- cleanVObject (vcal);
+ cleanVObject(vcal);
}
}