From 7dc9a9674120fa8be2fc33e627211b515475207f Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 26 May 2019 10:16:10 -0400 Subject: [PATCH] Deprecate foo_new_clone() in favor of foo_clone() Consistency between const and non-const args for clone functions --- .krazy | 2 ++ ReleaseNotes.txt | 19 ++++++++--- config.h.cmake | 15 -------- doc/Doxyfile.cmake | 3 +- doc/UsingLibical.md | 15 ++++---- doc/UsingLibical.txt | 14 ++++---- examples/access_properties_and_parameters.c | 2 +- .../lib/Net/ICal/Libical/Time.pm | 2 +- src/Net-ICal-Libical/netical.i | 2 +- src/Net-ICal-Libical/netical_wrap.c | 11 +++--- src/Net-ICal-Libical/netical_wrap.doc | 2 +- src/libical-glib/api/i-cal-component.xml | 4 +-- src/libical-glib/api/i-cal-parameter.xml | 4 +-- src/libical-glib/api/i-cal-property.xml | 4 +-- src/libical-glib/api/i-cal-value.xml | 2 +- src/libical/CMakeLists.txt | 1 + src/libical/astime.h | 6 ++-- src/libical/icalcomponent.c | 11 ++++-- src/libical/icalcomponent.h | 23 +++++++++---- src/libical/icalparameter.c | 7 +++- src/libical/icalparameter.h | 19 ++++++++--- src/libical/icalparameter_cxx.cpp | 4 +-- src/libical/icalparser.c | 2 +- src/libical/icalproperty.c | 11 ++++-- src/libical/icalproperty.h | 14 +++++++- src/libical/icalproperty_cxx.cpp | 4 +-- src/libical/icalvalue.c | 7 +++- src/libical/icalvalue.h | 14 +++++++- src/libical/icalvalue_cxx.cpp | 4 +-- src/libical/libical_deprecated.h | 19 +++++++++++ src/libical/vcomponent_cxx.cpp | 4 +-- src/libicalss/icalclassify.c | 2 +- src/libicalss/icalcluster.c | 16 ++++++--- src/libicalss/icalcluster.h | 15 +++++++- src/libicalss/icalfileset.c | 2 +- src/libicalss/icalmessage.c | 6 ++-- src/test/copycluster.c | 2 +- src/test/process.c | 4 +-- src/test/regression-storage.c | 8 ++--- src/test/regression.c | 34 +++++++++---------- src/test/stow.c | 8 ++--- 41 files changed, 227 insertions(+), 121 deletions(-) create mode 100644 src/libical/libical_deprecated.h diff --git a/.krazy b/.krazy index fb3706676..046476560 100644 --- a/.krazy +++ b/.krazy @@ -7,6 +7,8 @@ EXTRA style #Skip foo_export.h SKIP libical_.*_export\.h +#Skip installed macro headers +SKIP libical_deprecated\.h #Skip examples SKIP /examples/ diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index a9a5f2772..8577ade06 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -4,16 +4,27 @@ Release Highlights Version 3.1.0 (NOT RELEASED YET): -------------------------------- * Requires CMake v3.11.0 or higher + * All ical*_new_clone() functions have been deprecated in favour of ical*_clone() * New publicly available functions: + icalrecurrencetype_encode_day + icalrecurrencetype_encode_month + icaltzutil_set_zone_directory + + icalcomponent_clone + + icalproperty_clone + + icalparameter_clone + + icalvalue_clone + + icalcluster_clone * icaltzutil_get_zone_directory() can use the TZDIR environment to find system zoneinfo * Deprecated functions: - + caldat - + juldat + + caldat (replaced by internal function icaldat_int()) + + juldat (replaced by internal function juldat_int()) + + icalcomponent_new_clone + + icalproperty_new_clone + + icalparameter_new_clone + + icalvalue_new_clone + + icalcluster_new_clone * Removed unused declarations: - (in the public headers but not used at all) + (were in the public headers but not used at all) + struct icaltimezonetype + struct icaltimezonephase * Improved performance of recurrence iterators @@ -30,7 +41,7 @@ Version 3.0.5 (14 May 2019): including to be able to use it. * Built-in timezones updated to tzdata2019a * De-fuzzifications and Coverity fixes - + Version 3.0.4 (14 Aug 2018): ---------------------------- * Silently fail RSCALE recurrence clauses when RSCALE is disabled diff --git a/config.h.cmake b/config.h.cmake index 77a1ae11e..8fd3421b6 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -546,18 +546,3 @@ typedef ssize_t IO_SSIZE_T; #define _unused(x) (void)x #endif #endif - -#/* Deprecated function macro */ -#if defined(NO_DEPRECATION_WARNINGS) -#define _deprecated(x) x -#else -#if !defined(_deprecated) -#ifdef __GNUC__ -#define _deprecated(x) x __attribute__((deprecated)) -#elif defined(_MSC_VER) -#define _deprecated(x) __declspec(deprecated) x -#else -#define _deprecated(x) x -#endif -#endif -#endif diff --git a/doc/Doxyfile.cmake b/doc/Doxyfile.cmake index 54981ef10..6e2d5e390 100644 --- a/doc/Doxyfile.cmake +++ b/doc/Doxyfile.cmake @@ -160,7 +160,8 @@ PREDEFINED = LIBICAL_ICAL_EXPORT="" \ LIBICAL_VCAL_EXPORT="" \ LIBICAL_ICAL_NO_EXPORT="" \ LIBICAL_ICALS_NO_EXPORT="" \ - LIBICAL_VCAL_NO_EXPORT="" + LIBICAL_VCAL_NO_EXPORT="" \ + LIBICAL_DEPRECATED= EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- diff --git a/doc/UsingLibical.md b/doc/UsingLibical.md index 5ef6457ff..0655a3a97 100644 --- a/doc/UsingLibical.md +++ b/doc/UsingLibical.md @@ -1225,13 +1225,14 @@ caller owns and must free, and some of the memory is managed by the library. Here is a summary of the memory rules. 1. If the function name has "new" in it (such as `icalcomponent_new()`, - or `icalpropert_new_clone()`), the caller gets control - of the memory. - -2. If you got the memory from a routine with new in it, you must - call the corresponding `*_free()` routine to free the memory, for - example use `icalcomponent_free()` to free objects created with - `icalcomponent_new()`) + or `icalproperty_new_from_string()`), the caller gets control + of the memory. The caller also gets control over an object that is + cloned via a function that ends with "_clone" (like `icalcomponent_clone()`) + +2. If you got the memory from a routine with "clone" or "new" in it, you + must call the corresponding `*_free()` routine to free the memory, + for example use `icalcomponent_free()` to free objects created with + `icalcomponent_new()` or `icalcomponent_clone()` 3. If the function name has "add" in it, the caller is transferring control of the memory to the routine, for example the function diff --git a/doc/UsingLibical.txt b/doc/UsingLibical.txt index ab409697d..9eb73ce11 100644 --- a/doc/UsingLibical.txt +++ b/doc/UsingLibical.txt @@ -1146,12 +1146,14 @@ caller owns and must free, and some of the memory is managed by the library. Here is a summary of the memory rules. 1) If the function name has "new" in it (such as icalcomponent_new(), - or icalpropert_new_clone()), the caller gets control - of the memory. - -2) If you got the memory from a routine with new in it, you must - call the corresponding *_free routine to free the memory. ( Use - icalcomponent_free() to free objects created with icalcomponent_new()) + or icalproperty_new_from_string()), the caller gets control of the + memory. The caller also gets control over an object that is cloned via + a function that ends with "_clone" (like icalcomponent_clone()) + +2) If you got the memory from a routine with "clone" or "new" in it, you + must call the corresponding *_free() routine to free the memory, for + example use icalcomponent_free() to free objects created with + icalcomponent_new() or icalcomponent_clone(). 3) If the function name has "add" in it, the caller is transferring control of the memory to the routine. ( icalproperty_add_parameter() ) diff --git a/examples/access_properties_and_parameters.c b/examples/access_properties_and_parameters.c index d17d91c02..f36367d24 100644 --- a/examples/access_properties_and_parameters.c +++ b/examples/access_properties_and_parameters.c @@ -134,7 +134,7 @@ void test_properties() free(str); /* Make a copy of the property. Caller owns the memory */ - clone = icalproperty_new_clone(prop); + clone = icalproperty_clone(prop); /* Get a reference to the value within the clone property */ value = icalproperty_get_value(clone); diff --git a/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm b/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm index cbae5f67f..630219e5c 100644 --- a/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm +++ b/src/Net-ICal-Libical/lib/Net/ICal/Libical/Time.pm @@ -144,7 +144,7 @@ sub clone { bless( {%$self},ref($self)); - $self->{'ref'} = Net::ICal::Libical::icalproperty_new_clone($self->{'ref'}); + $self->{'ref'} = Net::ICal::Libical::icalproperty_clone($self->{'ref'}); } diff --git a/src/Net-ICal-Libical/netical.i b/src/Net-ICal-Libical/netical.i index 6a6c6f1b5..495c07244 100644 --- a/src/Net-ICal-Libical/netical.i +++ b/src/Net-ICal-Libical/netical.i @@ -40,7 +40,7 @@ icalcomponent* icalparser_parse_string(char* str); icalcomponent* icalcomponent_new(icalcomponent_kind kind); -icalcomponent* icalcomponent_new_clone(icalcomponent* component); +icalcomponent* icalcomponent_clone(icalcomponent* component); icalcomponent* icalcomponent_new_from_string(char* str); char* icalcomponent_as_ical_string(icalcomponent* component); diff --git a/src/Net-ICal-Libical/netical_wrap.c b/src/Net-ICal-Libical/netical_wrap.c index 4fcb09256..667bd44fc 100644 --- a/src/Net-ICal-Libical/netical_wrap.c +++ b/src/Net-ICal-Libical/netical_wrap.c @@ -515,7 +515,7 @@ XS(_wrap_icalcomponent_new) { XSRETURN(argvi); } -XS(_wrap_icalcomponent_new_clone) { +XS(_wrap_icalcomponent_clone) { icalcomponent * _result; icalcomponent * _arg0; @@ -524,12 +524,12 @@ XS(_wrap_icalcomponent_new_clone) { cv = cv; if ((items < 1) || (items > 1)) - croak("Usage: icalcomponent_new_clone(component);"); + croak("Usage: icalcomponent_clone(component);"); if (SWIG_GetPtr(ST(0),(void **) &_arg0,(char *) 0 )) { - croak("Type error in argument 1 of icalcomponent_new_clone. Expected icalcomponentPtr."); + croak("Type error in argument 1 of icalcomponent_clone. Expected icalcomponentPtr."); XSRETURN(1); } - _result = (icalcomponent *)icalcomponent_new_clone(_arg0); + _result = (icalcomponent *)icalcomponent_clone(_arg0); ST(argvi) = sv_newmortal(); sv_setref_pv(ST(argvi++),"icalcomponentPtr", (void *) _result); XSRETURN(argvi); @@ -2901,7 +2901,8 @@ XS(boot_Net__ICal__Libical) { newXS("Net::ICal::Libical::var_Net__ICal__Libical_init", _wrap_perl5_Net__ICal__Libical_var_init, file); newXS("Net::ICal::Libical::icalparser_parse_string", _wrap_icalparser_parse_string, file); newXS("Net::ICal::Libical::icalcomponent_new", _wrap_icalcomponent_new, file); - newXS("Net::ICal::Libical::icalcomponent_new_clone", _wrap_icalcomponent_new_clone, file); + newXS("Net::ICal::Libical::icalcomponent_new_clone", _wrap_icalcomponent_clone, file); + newXS("Net::ICal::Libical::icalcomponent_clone", _wrap_icalcomponent_clone, file); newXS("Net::ICal::Libical::icalcomponent_new_from_string", _wrap_icalcomponent_new_from_string, file); newXS("Net::ICal::Libical::icalcomponent_as_ical_string", _wrap_icalcomponent_as_ical_string, file); newXS("Net::ICal::Libical::icalcomponent_free", _wrap_icalcomponent_free, file); diff --git a/src/Net-ICal-Libical/netical_wrap.doc b/src/Net-ICal-Libical/netical_wrap.doc index 41616c00d..d74e59cae 100644 --- a/src/Net-ICal-Libical/netical_wrap.doc +++ b/src/Net-ICal-Libical/netical_wrap.doc @@ -9,7 +9,7 @@ icalparser_parse_string(str); icalcomponent_new(kind); [ returns icalcomponent * ] -icalcomponent_new_clone(component); +icalcomponent_clone(component); [ returns icalcomponent * ] icalcomponent_new_from_string(str); diff --git a/src/libical-glib/api/i-cal-component.xml b/src/libical-glib/api/i-cal-component.xml index 1e104d59f..ad4e360c0 100644 --- a/src/libical-glib/api/i-cal-component.xml +++ b/src/libical-glib/api/i-cal-component.xml @@ -19,8 +19,8 @@ Create a new #ICalComponent with specific type. - - + + Deeply clone a #ICalComponent. diff --git a/src/libical-glib/api/i-cal-parameter.xml b/src/libical-glib/api/i-cal-parameter.xml index 9f0ee4140..951fdf31d 100644 --- a/src/libical-glib/api/i-cal-parameter.xml +++ b/src/libical-glib/api/i-cal-parameter.xml @@ -19,8 +19,8 @@ Create a new #ICalParameter according to the kind type - - + + Deep clone a #ICalParameter diff --git a/src/libical-glib/api/i-cal-property.xml b/src/libical-glib/api/i-cal-property.xml index 16845ae2b..a1be7ac30 100644 --- a/src/libical-glib/api/i-cal-property.xml +++ b/src/libical-glib/api/i-cal-property.xml @@ -19,8 +19,8 @@ Create a #ICalProperty of the target type. - - + + Deeply clone a #ICalProperty. diff --git a/src/libical-glib/api/i-cal-value.xml b/src/libical-glib/api/i-cal-value.xml index 6320a9612..ee0d31bb2 100644 --- a/src/libical-glib/api/i-cal-value.xml +++ b/src/libical-glib/api/i-cal-value.xml @@ -19,7 +19,7 @@ Create a new #ICalValue with specific kind. - + Deeply clone a #ICalValue. diff --git a/src/libical/CMakeLists.txt b/src/libical/CMakeLists.txt index eadc995f4..f5922f181 100644 --- a/src/libical/CMakeLists.txt +++ b/src/libical/CMakeLists.txt @@ -399,6 +399,7 @@ install(FILES icaltimezone.h icaltypes.h icalvalue.h + libical_deprecated.h libical_ical_export.h pvl.h sspm.h diff --git a/src/libical/astime.h b/src/libical/astime.h index 2b95d6d18..f7b8367a7 100644 --- a/src/libical/astime.h +++ b/src/libical/astime.h @@ -67,8 +67,8 @@ #ifndef ICAL_ASTIME_H #define ICAL_ASTIME_H +#include "libical_deprecated.h" #include "libical_ical_export.h" -#include typedef struct ut_instant { @@ -91,12 +91,12 @@ typedef struct ut_instant /** converts julian date to year,mo,da * @deprecated use caldat_int() instead */ -LIBICAL_ICAL_EXPORT _deprecated(long caldat(UTinstantPtr)); +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(long caldat(UTinstantPtr)); /** returns julian day from year,mo,da * @deprecated use juldat_int() instead */ -LIBICAL_ICAL_EXPORT _deprecated(double juldat(UTinstantPtr)); +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(double juldat(UTinstantPtr)); typedef struct ut_instant_int { diff --git a/src/libical/icalcomponent.c b/src/libical/icalcomponent.c index 41c212390..15b4180c2 100644 --- a/src/libical/icalcomponent.c +++ b/src/libical/icalcomponent.c @@ -145,7 +145,7 @@ icalcomponent *icalcomponent_new_from_string(const char *str) /** @brief Constructor */ -icalcomponent *icalcomponent_new_clone(icalcomponent *old) +icalcomponent *icalcomponent_clone(const icalcomponent *old) { icalcomponent *new; icalproperty *p; @@ -162,17 +162,22 @@ icalcomponent *icalcomponent_new_clone(icalcomponent *old) for (itr = pvl_head(old->properties); itr != 0; itr = pvl_next(itr)) { p = (icalproperty *) pvl_data(itr); - icalcomponent_add_property(new, icalproperty_new_clone(p)); + icalcomponent_add_property(new, icalproperty_clone(p)); } for (itr = pvl_head(old->components); itr != 0; itr = pvl_next(itr)) { c = (icalcomponent *) pvl_data(itr); - icalcomponent_add_component(new, icalcomponent_new_clone(c)); + icalcomponent_add_component(new, icalcomponent_clone(c)); } return new; } +icalcomponent *icalcomponent_new_clone(icalcomponent *old) +{ + return icalcomponent_clone(old); +} + /** @brief Constructor */ icalcomponent *icalcomponent_new_x(const char *x_name) diff --git a/src/libical/icalcomponent.h b/src/libical/icalcomponent.h index dbedf08e4..7b3b47559 100644 --- a/src/libical/icalcomponent.h +++ b/src/libical/icalcomponent.h @@ -20,6 +20,7 @@ #ifndef ICALCOMPONENT_H #define ICALCOMPONENT_H +#include "libical_deprecated.h" #include "libical_ical_export.h" #include "icalenums.h" /* defines icalcomponent_kind */ #include "icalproperty.h" @@ -36,9 +37,14 @@ typedef struct icalcompiter } icalcompiter; +/** + * Deeply clone an icalcomponent. + * Returns a pointer to the memory for the newly cloned icalcomponent. + * @since 3.1.0 + */ LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_new(icalcomponent_kind kind); -LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_new_clone(icalcomponent *component); +LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_clone(const icalcomponent *component); LIBICAL_ICAL_EXPORT icalcomponent *icalcomponent_new_from_string(const char *str); @@ -58,9 +64,14 @@ LIBICAL_ICAL_EXPORT icalcomponent_kind icalcomponent_isa(const icalcomponent *co LIBICAL_ICAL_EXPORT int icalcomponent_isa_component(void *component); -/* - * Working with properties +/** + * @copydoc icalcomponent_clone() + * @deprecated use icalcomponent_clone() instead */ +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(icalcomponent *icalcomponent_new_clone( + icalcomponent *component)); + +/***** Working with Properties *****/ LIBICAL_ICAL_EXPORT void icalcomponent_add_property(icalcomponent *component, icalproperty *property); @@ -91,9 +102,7 @@ LIBICAL_ICAL_EXPORT icalproperty *icalcomponent_get_first_property(icalcomponent LIBICAL_ICAL_EXPORT icalproperty *icalcomponent_get_next_property(icalcomponent *component, icalproperty_kind kind); -/* - * Working with components - */ +/***** Working with Components *****/ /* Return the first VEVENT, VTODO or VJOURNAL sub-component of cop, or comp if it is one of those types */ @@ -141,7 +150,7 @@ LIBICAL_ICAL_EXPORT icalcomponent *icalcompiter_prior(icalcompiter * i); LIBICAL_ICAL_EXPORT icalcomponent *icalcompiter_deref(icalcompiter * i); -/* Working with embedded error properties */ +/***** Working with embedded error properties *****/ /* Check the component against itip rules and insert error properties*/ /* Working with embedded error properties */ diff --git a/src/libical/icalparameter.c b/src/libical/icalparameter.c index 39a907cc3..95dd88b4e 100644 --- a/src/libical/icalparameter.c +++ b/src/libical/icalparameter.c @@ -82,7 +82,7 @@ void icalparameter_free(icalparameter *param) free(param); } -icalparameter *icalparameter_new_clone(icalparameter *old) +icalparameter *icalparameter_clone(const icalparameter *old) { struct icalparameter_impl *new; @@ -117,6 +117,11 @@ icalparameter *icalparameter_new_clone(icalparameter *old) return new; } +icalparameter *icalparameter_new_clone(icalparameter *old) +{ + return icalparameter_clone(old); +} + icalparameter *icalparameter_new_from_string(const char *str) { char *eq; diff --git a/src/libical/icalparameter.h b/src/libical/icalparameter.h index d4e5d1ed6..687c7d1c2 100644 --- a/src/libical/icalparameter.h +++ b/src/libical/icalparameter.h @@ -27,6 +27,7 @@ #ifndef ICALPARAMETER_H #define ICALPARAMETER_H +#include "libical_deprecated.h" #include "libical_ical_export.h" #include "icalderivedparameter.h" @@ -82,7 +83,7 @@ LIBICAL_ICAL_EXPORT icalparameter *icalparameter_new(icalparameter_kind kind); * icalparameter *param = icalparameter_new_from_string("ROLE=CHAIR"); * * // clone the parameter - * icalparameter *clone = icalparameter_new_clone(param); + * icalparameter *clone = icalparameter_clone(param); * * if(clone) { * // use clone ... @@ -92,8 +93,15 @@ LIBICAL_ICAL_EXPORT icalparameter *icalparameter_new(icalparameter_kind kind); * icalparameter_free(param); * icalparameter_free(clone); * ``` + * @since 3.1.0 */ -LIBICAL_ICAL_EXPORT icalparameter *icalparameter_new_clone(icalparameter *p); +LIBICAL_ICAL_EXPORT icalparameter *icalparameter_clone(const icalparameter *p); + +/** + * @copydoc icalparameter_clone() + * @deprecated use icalparameter_clone() instead + */ +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(icalparameter *icalparameter_new_clone(icalparameter *p)); /** * @brief Create ::icalparameter object from string @@ -158,9 +166,10 @@ LIBICAL_ICAL_EXPORT icalparameter *icalparameter_new_from_value_string(icalparam * @param parameter The icalparameter to free * * This method needs to be used on all parameter objects returned - * from any of the `_new()` methods including icalparameter_new(), icalparameter_new_clone(), - * icalparameter_new_from_string() and icalparameter_new_from_value_string(), - * when they are not needed anymore and to be released. + * from any of the `_new()` methods including icalparameter_new(), + * icalparameter_new_from_string() and icalparameter_new_from_value_string() + * and on cloned parameter objects returned by icalparameter_clone() + * when these object are not needed anymore and to be released. * * ### Usage * ```c diff --git a/src/libical/icalparameter_cxx.cpp b/src/libical/icalparameter_cxx.cpp index c672d9da9..0f6e69d14 100644 --- a/src/libical/icalparameter_cxx.cpp +++ b/src/libical/icalparameter_cxx.cpp @@ -24,7 +24,7 @@ ICalParameter::ICalParameter() : imp(icalparameter_new(ICAL_ANY_PARAMETER)) { } -ICalParameter::ICalParameter(const ICalParameter &v) : imp(icalparameter_new_clone(v.imp)) +ICalParameter::ICalParameter(const ICalParameter &v) : imp(icalparameter_clone(v.imp)) { if (imp == NULL) { throw icalerrno; @@ -39,7 +39,7 @@ ICalParameter &ICalParameter::operator=(const ICalParameter &v) if (imp != NULL) { icalparameter_free(imp); - imp = icalparameter_new_clone(v.imp); + imp = icalparameter_clone(v.imp); if (imp == NULL) { throw icalerrno; } diff --git a/src/libical/icalparser.c b/src/libical/icalparser.c index fa71e8bd3..0dd913ff8 100644 --- a/src/libical/icalparser.c +++ b/src/libical/icalparser.c @@ -1146,7 +1146,7 @@ icalcomponent *icalparser_add_line(icalparser *parser, char *line) if (vcount > 0) { /* Actually, only clone after the second value */ - icalproperty *clone = icalproperty_new_clone(prop); + icalproperty *clone = icalproperty_clone(prop); icalcomponent *tail = pvl_data(pvl_tail(parser->components)); icalcomponent_add_property(tail, clone); diff --git a/src/libical/icalproperty.c b/src/libical/icalproperty.c index 64b502681..b84867a95 100644 --- a/src/libical/icalproperty.c +++ b/src/libical/icalproperty.c @@ -92,7 +92,7 @@ icalproperty *icalproperty_new(icalproperty_kind kind) return (icalproperty *) icalproperty_new_impl(kind); } -icalproperty *icalproperty_new_clone(icalproperty *old) +icalproperty *icalproperty_clone(const icalproperty *old) { icalproperty *new; pvl_elem p; @@ -102,7 +102,7 @@ icalproperty *icalproperty_new_clone(icalproperty *old) icalerror_check_arg_rz((new != 0), "new"); if (old->value != 0) { - new->value = icalvalue_new_clone(old->value); + new->value = icalvalue_clone(old->value); } if (old->x_name != 0) { @@ -117,7 +117,7 @@ icalproperty *icalproperty_new_clone(icalproperty *old) } for (p = pvl_head(old->parameters); p != 0; p = pvl_next(p)) { - icalparameter *param = icalparameter_new_clone(pvl_data(p)); + icalparameter *param = icalparameter_clone(pvl_data(p)); if (param == 0) { icalproperty_free(new); @@ -131,6 +131,11 @@ icalproperty *icalproperty_new_clone(icalproperty *old) return new; } +icalproperty *icalproperty_new_clone(icalproperty *old) +{ + return icalproperty_clone(old); +} + icalproperty *icalproperty_new_from_string(const char *str) { size_t buf_size = 1024; diff --git a/src/libical/icalproperty.h b/src/libical/icalproperty.h index 70daba98b..210b0c817 100644 --- a/src/libical/icalproperty.h +++ b/src/libical/icalproperty.h @@ -20,6 +20,7 @@ #ifndef ICALPROPERTY_H #define ICALPROPERTY_H +#include "libical_deprecated.h" #include "libical_ical_export.h" #include "icalderivedproperty.h" /* To get icalproperty_kind enumerations */ @@ -29,7 +30,12 @@ LIBICAL_ICAL_EXPORT icalproperty *icalproperty_new(icalproperty_kind kind); LIBICAL_ICAL_EXPORT icalproperty *icalproperty_new_impl(icalproperty_kind kind); -LIBICAL_ICAL_EXPORT icalproperty *icalproperty_new_clone(icalproperty *prop); +/** + * Deeply clone an icalproperty. + * Returns a pointer to the memory for the newly cloned icalproperty. + * @since 3.1.0 + */ +LIBICAL_ICAL_EXPORT icalproperty *icalproperty_clone(const icalproperty *prop); LIBICAL_ICAL_EXPORT icalproperty *icalproperty_new_from_string(const char *str); @@ -147,4 +153,10 @@ LIBICAL_ICAL_EXPORT int icalproperty_enum_belongs_to_property(icalproperty_kind */ LIBICAL_ICAL_EXPORT void icalproperty_normalize(icalproperty *prop); +/** + * @copydoc icalproperty_clone() + * @deprecated use icalproperty_clone() instead + */ +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(icalproperty *icalproperty_new_clone(icalproperty *prop)); + #endif /*ICALPROPERTY_H */ diff --git a/src/libical/icalproperty_cxx.cpp b/src/libical/icalproperty_cxx.cpp index 16cedf477..58d81fe93 100644 --- a/src/libical/icalproperty_cxx.cpp +++ b/src/libical/icalproperty_cxx.cpp @@ -26,7 +26,7 @@ ICalProperty::ICalProperty() : imp(icalproperty_new(ICAL_ANY_PROPERTY)) { } -ICalProperty::ICalProperty(const ICalProperty &v) : imp(icalproperty_new_clone(v.imp)) +ICalProperty::ICalProperty(const ICalProperty &v) : imp(icalproperty_clone(v.imp)) { if (imp == NULL) { throw icalerrno; @@ -41,7 +41,7 @@ ICalProperty &ICalProperty::operator=(const ICalProperty &v) if (imp != NULL) { icalproperty_free(imp); - imp = icalproperty_new_clone(v.imp); + imp = icalproperty_clone(v.imp); if (imp == NULL) { throw icalerrno; } diff --git a/src/libical/icalvalue.c b/src/libical/icalvalue.c index 44541498c..976a0f9df 100644 --- a/src/libical/icalvalue.c +++ b/src/libical/icalvalue.c @@ -64,7 +64,7 @@ icalvalue *icalvalue_new(icalvalue_kind kind) return (icalvalue *) icalvalue_new_impl(kind); } -icalvalue *icalvalue_new_clone(const icalvalue *old) +icalvalue *icalvalue_clone(const icalvalue *old) { struct icalvalue_impl *new; @@ -167,6 +167,11 @@ icalvalue *icalvalue_new_clone(const icalvalue *old) return new; } +icalvalue *icalvalue_new_clone(const icalvalue *old) +{ + return icalvalue_clone(old); +} + static char *icalmemory_strdup_and_dequote(const char *str) { const char *p; diff --git a/src/libical/icalvalue.h b/src/libical/icalvalue.h index 4060b047e..c7470cfb2 100644 --- a/src/libical/icalvalue.h +++ b/src/libical/icalvalue.h @@ -20,15 +20,21 @@ #ifndef ICALVALUE_H #define ICALVALUE_H +#include "libical_deprecated.h" #include "libical_ical_export.h" #include "icalvalueimpl.h" #define ICAL_BOOLEAN_TRUE 1 #define ICAL_BOOLEAN_FALSE 0 +/** + * Deeply clone an icalvalue. + * Returns a pointer to the memory for the newly cloned icalvalue. + * @since 3.1.0 + */ LIBICAL_ICAL_EXPORT icalvalue *icalvalue_new(icalvalue_kind kind); -LIBICAL_ICAL_EXPORT icalvalue *icalvalue_new_clone(const icalvalue *value); +LIBICAL_ICAL_EXPORT icalvalue *icalvalue_clone(const icalvalue *value); LIBICAL_ICAL_EXPORT icalvalue *icalvalue_new_from_string(icalvalue_kind kind, const char *str); @@ -47,6 +53,12 @@ LIBICAL_ICAL_EXPORT int icalvalue_isa_value(void *); LIBICAL_ICAL_EXPORT icalparameter_xliccomparetype icalvalue_compare(const icalvalue *a, const icalvalue *b); +/** + * @copydoc icalvalue_clone() + * @deprecated use icalvalue_clone() instead + */ +LIBICAL_ICAL_EXPORT LIBICAL_DEPRECATED(icalvalue *icalvalue_new_clone(const icalvalue *value)); + /* Special, non autogenerated value accessors */ /* Defined in icalderivedvalue.h */ diff --git a/src/libical/icalvalue_cxx.cpp b/src/libical/icalvalue_cxx.cpp index 3575fc2fb..e04b7fb34 100644 --- a/src/libical/icalvalue_cxx.cpp +++ b/src/libical/icalvalue_cxx.cpp @@ -26,7 +26,7 @@ ICalValue::ICalValue() : imp(icalvalue_new(ICAL_ANY_VALUE)) { } -ICalValue::ICalValue(const ICalValue &v) : imp(icalvalue_new_clone(v.imp)) +ICalValue::ICalValue(const ICalValue &v) : imp(icalvalue_clone(v.imp)) { if (imp == NULL) { throw icalerrno; @@ -41,7 +41,7 @@ ICalValue &ICalValue::operator=(const ICalValue &v) if (imp != NULL) { icalvalue_free(imp); - imp = icalvalue_new_clone(v.imp); + imp = icalvalue_clone(v.imp); if (imp == NULL) { throw icalerrno; } diff --git a/src/libical/libical_deprecated.h b/src/libical/libical_deprecated.h new file mode 100644 index 000000000..d1fa9dadd --- /dev/null +++ b/src/libical/libical_deprecated.h @@ -0,0 +1,19 @@ +#ifndef LIBICAL_DEPRECATED_H +#define LIBICAL_DEPRECATED_H + +/* Deprecated function macro */ +#if defined(NO_DEPRECATION_WARNINGS) +#define LIBICAL_DEPRECATED(x) x +#else +#if !defined(LIBICAL_DEPRECATED) +#ifdef __GNUC__ +#define LIBICAL_DEPRECATED(x) x __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define LIBICAL_DEPRECATED(x) __declspec(deprecated) x +#else +#define LIBICAL_DEPRECATED(x) x +#endif +#endif +#endif + +#endif diff --git a/src/libical/vcomponent_cxx.cpp b/src/libical/vcomponent_cxx.cpp index 3c7860c47..857ead667 100644 --- a/src/libical/vcomponent_cxx.cpp +++ b/src/libical/vcomponent_cxx.cpp @@ -37,7 +37,7 @@ VComponent::VComponent() : imp(icalcomponent_new(ICAL_ANY_COMPONENT)) { } -VComponent::VComponent(const VComponent &v) : imp(icalcomponent_new_clone(v.imp)) +VComponent::VComponent(const VComponent &v) : imp(icalcomponent_clone(v.imp)) { if (imp == NULL) { throw icalerrno; @@ -52,7 +52,7 @@ VComponent &VComponent::operator=(const VComponent &v) if (imp != NULL) { icalcomponent_free(imp); - imp = icalcomponent_new_clone(v.imp); + imp = icalcomponent_clone(v.imp); if (imp == NULL) { throw icalerrno; } diff --git a/src/libicalss/icalclassify.c b/src/libicalss/icalclassify.c index 17bce19de..f19b6ccae 100644 --- a/src/libicalss/icalclassify.c +++ b/src/libicalss/icalclassify.c @@ -90,7 +90,7 @@ icalcomponent *icalclassify_find_overlaps(icalset *set, icalcomponent *comp) if (compspan.start < span.end && compspan.end > span.start) { - icalcomponent *clone = icalcomponent_new_clone(c); + icalcomponent *clone = icalcomponent_clone(c); icalcomponent_add_component(return_set, clone); } diff --git a/src/libicalss/icalcluster.c b/src/libicalss/icalcluster.c index a11046e46..a0824a50d 100644 --- a/src/libicalss/icalcluster.c +++ b/src/libicalss/icalcluster.c @@ -56,7 +56,6 @@ static icalcluster *icalcluster_new_impl(void) * * @todo Always do a deep copy. */ - icalcluster *icalcluster_new(const char *key, icalcomponent *data) { struct icalcluster_impl *impl = icalcluster_new_impl(); @@ -72,7 +71,7 @@ icalcluster *icalcluster_new(const char *key, icalcomponent *data) impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT); icalcomponent_add_component(impl->data, data); } else { - impl->data = icalcomponent_new_clone(data); + impl->data = icalcomponent_clone(data); } } else { impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT); @@ -85,18 +84,27 @@ icalcluster *icalcluster_new(const char *key, icalcomponent *data) * Deep clone an icalcluster to a new one */ -icalcluster *icalcluster_new_clone(const icalcluster *data) +icalcluster *icalcluster_clone(const icalcluster *data) { struct icalcluster_impl *old = (struct icalcluster_impl *)data; struct icalcluster_impl *impl = icalcluster_new_impl(); impl->key = strdup(old->key); - impl->data = icalcomponent_new_clone(old->data); + impl->data = icalcomponent_clone(old->data); impl->changed = 0; return impl; } +/** + * Deprecated function to clone a cluster + * @deprecated use ucalcluster_clone() instead + */ +icalcluster *icalcluster_new_clone(const icalcluster *data) +{ + return icalcluster_clone(data); +} + void icalcluster_free(icalcluster *impl) { icalerror_check_arg_rv((impl != 0), "cluster"); diff --git a/src/libicalss/icalcluster.h b/src/libicalss/icalcluster.h index 8116012bb..fea99ef32 100644 --- a/src/libicalss/icalcluster.h +++ b/src/libicalss/icalcluster.h @@ -19,6 +19,7 @@ #ifndef ICALCLUSTER_H #define ICALCLUSTER_H +#include "libical_deprecated.h" #include "libical_icalss_export.h" #include "icalcomponent.h" #include "icalerror.h" @@ -27,7 +28,12 @@ typedef struct icalcluster_impl icalcluster; LIBICAL_ICALSS_EXPORT icalcluster *icalcluster_new(const char *key, icalcomponent *data); -LIBICAL_ICALSS_EXPORT icalcluster *icalcluster_new_clone(const icalcluster *cluster); +/** + * Deeply clone an icalcluster. + * Returns a pointer to the memory for the newly cloned icalcluster. + * @since 3.1.0 +*/ +LIBICAL_ICALSS_EXPORT icalcluster *icalcluster_clone(const icalcluster *cluster); LIBICAL_ICALSS_EXPORT void icalcluster_free(icalcluster *cluster); @@ -56,4 +62,11 @@ LIBICAL_ICALSS_EXPORT icalcomponent *icalcluster_get_first_component(icalcluster LIBICAL_ICALSS_EXPORT icalcomponent *icalcluster_get_next_component(icalcluster *cluster); +/** + * @copydoc icalcluster_new() + * @deprecated use icalcluster_clone() instead + */ +LIBICAL_ICALSS_EXPORT LIBICAL_DEPRECATED(icalcluster *icalcluster_new_clone( + const icalcluster *cluster)); + #endif /* !ICALCLUSTER_H */ diff --git a/src/libicalss/icalfileset.c b/src/libicalss/icalfileset.c index b35b90bb2..6eb4600a4 100644 --- a/src/libicalss/icalfileset.c +++ b/src/libicalss/icalfileset.c @@ -113,7 +113,7 @@ icalset *icalfileset_init(icalset *set, const char *path, void *options_in) } if (options->cluster) { - fset->cluster = icalcomponent_new_clone(icalcluster_get_component(options->cluster)); + fset->cluster = icalcomponent_clone(icalcluster_get_component(options->cluster)); fset->changed = 1; } diff --git a/src/libicalss/icalmessage.c b/src/libicalss/icalmessage.c index 4cd9e1d2b..79d3cddea 100644 --- a/src/libicalss/icalmessage.c +++ b/src/libicalss/icalmessage.c @@ -100,7 +100,7 @@ static void icalmessage_copy_properties(icalcomponent *to, icalcomponent *from, icalcomponent_add_property( to_inner, - icalproperty_new_clone(icalcomponent_get_first_property(from_inner, kind))); + icalproperty_clone(icalcomponent_get_first_property(from_inner, kind))); } static icalcomponent *icalmessage_new_reply_base(icalcomponent *c, @@ -144,7 +144,7 @@ static icalcomponent *icalmessage_new_reply_base(icalcomponent *c, return 0; } - icalcomponent_add_property(inner, icalproperty_new_clone(attendee)); + icalcomponent_add_property(inner, icalproperty_clone(attendee)); /* Add PRODID and VERSION */ @@ -309,7 +309,7 @@ icalcomponent *icalmessage_new_error_reply(icalcomponent *c, for (p = icalcomponent_get_first_property(cinner, ICAL_REQUESTSTATUS_PROPERTY); p != 0; p = icalcomponent_get_next_property(cinner, ICAL_REQUESTSTATUS_PROPERTY)) { - icalcomponent_add_property(inner, icalproperty_new_clone(p)); + icalcomponent_add_property(inner, icalproperty_clone(p)); } } diff --git a/src/test/copycluster.c b/src/test/copycluster.c index 258c556fb..b16a3c3c6 100644 --- a/src/test/copycluster.c +++ b/src/test/copycluster.c @@ -104,7 +104,7 @@ int main(int c, char *argv[]) if (tostdout) { printf("--------------\n%s\n", icalcomponent_as_ical_string(itr)); } else { - (void)icalfileset_add_component(clusterout, icalcomponent_new_clone(itr)); + (void)icalfileset_add_component(clusterout, icalcomponent_clone(itr)); } count++; } diff --git a/src/test/process.c b/src/test/process.c index f4734219c..a5038b90c 100644 --- a/src/test/process.c +++ b/src/test/process.c @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) if (overlaps == 0) { /* No overlaps, book the meeting */ -/* icalset_add_component(cal,icalcomponent_new_clone(c));*/ +/* icalset_add_component(cal,icalcomponent_clone(c));*/ /* Return a reply */ reply = @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) next_time = icalspanlist_next_free_time(spanl, icalcomponent_get_dtstart(c)); - newc = icalcomponent_new_clone(c); + newc = icalcomponent_clone(c); icalcomponent_set_dtstart(newc, next_time.start); diff --git a/src/test/regression-storage.c b/src/test/regression-storage.c index 6051e82ac..1bc9a4dc4 100644 --- a/src/test/regression-storage.c +++ b/src/test/regression-storage.c @@ -168,7 +168,7 @@ void test_fileset_extended(void) start.month = month; end.month = month; - clone = icalcomponent_new_clone(c); + clone = icalcomponent_clone(c); ok("Making clone of output file", (clone != 0)); assert(clone != 0); @@ -349,7 +349,7 @@ void test_bdbset() start.month = month; end.month = month; - clone = icalcomponent_new_clone(c); + clone = icalcomponent_clone(c); assert(clone != 0); event = icalcomponent_get_first_component(clone, ICAL_VEVENT_COMPONENT); assert(event != 0); @@ -670,7 +670,7 @@ void test_dirset_extended(void) /* Change the dtstart and dtend times in the component pointed to by Itr */ - (void)icalcomponent_new_clone(itr); + (void)icalcomponent_clone(itr); inner = icalcomponent_get_first_component(itr, ICAL_VEVENT_COMPONENT); ok("Duplicating component...", (icalerrno == ICAL_NO_ERROR) && (inner != 0)); @@ -710,7 +710,7 @@ void test_dirset_extended(void) if (VERBOSE) printf("\n----------\n%s\n---------\n", icalcomponent_as_ical_string(inner)); - error = icaldirset_add_component(s, icalcomponent_new_clone(itr)); + error = icaldirset_add_component(s, icalcomponent_clone(itr)); ok("Adding component to dirset", (icalerrno == ICAL_NO_ERROR)); assert(error == ICAL_NO_ERROR); diff --git a/src/test/regression.c b/src/test/regression.c index 8febe7571..020627a40 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -190,9 +190,9 @@ void test_values() str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "cap://value/2"); - copy = icalvalue_new_clone(v); + copy = icalvalue_clone(v); - str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "cap://value/2"); + str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "cap://value/2"); icalvalue_free(v); icalvalue_free(copy); @@ -203,8 +203,8 @@ void test_values() ok("icalvalue_set_boolean(2)", (2 == icalvalue_get_boolean(v))); str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "TRUE"); - copy = icalvalue_new_clone(v); - str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "TRUE"); + copy = icalvalue_clone(v); + str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "TRUE"); icalvalue_free(v); icalvalue_free(copy); @@ -215,8 +215,8 @@ void test_values() str_is("icalvalue_set_x(test2)", icalvalue_get_x(v), "test2"); str_is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "test2"); - copy = icalvalue_new_clone(v); - str_is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "test2"); + copy = icalvalue_clone(v); + str_is("icalvalue_clone()", icalvalue_as_ical_string(copy), "test2"); icalvalue_free(v); icalvalue_free(copy); @@ -226,8 +226,8 @@ void test_values() icalvalue_set_datetime(v, icaltime_from_timet_with_zone(1023404802 - 3600, 0, NULL)); str_is("icalvalue_set_datetime()", icalvalue_as_ical_string(v), "20020606T220642"); - copy = icalvalue_new_clone(v); - str_is("icalvalue_new_clone()", icalvalue_as_ical_string(v), "20020606T220642"); + copy = icalvalue_clone(v); + str_is("icalvalue_clone()", icalvalue_as_ical_string(v), "20020606T220642"); icalvalue_free(v); icalvalue_free(copy); @@ -323,12 +323,12 @@ void test_properties() } str_is("icalproperty_as_ical_string()", icalproperty_as_ical_string(prop), test_ical_str_good); - clone = icalproperty_new_clone(prop); + clone = icalproperty_clone(prop); if (VERBOSE) { printf("Clone:\n %s\n", icalproperty_as_ical_string(prop)); } - str_is("icalproperty_new_clone()", icalproperty_as_ical_string(prop), test_ical_str_good); + str_is("icalproperty_clone()", icalproperty_as_ical_string(prop), test_ical_str_good); icalproperty_free(clone); icalproperty_free(prop); @@ -954,7 +954,7 @@ void test_dirset() /* Change the dtstart and dtend times in the component pointed to by Itr */ - clone = icalcomponent_new_clone(itr); + clone = icalcomponent_clone(itr); assert(icalerrno == ICAL_NO_ERROR); assert(clone != 0); @@ -1026,7 +1026,7 @@ void test_compare() icalvalue *v1, *v2; v1 = icalvalue_new_caladdress("cap://value/1"); - v2 = icalvalue_new_clone(v1); + v2 = icalvalue_clone(v1); ok("compare value and clone", (icalvalue_compare(v1, v2) == ICAL_XLICCOMPARETYPE_EQUAL)); @@ -1194,7 +1194,7 @@ void test_calendar() c = icalcalendar_get_properties(calendar); - error = icalfileset_add_component(c, icalcomponent_new_clone(comp)); + error = icalfileset_add_component(c, icalcomponent_clone(comp)); ok("Adding Clone Component to dirset", (error == ICAL_NO_ERROR)); @@ -2247,7 +2247,7 @@ void test_icalset() icalcomponent *clone; - clone = icalcomponent_new_clone(c); + clone = icalcomponent_clone(c); (void)icalset_add_component(d, clone); @@ -3403,7 +3403,7 @@ void test_file_locks() (void)icalfileset_add_component(fs, c); - c2 = icalcomponent_new_clone(c); + c2 = icalcomponent_clone(c); (void)icalfileset_add_component(fs, c2); @@ -3439,7 +3439,7 @@ void test_file_locks() icalcomponent_set_duration(c, d); icalcomponent_set_summary(c, "Child"); - c2 = icalcomponent_new_clone(c); + c2 = icalcomponent_clone(c); icalcomponent_set_summary(c2, "Child"); (void)icalfileset_add_component(fs, c2); @@ -3472,7 +3472,7 @@ void test_file_locks() icalcomponent_set_duration(c, d); icalcomponent_set_summary(c, "Parent"); - c2 = icalcomponent_new_clone(c); + c2 = icalcomponent_clone(c); icalcomponent_set_summary(c2, "Parent"); (void)icalfileset_add_component(fs, c2); diff --git a/src/test/stow.c b/src/test/stow.c index f425288a1..1d15b59d9 100644 --- a/src/test/stow.c +++ b/src/test/stow.c @@ -290,11 +290,11 @@ icalcomponent *make_reply(icalcomponent *comp, icalproperty *return_status, icalproperty_new_method(ICAL_METHOD_REPLY), icalcomponent_vanew( ICAL_VEVENT_COMPONENT, - icalproperty_new_clone( + icalproperty_clone( icalcomponent_get_first_property(inner, ICAL_DTSTAMP_PROPERTY)), - icalproperty_new_clone( + icalproperty_clone( icalcomponent_get_first_property(inner, ICAL_ORGANIZER_PROPERTY)), - icalproperty_new_clone( + icalproperty_clone( icalcomponent_get_first_property(inner, ICAL_UID_PROPERTY)), icalproperty_new_attendee(attendee), 0), @@ -310,7 +310,7 @@ icalcomponent *make_reply(icalcomponent *comp, icalproperty *return_status, for (p = icalcomponent_get_first_property(inner, ICAL_REQUESTSTATUS_PROPERTY); p != 0; p = icalcomponent_get_next_property(inner, ICAL_REQUESTSTATUS_PROPERTY)) { - icalcomponent_add_property(rinner, icalproperty_new_clone(p)); + icalcomponent_add_property(rinner, icalproperty_clone(p)); } if (return_status != 0) {