PATCH 21.5
I've had this patch sitting around for AGES. It's about time to show
it to somebody.
This patch adds rudimentary support for valgrind on-the-fly memory
leak checks to XEmacs. When I first wrote it, I couldn't use it
successfully, because valgrind always reported a segfault and killed
the XEmacs process before I could get around to invoking either of the
functions added by this patch. I WAS using the magic valgrind option
that is supposed to make it ignore the deliberate segfaults caused by
the garbage collector. I'll try again now and see if the situation
has improved.
Much deeper integration with valgrind is possible. First I have to
get a machine where a valgrinded XEmacs runs faster than a snail,
however.
diff -r c064d7197712 ChangeLog
--- a/ChangeLog Sat Apr 18 03:24:48 2009 +0900
+++ b/ChangeLog Fri May 15 11:54:50 2009 -0600
@@ -1,3 +1,7 @@
+2009-05-15 Jerry James <james(a)xemacs.org>
+
+ * configure.ac: Add --with-valgrind option.
+
2009-02-11 Jerry James <james(a)xemacs.org>
* config.guess:
diff -r c064d7197712 configure.ac
--- a/configure.ac Sat Apr 18 03:24:48 2009 +0900
+++ b/configure.ac Fri May 15 11:54:50 2009 -0600
@@ -1024,6 +1024,9 @@
XE_MERGED_ARG([purify],
AS_HELP_STRING([--with-purify],[Support memory debugging using Purify.]),
[], [])
+XE_MERGED_ARG([valgrind],
+ AS_HELP_STRING([--with-valgrind],[Support memory debugging using Valgrind.]),
+ [], [])
dnl -------------------------------------------------------------------------
dnl Final command line argument checks.
@@ -5918,6 +5921,7 @@
test "$enable_quick_build" = "yes" && AC_DEFINE(QUICK_BUILD)
test "$with_purify" = "yes" && AC_DEFINE(PURIFY)
test "$with_quantify" = "yes" && AC_DEFINE(QUANTIFY)
+test "$with_valgrind" = "yes" &&
AC_DEFINE(USE_VALGRIND)
test "$with_pop" = "yes" &&
AC_DEFINE(MAIL_USE_POP)
test "$with_kerberos" = "yes" && AC_DEFINE(KERBEROS)
test "$with_hesiod" = "yes" && AC_DEFINE(HESIOD)
@@ -6236,6 +6240,7 @@
echo " WARNING: Error checking is on by default for XEmacs beta releases."
echo " WARNING: ---------------------------------------------------------"
fi
+test "$with_valgrind" = yes && echo " Compiling in support for
memory debugging with Valgrind."
echo ""
) | tee -a Installation
dnl echo "The above configure report is appended to \"Installation\"
file."
diff -r c064d7197712 src/ChangeLog
--- a/src/ChangeLog Sat Apr 18 03:24:48 2009 +0900
+++ b/src/ChangeLog Fri May 15 11:54:50 2009 -0600
@@ -1,3 +1,10 @@
+2009-05-15 Jerry James <james(a)xemacs.org>
+
+ * alloc.c (Fvalgrind_leak_check): New function.
+ (Fvalgrind_quick_leak_check): Ditto.
+ * config.h.in (USE_VALGRIND): Defined by configure if
+ --with-valgrind is supplied.
+
2009-03-08 Ville Skyttä <scop(a)xemacs.org>
* glyphs-gtk.c (init_image_instance_from_gdk_pixmap): Apply the
diff -r c064d7197712 src/alloc.c
--- a/src/alloc.c Sat Apr 18 03:24:48 2009 +0900
+++ b/src/alloc.c Fri May 15 11:54:50 2009 -0600
@@ -71,6 +71,9 @@
#ifdef DOUG_LEA_MALLOC
#include <malloc.h>
#endif
+#ifdef USE_VALGRIND
+#include <valgrind/memcheck.h>
+#endif
EXFUN (Fgarbage_collect, 0);
@@ -4690,6 +4693,29 @@
}
#endif /* ALLOC_TYPE_STATS */
+#ifdef USE_VALGRIND
+DEFUN ("valgrind-leak-check", Fvalgrind_leak_check, 0, 0, 0, /*
+Ask valgrind to perform a memory leak check.
+The results of the leak check are sent to stderr.
+*/
+ ())
+{
+ VALGRIND_DO_LEAK_CHECK;
+ return Qnil;
+}
+
+DEFUN ("valgrind-quick-leak-check", Fvalgrind_quick_leak_check, 0, 0, 0, /*
+Ask valgrind to perform a quick memory leak check.
+This just prints a summary of leaked memory, rather than all the details.
+The results of the leak check are sent to stderr.
+*/
+ ())
+{
+ VALGRIND_DO_QUICK_LEAK_CHECK;
+ return Qnil;
+}
+#endif /* USE_VALGRIND */
+
void
recompute_funcall_allocation_flag (void)
{
@@ -5070,6 +5096,10 @@
#endif
DEFSUBR (Ftotal_memory_usage);
DEFSUBR (Fconsing_since_gc);
+#ifdef USE_VALGRIND
+ DEFSUBR (Fvalgrind_leak_check);
+ DEFSUBR (Fvalgrind_quick_leak_check);
+#endif
}
void
diff -r c064d7197712 src/config.h.in
--- a/src/config.h.in Sat Apr 18 03:24:48 2009 +0900
+++ b/src/config.h.in Fri May 15 11:54:50 2009 -0600
@@ -648,6 +648,10 @@
It is only intended for use by the developers. */
#undef PURIFY
+/* Define USE_VALGRIND to compile valgrind hints into the code.
+ It is only intended for use by the developers. */
+#undef USE_VALGRIND
+
/* Define EXTERNAL_WIDGET to compile support for using the editor as a
widget within another program. */
#undef EXTERNAL_WIDGET
--
Jerry James
http://www.jamezone.org/
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches