for review: mkpragmaframe() bug fix

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Dec 9 22:48:43 AEDT 1998


Hi,

Could someone please review this one for me?

--------------------

Estimated hours taken: 0.25

runtime/mercury_stacks.h:
	Fix a bug in makepragmaframe() that caused it to allocate
	too much memory: convert the struct size from bytes to words
	before adding it to MR_maxfr.

This is `diff -u -b' (ignoring whitespace changes):

--- ../mercury-compiler-0.8/runtime/mercury_stacks.h	Thu Nov 12 00:30:47 1998
+++ runtime/mercury_stacks.h	Tue Dec  8 18:11:39 1998
@@ -134,6 +134,9 @@
 				nondstack_overflow_check();		\
 			} while (0)
 
+/* convert a size in bytes to a size in words, rounding up if necessary */
+#define MR_bytes_to_words(x) (((x) + sizeof(Word) - 1) / sizeof(Word))
+
 /* just like mkframe, but also reserves space for a struct     */
 /* with the given tag at the bottom of the nondet stack frame  */
 #define	mkpragmaframe(prednm, numslots, structname, redoip)		\
@@ -143,8 +146,8 @@
 									\
 				prevfr = MR_maxfr;			\
 				succfr = MR_curfr;			\
-				MR_maxfr += (MR_NONDET_FIXED_SIZE + numslots \
-					+ sizeof(struct structname));	\
+		MR_maxfr += MR_NONDET_FIXED_SIZE + numslots + 		\
+			MR_bytes_to_words(sizeof(struct structname));	\
 				MR_curfr = MR_maxfr;			\
 				MR_redoip_slot(MR_curfr) = redoip;	\
 				MR_prevfr_slot(MR_curfr) = prevfr;	\

This is `diff -u' (showing whitespace changes):

--- ../mercury-compiler-0.8/runtime/mercury_stacks.h	Thu Nov 12 00:30:47 1998
+++ runtime/mercury_stacks.h	Tue Dec  8 18:11:39 1998
@@ -134,27 +134,30 @@
 				nondstack_overflow_check();		\
 			} while (0)
 
+/* convert a size in bytes to a size in words, rounding up if necessary */
+#define MR_bytes_to_words(x) (((x) + sizeof(Word) - 1) / sizeof(Word))
+
 /* just like mkframe, but also reserves space for a struct     */
 /* with the given tag at the bottom of the nondet stack frame  */
 #define	mkpragmaframe(prednm, numslots, structname, redoip)		\
-			do {						\
-				reg	Word	*prevfr;		\
-				reg	Word	*succfr;		\
+	do {								\
+		reg	Word	*prevfr;				\
+		reg	Word	*succfr;				\
 									\
-				prevfr = MR_maxfr;			\
-				succfr = MR_curfr;			\
-				MR_maxfr += (MR_NONDET_FIXED_SIZE + numslots \
-					+ sizeof(struct structname));	\
-				MR_curfr = MR_maxfr;			\
-				MR_redoip_slot(MR_curfr) = redoip;	\
-				MR_prevfr_slot(MR_curfr) = prevfr;	\
-				MR_succip_slot(MR_curfr) = MR_succip;	\
-				MR_succfr_slot(MR_curfr) = succfr;	\
-				MR_redofr_slot(MR_curfr) = MR_curfr;	\
-				mkframe_save_prednm(prednm);		\
-				debugmkframe();				\
-				nondstack_overflow_check();		\
-			} while (0)
+		prevfr = MR_maxfr;					\
+		succfr = MR_curfr;					\
+		MR_maxfr += MR_NONDET_FIXED_SIZE + numslots + 		\
+			MR_bytes_to_words(sizeof(struct structname));	\
+		MR_curfr = MR_maxfr;					\
+		MR_redoip_slot(MR_curfr) = redoip;			\
+		MR_prevfr_slot(MR_curfr) = prevfr;			\
+		MR_succip_slot(MR_curfr) = MR_succip;			\
+		MR_succfr_slot(MR_curfr) = succfr;			\
+		MR_redofr_slot(MR_curfr) = MR_curfr;			\
+		mkframe_save_prednm(prednm);				\
+		debugmkframe();						\
+		nondstack_overflow_check();				\
+	} while (0)
 
 #define	mktempframe(redoip)						\
 			do {						\

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list