diff options
Diffstat (limited to 'calendar/cal-util')
-rw-r--r-- | calendar/cal-util/calobj.c | 21 | ||||
-rw-r--r-- | calendar/cal-util/calobj.h | 11 |
2 files changed, 32 insertions, 0 deletions
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c index cc9c1636c7..9691d31c11 100644 --- a/calendar/cal-util/calobj.c +++ b/calendar/cal-util/calobj.c @@ -66,6 +66,8 @@ ical_object_new (void) ico->pilot_id = 0; ico->pilot_status = ICAL_PILOT_SYNC_MOD; + ico->ref_count = 1; + return ico; } @@ -91,6 +93,23 @@ ical_new (char *comment, char *organizer, char *summary) return ico; } + +void +ical_object_ref (iCalObject *ico) +{ + ico->ref_count++; +} + + +void +ical_object_unref (iCalObject *ico) +{ + ico->ref_count--; + if (ico->ref_count == 0) + ical_object_destroy (ico); +} + + static void my_free (gpointer data, gpointer user_dat_ignored) { @@ -588,6 +607,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name) return 0; } + ical->ref_count = 1; + /* uid */ if (has (o, VCUniqueStringProp)){ ical->uid = g_strdup (str_val (vo)); diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h index 25954b8098..e44b2ad7b1 100644 --- a/calendar/cal-util/calobj.h +++ b/calendar/cal-util/calobj.h @@ -221,6 +221,8 @@ typedef struct { /* Pilot */ iCalPilotState pilot_status; /* Status information */ guint32 pilot_id; /* Pilot ID */ + + guint ref_count; } iCalObject; /* The callback for the recurrence generator */ @@ -228,7 +230,16 @@ typedef int (*calendarfn) (iCalObject *, time_t, time_t, void *); iCalObject *ical_new (char *comment, char *organizer, char *summary); iCalObject *ical_object_new (void); + +/* iCalObjects are created with a refcount of 1. When it drops to 0 it is + destroyed with ical_object_destroy(). To maintain backwards compatability + ical_object_destroy() can still be used, though code which uses it should + not be mixed with code that uses refcounts. */ +void ical_object_ref (iCalObject *ico); +void ical_object_unref (iCalObject *ico); + void ical_object_destroy (iCalObject *ico); + iCalObject *ical_object_create_from_vobject (VObject *obj, const char *object_name); VObject *ical_object_to_vobject (iCalObject *ical); iCalObject *ical_object_duplicate (iCalObject *o); |