Re: glib compat w/dmalloc



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.

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]