changeset 3988:1227374e7199

[xemacs-hg @ 2007-05-26 18:28:19 by aidan] Make double-free checks 64-bit safe, from Sebastian Freundt.
author aidan
date Sat, 26 May 2007 18:28:23 +0000
parents 445918763299
children 53260b0cd16b
files src/ChangeLog src/free-hook.c src/lisp.h
diffstat 3 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri May 25 21:51:11 2007 +0000
+++ b/src/ChangeLog	Sat May 26 18:28:23 2007 +0000
@@ -1,3 +1,12 @@
+2007-05-24  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* free-hook.c (check_free):
+	* lisp.h:
+	* lisp.h (xfree):
+	Inspired by some of Sebastian Freundt's SXEmacs work, use a 64-bit
+	constant on 64-bit platforms when making sure pointers haven't
+	been freed twice. 
+
 2007-05-22  Ville Skyttä  <scop@xemacs.org>
 
 	* Makefile.in.in ($(LISP)/finder-inf.el): Set lisp-directory
--- a/src/free-hook.c	Fri May 25 21:51:11 2007 +0000
+++ b/src/free-hook.c	Sat May 26 18:28:23 2007 +0000
@@ -179,6 +179,8 @@
 	    / sizeof (long);
 	  unsigned long i;
 
+          /* Not using the DEADBEEF_CONSTANT #define, since we don't know
+           * that allocation sizes will be multiples of eight. */
 	  for (i = 0; i < long_length; i++)
 	    ((unsigned long *) ptr)[i] = 0xdeadbeef;
 	}
--- a/src/lisp.h	Fri May 25 21:51:11 2007 +0000
+++ b/src/lisp.h	Sat May 26 18:28:23 2007 +0000
@@ -250,6 +250,14 @@
 typedef unsigned long uintptr_t;
 #endif
 
+#if SIZEOF_VOID_P == 8
+#define DEADBEEF_CONSTANT 0xCAFEBABEDEADBEEF
+#elif SIZEOF_VOID_P == 4
+#define DEADBEEF_CONSTANT 0xDEADBEEF
+#else
+#error "What size are your pointers, really?"
+#endif /* SIZEOF_VOID_P == 8 */
+
 /* ---------------------- definition of EMACS_INT --------------------- */
 
 /* EMACS_INT is the underlying integral type into which a Lisp_Object must fit.
@@ -1084,7 +1092,7 @@
 #define xfree(lvalue, type) do						\
 {									\
   xfree_1 (lvalue);							\
-  VOIDP_CAST (lvalue) = (void *) 0xDEADBEEF;				\
+  VOIDP_CAST (lvalue) = (void *) DEADBEEF_CONSTANT;                     \
 } while (0)
 #else
 #define xfree(lvalue,type) xfree_1 (lvalue)