[m-dev.] MR_warning()

Warwick Harvey wharvey at cs.monash.edu.au
Thu Aug 13 11:28:45 AEST 1998


Peter Ross writes:
> Here is the code that I copied out of 'Advanced Unix Programming'.
> Warwick if you want to add it.

[code for a var args version of fatal_error() snipped]

Hey, thanks for that.  Here's a revised diff, incorporating the key points 
from that code while maintaining backwards compatibility with the old 
version.

Assuming the bootcheck is successful and the change seems to work, I expect 
to commit this change tomorrow (unless there are further comments).


Index: runtime/mercury_misc.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.c,v
retrieving revision 1.10
diff -u -r1.10 mercury_misc.c
--- mercury_misc.c	1998/07/29 08:55:59	1.10
+++ mercury_misc.c	1998/08/13 01:17:45
@@ -12,6 +12,7 @@
 #include	"mercury_misc.h"
 
 #include	<stdio.h>
+#include	<stdarg.h>
 
 /*--------------------------------------------------------------------*/
 
@@ -458,16 +459,45 @@
 	return p;
 }
 
+void
+MR_warning(const char *fmt, ...)
+{
+	va_list args;
+
+	fflush(stdout);		/* in case stdout and stderr are the same */
+
+	fprintf(stderr, "Mercury runtime: ");
+	va_start(args, fmt);
+	vfprintf(stderr, fmt, args);
+	va_end(args);
+	fprintf(stderr, "\n");
+
+	fflush(stderr);
+}
+
 /*
 ** XXX will need to modify this to kill other threads if MR_THREAD_SAFE
 ** (and cleanup resources, etc....)
 */
 
 void 
-fatal_error(const char *message) {
-	fprintf(stderr, "Mercury runtime: %s\n", message);
+fatal_error(const char *fmt, ...)
+{
+	va_list args;
+
+	fflush(stdout);		/* in case stdout and stderr are the same */
+
+	fprintf(stderr, "Mercury runtime: ");
+	va_start(args, fmt);
+	vfprintf(stderr, fmt, args);
+	va_end(args);
+	fprintf(stderr, "\n");
+
 	MR_trace_report(stderr);
-	exit(1);
+
+	fflush(NULL);		/* flushes all stdio output streams */
+
+	exit(EXIT_FAILURE);
 }
 
 	/* See header file for documentation on why we need this function */
Index: runtime/mercury_misc.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_misc.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_misc.h
--- mercury_misc.h	1998/07/29 08:56:01	1.8
+++ mercury_misc.h	1998/08/13 01:17:45
@@ -6,6 +6,7 @@
 
 /*
 ** mercury_misc.h -	debugging messages,
+**			MR_warning(),
 **			fatal_error(),
 **			checked_malloc(),
 **			MR_memcpy
@@ -59,7 +60,8 @@
 #else
 	#define NO_RETURN
 #endif
-extern	void	fatal_error(const char *msg) NO_RETURN;
+extern	void	MR_warning(const char *msg, ...);
+extern	void	fatal_error(const char *msg, ...) NO_RETURN;
 
 /*
 ** We use our own version of memcpy because gcc recognises calls to the





More information about the developers mailing list