From 55d7ee4fb2a680892db4d6e22b7d3b40061dcf39 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Mon, 5 Oct 2020 18:16:37 +0200 Subject: [PATCH 2/2] libical-glib: Introduce i_cal_timezone_take_component() Deprecate i_cal_timezone_set_component(), because it adds a circular dependency between the 'zone' and the passed-in component, which causes neither of them being freed properly. --- ReleaseNotes.txt | 1 + src/libical-glib/api/i-cal-timezone.xml | 28 ++++++++++++++++++++++++- src/libical-glib/i-cal-object.c.in | 21 +++++++++++++++++++ src/libical-glib/i-cal-object.h.in | 3 +++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 5dda55be..4f8d51b5 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -5,6 +5,7 @@ Version 3.0.9 (UNRELEASED): --------------------------- * Add support for empty parameters, e.g. CN="" * Fix cross-compile support in libical-glib + * libical-glib: Introduce i_cal_timezone_take_component(), a replacement of i_cal_timezone_set_component() Version 3.0.8 (07 March 2020): ------------------------------ diff --git a/src/libical-glib/api/i-cal-timezone.xml b/src/libical-glib/api/i-cal-timezone.xml index dfa4140d..0c919a5f 100644 --- a/src/libical-glib/api/i-cal-timezone.xml +++ b/src/libical-glib/api/i-cal-timezone.xml @@ -100,7 +100,9 @@ Sets the VTIMEZONE component of #ICalTimezone, initializing the tzid, location and tzname fields. It returns 1 on success or 0 on failure, i.e. no TZID was found. * - * @note The @zone assumes ownership of the @comp, thus make sure you pass an unowned #ICalComponent. + * @note The @zone assumes ownership of the @comp, thus make sure you pass an unowned #ICalComponent. + * + * Deprecated: 3.0.9: Use i_cal_timezone_take_component() instead. g_return_val_if_fail(I_CAL_IS_TIMEZONE(zone), 0); g_return_val_if_fail(I_CAL_IS_COMPONENT(comp), 0); @@ -108,6 +110,30 @@ return icaltimezone_set_component ((icaltimezone *)i_cal_object_get_native (I_CAL_OBJECT (zone)), (icalcomponent *)i_cal_object_get_native (I_CAL_OBJECT (comp))); + + + + + Sets the VTIMEZONE component of #ICalTimezone, initializing the tzid, location and tzname fields. + * + * @note The @zone assumes ownership of the @comp, thus make sure you pass an unowned #ICalComponent. The @comp is invalidated and unreffed at the end of the call. + gint success; + icalcomponent *native; + + g_return_val_if_fail(I_CAL_IS_TIMEZONE(zone), FALSE); + g_return_val_if_fail(I_CAL_IS_COMPONENT(comp), FALSE); + + native = i_cal_object_steal_native(I_CAL_OBJECT(comp)); + success = icaltimezone_set_component((icaltimezone *)i_cal_object_get_native(I_CAL_OBJECT(zone)), native); + + if(!success) { + /* Return the native back, thus it's freed together with the 'comp'. */ + i_cal_object_set_native(I_CAL_OBJECT(comp), native); + } + g_object_unref(comp); + + return success != 0; + diff --git a/src/libical-glib/i-cal-object.c.in b/src/libical-glib/i-cal-object.c.in index 23aaddb2..fc427198 100644 --- a/src/libical-glib/i-cal-object.c.in +++ b/src/libical-glib/i-cal-object.c.in @@ -386,6 +386,27 @@ i_cal_object_construct(GType object_type, return iobject; } +/** + * i_cal_object_set_native: (skip) + * @iobject: an #ICalObject + * @native: (transfer full): the native libical structure pointer + * + * Set native libical structure pointer associated with this @iobject. + * + * Since: 3.0.9 + **/ +void i_cal_object_set_native(ICalObject *iobject, + gpointer native) +{ + g_return_if_fail(I_CAL_IS_OBJECT(iobject)); + + LOCK_PROPS(iobject); + + iobject->priv->native = native; + + UNLOCK_PROPS(iobject); +} + /** * i_cal_object_get_native: (skip) * @iobject: an #ICalObject diff --git a/src/libical-glib/i-cal-object.h.in b/src/libical-glib/i-cal-object.h.in index bc53e9e0..491f1d9b 100644 --- a/src/libical-glib/i-cal-object.h.in +++ b/src/libical-glib/i-cal-object.h.in @@ -86,6 +86,9 @@ LIBICAL_ICAL_EXPORT gpointer i_cal_object_construct(GType object_type, GDestroyNotify native_destroy_func, gboolean is_global_memory, GObject *owner); +LIBICAL_ICAL_EXPORT void i_cal_object_set_native(ICalObject *iobject, + gpointer native); + LIBICAL_ICAL_EXPORT gpointer i_cal_object_get_native(ICalObject *iobject); LIBICAL_ICAL_EXPORT gpointer i_cal_object_steal_native(ICalObject *iobject); -- 2.26.2