[m-dev.] diff: assert() becomes MR_assert()

Bert THOMPSON aet at cs.mu.oz.au
Tue Jun 3 18:22:38 AEST 1997


People,

Any C assertions are turned off in end-user code that #includes the 
standard Mercury headers. This is LessThanOptimal(TM).

Mercury fouls the namespace quite a bit besides, a problem which is 
on the TODO list.

Fix below.

============================================================

Estimated hours taken: 0.2

runtime/context.mod:
runtime/debug.h:
runtime/dlist.c:
runtime/imp.h:
runtime/regs.h:
runtime/std.h:
runtime/wrapper.mod:
	Replaced all occurences of assert() with the new macro
	MR_assert(), which does nothing if SPEED is defined.

	Previously, we defined NDEBUG if SPEED was defined, which
	had the unfortunate consequence of turning off assertions
	in the code of Mercury users that includes the standard
	Mercury headers. Users' assertions no longer get turned off
	inadvertently.

CVS: ----------------------------------------------------------------------
CVS: Enter Log.  Lines beginning with `CVS: ' are removed automatically
CVS: 
CVS: Committing in .
CVS: 
CVS: Modified Files:
CVS: 	context.mod debug.h dlist.c imp.h regs.h std.h wrapper.mod 
CVS: ----------------------------------------------------------------------

Index: context.mod
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/context.mod,v
retrieving revision 1.6
diff -u -r1.6 context.mod
--- 1.6	1997/04/15 02:14:20
+++ context.mod	1997/06/03 08:04:02
@@ -8,7 +8,6 @@
 
 #include "imp.h"
 
-#include <assert.h>
 #include <unistd.h>		/* for getpid() and fork() */
 #ifdef PARALLEL
 #include <signal.h>
@@ -124,7 +123,7 @@
 
 	get_lock(free_context_list_lock);
 
-	assert(free_context_list_ptr != NULL);
+	MR_assert(free_context_list_ptr != NULL);
 	if (*free_context_list_ptr == NULL) {
 		fatal_error("no free contexts");
 	} else {
@@ -169,7 +168,7 @@
 delete_context(Context *c)
 {
 	get_lock(free_context_list_lock);
-	assert(free_context_list_ptr != NULL);
+	MR_assert(free_context_list_ptr != NULL);
 	c->next = *free_context_list_ptr;
 	*free_context_list_ptr = c;
 	release_lock(free_context_list_lock);
@@ -319,7 +318,7 @@
 
 	get_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
 	if (--(sync_term[SYNC_TERM_COUNTER]) == 0) {
-		assert(sync_term[SYNC_TERM_PARENT] != NULL);
+		MR_assert(sync_term[SYNC_TERM_PARENT] != NULL);
 		release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
 		ctxt = (Context *) sync_term[SYNC_TERM_PARENT];
 		delete_context(this_context);
@@ -349,7 +348,7 @@
 
 	get_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
 	if (--(sync_term[SYNC_TERM_COUNTER]) == 0) {
-		assert(sync_term[SYNC_TERM_PARENT] == NULL);
+		MR_assert(sync_term[SYNC_TERM_PARENT] == NULL);
 		release_lock((SpinLock *)&sync_term[SYNC_TERM_LOCK]);
 		GOTO(do_join_and_continue_where_to);
 	} else {
Index: debug.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/debug.h,v
retrieving revision 1.9
diff -u -r1.9 debug.h
--- 1.9	1997/02/12 02:15:12
+++ debug.h	1997/06/03 08:05:20
@@ -25,7 +25,7 @@
 #else
 
 #define	debuggoto(label) \
-	(assert(label), \
+	(MR_assert(label), \
 	IF (gotodebug, (save_transient_registers(), goto_msg(label))))
 
 #define	debugsreg() \
Index: dlist.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/dlist.c,v
retrieving revision 1.5
diff -u -r1.5 dlist.c
--- 1.5	1997/02/12 02:15:16
+++ dlist.c	1997/06/03 08:04:38
@@ -9,7 +9,6 @@
 */
 
 #include	<stdio.h>
-#include	<assert.h>
 #include	"std.h"
 #include	"dlist.h"
 
@@ -39,7 +38,7 @@
 {
 	reg	List	*list;
 
-	assert(data != NULL);
+	MR_assert(data != NULL);
 	list = makelist0();
 	addhead(list, data);
 	return list;
Index: imp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/imp.h,v
retrieving revision 1.107
diff -u -r1.107 imp.h
--- 1.107	1997/02/12 02:15:36
+++ imp.h	1997/06/03 07:59:35
@@ -19,15 +19,8 @@
 #ifndef IMP_H
 #define IMP_H
 
-#ifdef SPEED
-/* turn off `assert()'s */
-#define NDEBUG
-#endif
-
 #include	"regs.h"	/* must come before system headers */
 
-#include	<assert.h>
-
 #include	"conf.h"
 
 #include	"std.h"
Index: regs.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/regs.h,v
retrieving revision 1.28
diff -u -r1.28 regs.h
--- 1.28	1997/02/12 07:41:09
+++ regs.h	1997/06/03 08:05:26
@@ -36,7 +36,7 @@
 ** mr0, mr1, etc. as the physical machine registers, and defines an
 ** array fake_regs[n] of pseudo registers.
 **
-** The next level defines macroes mr0 through mr36 and also mr(n) for
+** The next level defines macros mr0 through mr36 and also mr(n) for
 ** n>36.  The lower the number,
 ** the greater the probability that the storage referred to will be
 ** a real machine register, and not a simulated one. The number of
@@ -81,7 +81,7 @@
 
 /* The machdeps header defines mr0 .. mr36; now define mr(n) for n > 36 */
 
-#define mr(n) LVALUE_SEQ(assert((n) >= MAX_REAL_REG + NUM_SPECIAL_REG && \
+#define mr(n) LVALUE_SEQ(MR_assert((n) >= MAX_REAL_REG + NUM_SPECIAL_REG && \
 				(n) < MAX_FAKE_REG),\
 		fake_reg[n])
 
Index: std.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/std.h,v
retrieving revision 1.16
diff -u -r1.16 std.h
--- 1.16	1997/05/16 08:27:32
+++ std.h	1997/06/03 08:05:44
@@ -13,6 +13,7 @@
 #define STD_H
 
 #include <stdlib.h>	/* for size_t */
+#include <assert.h>	/* for assert() */
 
 #ifndef	reg
 #define	reg		register
@@ -49,6 +50,16 @@
 #define	FALSE		0
 #endif
 
+/*
+** turn assertions off for speed
+*/
+#ifdef SPEED
+#define MR_assert(ASSERTION)	((void)0)
+#else
+#define	MR_assert(ASSERTION)	assert(ASSERTION)
+#endif
+
+
 /* XXX these should go in memory.h or heap.h */
 extern	void	*newmem(size_t);
 extern	void	*resizemem(void *, size_t);
Index: wrapper.mod
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/wrapper.mod,v
retrieving revision 1.73
diff -u -r1.73 wrapper.mod
--- 1.73	1997/02/12 02:16:50
+++ wrapper.mod	1997/06/03 08:05:10
@@ -709,7 +709,7 @@
 		int i;
 
 		for (i = 0; i < SAFETY_BUFFER_SIZE; i++)
-			assert(safety_buffer[i] == MAGIC_MARKER_2);
+			MR_assert(safety_buffer[i] == MAGIC_MARKER_2);
 	}
 #endif
 



More information about the developers mailing list