Re: [Evolution-hackers] detecting new ical memory tracking

2008-05-06 Thread Patrick Ohly
On Mon, 2008-04-21 at 11:13 +0530, Srinivasa Ragavan wrote:
 Your deal is to add a new global variable, and dlopen it to find if it
 is new e-d-s or not. Is there something new we already added in 2.22.x
 that you can find to dlopen, instead of adding a new ?

As discussed in the bug tracker, there was no such change and if if
there had been, it would have been risky to rely on unrelated changes to
detect the memfix patch.

The ical_memfix variable is now part of trunk and gnome-2-22. If there
are any other client library in the same situation as myself, you might
find the attached code from SyncEvolution useful. I tried both compiling
against 2.22.x directly as well as compiling against 2.12 and running
with 2.22.x (this is actually now part of the nightly testing).

-- 
Bye, Patrick Ohly
--  
[EMAIL PROTECTED]
http://www.estamos.de/
/*
 * Copyright (C) 2008 Patrick Ohly
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#include libical/icalstrdup.h

#ifndef LIBICAL_MEMFIXES

#if defined(HAVE_CONFIG_H)
# include config.h
#endif

#if defined(_GNU_SOURCE)  defined(HAVE_DLFCN_H)
# include dlfcn.h
# define LIBICAL_RUNTIME_CHECK
#endif

#include string.h

char *ical_strdup(const char *x)
{
#ifdef LIBICAL_RUNTIME_CHECK
static enum {
PATCH_UNCHECKED,
PATCH_FOUND,
PATCH_NOT_FOUND
} patch_status;

if (patch_status == PATCH_UNCHECKED) {
patch_status = dlsym(RTLD_NEXT, ical_memfixes) != NULL ?
PATCH_FOUND : PATCH_NOT_FOUND;
}

if (patch_status == PATCH_FOUND) {
/* patch applied, not need to copy */
return (char *)x;
}
#endif

return x ? strdup(x) : NULL;
}

#endif /* !LIBICAL_MEMFIXES */
/*
 * Copyright (C) 2008 Patrick Ohly
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#ifndef ICALSTRDUP_H
#define ICALSTRDUP_H

#ifndef HANDLE_LIBICAL_MEMORY
# define HANDLE_LIBICAL_MEMORY 1
#endif
#include libical/ical.h

#ifdef __cplusplus
extern C {
#pragma }
#endif /* __cplusplus */

#ifndef LIBICAL_MEMFIXES
/**
 * 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.
 *
 * 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. Otherwise 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
 *
 * @param xresult of one of the functions above
 * @return 

Re: [Evolution-hackers] detecting new ical memory tracking

2008-04-20 Thread Patrick Ohly
Hello,

this issue is getting urgent and needs to be solved, otherwise I cannot
get rid of the memory leaks which currently break the nightly testing
with trunk.

I have created http://bugzilla.gnome.org/show_bug.cgi?id=528986 with the
appeal to add the ical_memfixes variable (patch attached to that bug
again). Please apply or implement some other runtime detection
mechanism. These also needs to go into 22.x.

-- 
Bye, Patrick Ohly
--  
[EMAIL PROTECTED]
http://www.estamos.de/

___
Evolution-hackers mailing list
Evolution-hackers@gnome.org
http://mail.gnome.org/mailman/listinfo/evolution-hackers


Re: [Evolution-hackers] detecting new ical memory tracking

2008-04-08 Thread Matthew Barnes
On Tue, 2008-04-08 at 21:42 +0200, Patrick Ohly wrote:
 Introducing the code rewrite suggested by Michael is impossible. Can I
 have the less intrusive patch included on trunk and the stable branch,
 please? Or is there some other version number which can be queried at
 runtime? I'd rather not parse /proc/self/maps to find out what the
 revision of libecal is... As discussed in #516408, checking the version
 number would be sub-optimal.

More broadly, we should add some versioning macros and symbols to
libedataserver similar to [1], so Patrick could do something like:

#if EDS_CHECK_VERSION(2,22,0)
... free libical strings ...
#endif

Would that address your needs, Patrick?

Matthew Barnes


[1]
http://library.gnome.org/devel/glib/unstable/glib-Version-Information.html

___
Evolution-hackers mailing list
Evolution-hackers@gnome.org
http://mail.gnome.org/mailman/listinfo/evolution-hackers


Re: [Evolution-hackers] detecting new ical memory tracking

2008-04-08 Thread Patrick Ohly
On Di, 2008-04-08 at 18:29 -0400, Matthew Barnes wrote:
 More broadly, we should add some versioning macros and symbols to
 libedataserver similar to [1], so Patrick could do something like:
 
 #if EDS_CHECK_VERSION(2,22,0)
 ... free libical strings ...
 #endif
 
 Would that address your needs, Patrick?

It probably would work in practice, but I would have to make assumptions
about which versions contain this new feature. As Chris Lord pointed
out, eds-dbus might pick up the patch and then offer it under a
different version. As of last weekend, SyncEvolution can synchronize
calendars on Maemo with EDS-DBus, so I care about that. Making it work
with that were part of the reason for changing SyncEvolution.

Even if you add versioning information to 2.22.x, I still would have to
depend on dlsym() tricks to work with older releases.

-- 
Bye, Patrick Ohly
--  
[EMAIL PROTECTED]
http://www.estamos.de/

___
Evolution-hackers mailing list
Evolution-hackers@gnome.org
http://mail.gnome.org/mailman/listinfo/evolution-hackers