src/backends/evolution/libical/icalstrdup.c File Reference

#include "libical/icalstrdup.h"
#include <string.h>

Include dependency graph for icalstrdup.c:

Go to the source code of this file.

Functions

char * ical_strdup (const char *x)


Function Documentation

char* ical_strdup ( const char *  x  ) 

The patch in http://bugzilla.gnome.org/show_bug.cgi?id=516408 changes the ownership of strings returned by some libical and libecal functions: previously, the memory was owned by the library. After the patch the caller owns the copied string and must free it.

The upstream SourceForge libical has incorporated the patch, but without changing the semantic of the existing calls. Instead they added _r variants which return memory that the caller must free. As soon as Evolution switches to upstream libical (planned for 2.25), it probably will have to bump the libecal version because the API is reverted so that binaries which free strings will crash. When EVOLUTION_COMPATIBILITY is defined, SyncEvolution deals with this by always checking at runtime what the memory handling is.

This utility function ensures that the caller *always* owns the returned string. When compiled against a current Evolution Dataserver, the function becomes a NOP macro, unless compatibility mode is on (in which case the current binary might later run with an older Evolution release!). If not a NOP macro, then the function duplicates the string; it handles NULL by passing it through.

When compiled against an old Evolution Dataserver, then a runtime check can be enabled to to determine whether the string needs to be duplicated. If uncertain, it always duplicates the string. If the check fails, then memory is leaked, which also happens when running programs which do not know about the patch.

To enable the runtime check, compile the .c file with -D_GNU_SOURCE and -DHAVE_DLFCN_H. If HAVE_CONFIG_H is set, then config.h is included and can be set to set some of these defines. If enabled, then link with -ldl.

ical_strdup() must be wrapped around the following functions:

  • icalreqstattype_as_string
  • icalproperty_as_ical_string
  • icalproperty_get_parameter_as_string
  • icalproperty_get_value_as_string
  • icallangbind_property_eval_string
  • icalperiodtype_as_ical_string
  • icaltime_as_ical_string
  • icalvalue_as_ical_string
  • icalcomponent_as_ical_string
  • e_cal_component_get_recurid_as_string

Parameters:
x result of one of the functions above
Returns:
string which has to be freed by caller, may be NULL if x was NULL

Definition at line 35 of file icalstrdup.c.


Generated on Sat Oct 18 17:16:50 2008 for SyncEvolution and Funambol by  doxygen 1.5.7.1