Re: glib compat w/dmalloc
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list redhat com
- Cc: Kennard White <kennard berkeley innomedia com>, gtk-bugs gtk org
- Subject: Re: glib compat w/dmalloc
- Date: 28 Feb 2000 15:38:53 -0500
Sebastian Wilhelmi <wilhelmi@ira.uka.de> writes:
> Hi everyone,
>
> As Kennard White pointed out, the current dmalloc version does not work with
> glib.
>
> We have three possibilities:
>
> * Fix it for third party software and glib itself. This is done in the
> attached patch. This includes defining a g_free_func, which always is a
> function doing g_free, whereas g_free might be a macro.
> * Fix it only for software using glib. This is my patch with some things
> removed.
> * Remove dmalloc support completely. This might also be an option.
My personal preference would be to completely remove DMALLOC support from
GLib. I don't think people use it much, and also feel that if you
want debugging malloc support, you should actually replace the libc's
malloc/free (using libc functionality as provided with GNU libc, with
a LD_PRELOAD, or with a library simply linked in before libc.)
But failing that, I think that g_free() must always be a function, so
you simply want to remove the:
#define g_free(mem) FREE (mem)
in the DMALLOC case and replace simply always have a g_free() function
as in the non-DMALLOC case. Making every piece of software that
uses g_free for a GDestroyNotify, etc, broken, is not an option
in my opinion.
Regards,
Owen
> I'll commit my changes next week unless someone objects.
>
> Bye,
> Sebastian
> --
> Sebastian Wilhelmi | här ovanför alla molnen
> mailto:wilhelmi@ira.uka.de | är himmlen så förunderligt blå
> http://goethe.ira.uka.de/~wilhelmi |Index: glib.h
> ===================================================================
> RCS file: /cvs/gnome/glib/glib.h,v
> retrieving revision 1.116.2.8
> diff -u -b -B -u -r1.116.2.8 glib.h
> --- glib.h 2000/02/17 11:29:17 1.116.2.8
> +++ glib.h 2000/02/28 17:10:46
> @@ -307,18 +307,12 @@
> * in order to avoid compiler warnings. (Makes the code neater).
> */
>
> -#ifdef __DMALLOC_H__
> -# define g_new(type, count) (ALLOC (type, count))
> -# define g_new0(type, count) (CALLOC (type, count))
> -# define g_renew(type, mem, count) (REALLOC (mem, type, count))
> -#else /* __DMALLOC_H__ */
> -# define g_new(type, count) \
> +#define g_new(type, count) \
> ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
> -# define g_new0(type, count) \
> +#define g_new0(type, count) \
> ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
> -# define g_renew(type, mem, count) \
> +#define g_renew(type, mem, count) \
> ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
> -#endif /* __DMALLOC_H__ */
>
> #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
> g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
> @@ -1351,11 +1345,13 @@
> */
> #ifdef USE_DMALLOC
>
> -#define g_malloc(size) ((gpointer) MALLOC (size))
> -#define g_malloc0(size) ((gpointer) CALLOC (char, size))
> -#define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
> -#define g_free(mem) FREE (mem)
> +#define g_malloc(size) ((gpointer) malloc (size))
> +#define g_malloc0(size) ((gpointer) calloc (size, sizeof (char)))
> +#define g_realloc(mem,size) ((gpointer) realloc (mem, size))
> +#define g_free(mem) (free (mem))
>
> +void g_free_func (gpointer mem);
> +
> #else /* !USE_DMALLOC */
>
> gpointer g_malloc (gulong size);
> @@ -1363,6 +1359,7 @@
> gpointer g_realloc (gpointer mem,
> gulong size);
> void g_free (gpointer mem);
> +#define g_free_func g_free
>
> #endif /* !USE_DMALLOC */
>
> Index: gmain.c
> ===================================================================
> RCS file: /cvs/gnome/glib/gmain.c,v
> retrieving revision 1.26.2.8
> diff -u -b -B -u -r1.26.2.8 gmain.c
> --- gmain.c 2000/02/03 00:53:22 1.26.2.8
> +++ gmain.c 2000/02/28 17:10:46
> @@ -152,8 +153,9 @@
> g_timeout_prepare,
> g_timeout_check,
> g_timeout_dispatch,
> - g_free,
> + g_free_func
> };
> +
>
> static GSourceFuncs idle_funcs =
> {
> Index: gmem.c
> ===================================================================
> RCS file: /cvs/gnome/glib/gmem.c,v
> retrieving revision 1.13.2.5
> diff -u -b -B -u -r1.13.2.5 gmem.c
> --- gmem.c 1999/09/17 09:03:51 1.13.2.5
> +++ gmem.c 2000/02/28 17:10:46
> @@ -1002,3 +1002,13 @@
> allocating_for_mem_chunk = g_private_new(NULL);
> #endif
> }
> +
> +/* Here we really want to define g_free_func, not g_free, so we have
> + * to undefine g_free_func first */
> +#undef g_free_func
> +void
> +g_free_func (gpointer mem)
> +{
> + g_free (mem);
> +}
> +
> Index: gstrfuncs.c
> ===================================================================
> RCS file: /cvs/gnome/glib/gstrfuncs.c,v
> retrieving revision 1.26.2.6
> diff -u -b -B -u -r1.26.2.6 gstrfuncs.c
> --- gstrfuncs.c 2000/01/09 10:59:09 1.26.2.6
> +++ gstrfuncs.c 2000/02/28 17:10:46
> @@ -656,7 +656,7 @@
> if (!msg)
> {
> msg = g_new (gchar, 64);
> - g_static_private_set (&msg_private, msg, g_free);
> + g_static_private_set (&msg_private, msg, g_free_func);
> }
>
> sprintf (msg, "unknown error (%d)", errnum);
> @@ -783,7 +783,7 @@
> if (!msg)
> {
> msg = g_new (gchar, 64);
> - g_static_private_set (&msg_private, msg, g_free);
> + g_static_private_set (&msg_private, msg, g_free_func);
> }
>
> sprintf (msg, "unknown signal (%d)", signum);
> Index: gmodule/gmodule.c
> ===================================================================
> RCS file: /cvs/gnome/glib/gmodule/gmodule.c,v
> retrieving revision 1.20.2.1
> diff -u -b -B -u -r1.20.2.1 gmodule.c
> --- gmodule/gmodule.c 1999/04/24 09:45:51 1.20.2.1
> +++ gmodule/gmodule.c 2000/02/28 17:10:46
> @@ -121,7 +121,7 @@
> static inline void
> g_module_set_error (const gchar *error)
> {
> - g_static_private_set (&module_error_private, g_strdup (error), g_free);
> + g_static_private_set (&module_error_private, g_strdup (error), g_free_func);
> errno = 0;
> }
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]