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



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
--  
Patrick Ohly gmx de
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 x    result of one of the functions above
 * @return string which has to be freed by caller, may be NULL if x was NULL
 */
extern char *ical_strdup(const char *x);
#else
# define ical_strdup(_x) (_x)
#endif

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* ICALSTRDUP_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]