[m-rev.] diff: export MR_checked_{fopen,fclose,atexit}

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Dec 27 18:06:26 AEDT 2001


Estimated hours taken: 1
Branches: main

runtime/mercury_runtime_util.[ch]:
	New module for utility functions. Contains the checked versions of
	fopen, fclose, atexit which used to be static in mercury_prof.c,
	and the backup version of strerror which used to be in
	mercury_strerror.c.

runtime/mercury_strerror.[ch]:
	Deleted this now obsolete module.

runtime/mercury_prof.c:

runtime/Mmakefile:
	Mention the new module and delete references to the deleted module.

runtime/mercury_deep_profiling.c:
runtime/mercury_trace_base.c:
	Add #includes of the new module.

Zoltan.

cvs diff: Diffing .
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.77
diff -u -b -r1.77 Mmakefile
--- Mmakefile	2001/08/14 10:19:01	1.77
+++ Mmakefile	2001/12/22 20:29:35
@@ -73,12 +73,12 @@
 			mercury_reg_workarounds.h	\
 			mercury_regorder.h	\
 			mercury_regs.h		\
+			mercury_runtime_util.h	\
 			mercury_signal.h	\
 			mercury_std.h		\
 			mercury_stack_layout.h	\
 			mercury_stack_trace.h	\
 			mercury_stacks.h	\
-			mercury_strerror.h	\
 			mercury_string.h	\
 			mercury_tabling.h	\
 			mercury_tabling_macros.h	\
@@ -159,10 +159,10 @@
 			mercury_prof_time.c	\
 			mercury_reg_workarounds.c	\
 			mercury_regs.c		\
+			mercury_runtime_util.c	\
 			mercury_signal.c	\
 			mercury_stack_trace.c	\
 			mercury_stacks.c	\
-			mercury_strerror.c	\
 			mercury_string.c	\
 			mercury_tabling.c	\
 			mercury_thread.c	\
Index: mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.6
diff -u -b -r1.6 mercury_deep_profiling.c
--- mercury_deep_profiling.c	2001/08/03 04:06:27	1.6
+++ mercury_deep_profiling.c	2001/12/22 20:29:35
@@ -15,6 +15,7 @@
 #include "mercury_stack_layout.h"
 #include "mercury_timing.h"
 #include "mercury_prof_time.h"
+#include "mercury_runtime_util.h"	/* for strerror() on some systems */
 #include "mercury_deep_profiling.h"
 
 #ifdef MR_DEEP_PROFILING
Index: mercury_prof.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.c,v
retrieving revision 1.16
diff -u -b -r1.16 mercury_prof.c
--- mercury_prof.c	2001/05/31 06:00:14	1.16
+++ mercury_prof.c	2001/12/22 20:29:35
@@ -28,6 +28,7 @@
 #include	"mercury_signal.h"
 #include        "mercury_std.h"
 #include	"mercury_timing.h"
+#include	"mercury_runtime_util.h"
 
 #include	<signal.h>		/* for SIGINT */
 
@@ -122,54 +123,6 @@
 
 /* ======================================================================== */
 
-/* utility routines for opening and closing files */
-
-#if defined(MR_MPROF_PROFILE_TIME) || defined(MR_MPROF_PROFILE_CALLS) \
-	|| defined(MR_MPROF_PROFILE_MEMORY)
-
-static FILE *
-MR_checked_fopen(const char *filename, const char *message, const char *mode)
-{
-	FILE *file;
-
-	errno = 0;
-	file = fopen(filename, mode);
-	if (!file) {
-		fprintf(stderr, "Mercury runtime: couldn't %s file `%s': %s\n",
-				message, filename, strerror(errno));
-		exit(1);
-	}
-	return file;
-}
-
-static void
-MR_checked_fclose(FILE *file, const char *filename)
-{
-	errno = 0;
-	if (fclose(file) != 0) {
-		fprintf(stderr,
-			"Mercury runtime: error closing file `%s': %s\n",
-			filename, strerror(errno));
-		exit(1);
-	}
-}
-
-static void
-MR_checked_atexit(void (*func)(void))
-{
-	errno = 0;
-	if (atexit(func) != 0) {
-		fprintf(stderr,
-			"Mercury runtime: error in call to atexit: %s\n",
-			strerror(errno));
-		exit(1);
-	}
-}
-
-#endif /* MR_MPROF_PROFILE_TIME or MR_MPROF_PROFILE_CALLS or MR_MPROF_PROFILE_MEMORY */
-
-/* ======================================================================== */
-
 #ifdef MR_MPROF_PROFILE_CALLS
 
 /*
@@ -476,7 +429,7 @@
 	** exit() will call MR_prof_finish(), which we registered
 	** with atexit().
 	*/
-  exit(1);
+	exit(EXIT_FAILURE);
 }
 #endif
 
Index: mercury_runtime_util.c
===================================================================
RCS file: mercury_runtime_util.c
diff -N mercury_runtime_util.c
--- /dev/null	Fri Dec  1 02:25:58 2000
+++ mercury_runtime_util.c	Thu Dec 27 18:00:33 2001
@@ -0,0 +1,82 @@
+/*
+** Copyright (C) 1999 The University of Melbourne.
+** This file may only be copied under the terms of the GNU Library General
+** Public License - see the file COPYING.LIB in the Mercury distribution.
+*/
+
+/*
+** This module contains utility functions for the rest of the Mercury runtime.
+**
+** Author: petdr
+*/
+
+#include        "mercury_imp.h"
+#include	"mercury_runtime_util.h"
+
+#include	<stdio.h>
+#include	<unistd.h>
+#include	<errno.h>
+
+#ifndef HAVE_STRERROR
+
+/*
+** Apparently SunOS 4.1.3 doesn't have strerror()
+**	(!%^&!^% non-ANSI systems, grumble...)
+*/
+
+extern	int	sys_nerr;
+extern	char	*sys_errlist[];
+
+char *
+strerror(int errnum)
+{
+	if (errnum >= 0 && errnum < sys_nerr && sys_errlist[errnum] != NULL) {
+		return sys_errlist[errnum];
+	} else {
+		static	char	buf[30];
+		sprintf(buf, "Error %d", errnum);
+		return buf;
+	}
+}
+
+#endif	/* HAVE_STRERROR */
+
+FILE *
+MR_checked_fopen(const char *filename, const char *message, const char *mode)
+{
+	FILE *file;
+
+	errno = 0;
+	file = fopen(filename, mode);
+	if (file == NULL) {
+		fprintf(stderr,
+			"Mercury runtime: couldn't %s file `%s': %s\n",
+			message, filename, strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+	return file;
+}
+
+void
+MR_checked_fclose(FILE *file, const char *filename)
+{
+	errno = 0;
+	if (fclose(file) != 0) {
+		fprintf(stderr,
+			"Mercury runtime: error closing file `%s': %s\n",
+			filename, strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+}
+
+void
+MR_checked_atexit(void (*func)(void))
+{
+	errno = 0;
+	if (atexit(func) != 0) {
+		fprintf(stderr,
+			"Mercury runtime: error in call to atexit: %s\n",
+			strerror(errno));
+		exit(EXIT_FAILURE);
+	}
+}
Index: mercury_runtime_util.h
===================================================================
RCS file: mercury_runtime_util.h
diff -N mercury_runtime_util.h
--- /dev/null	Fri Dec  1 02:25:58 2000
+++ mercury_runtime_util.h	Sun Dec 23 07:29:35 2001
@@ -0,0 +1,21 @@
+/*
+** Copyright (C) 1999 The University of Melbourne.
+** This file may only be copied under the terms of the GNU Library General
+** Public License - see the file COPYING.LIB in the Mercury distribution.
+*/
+
+#ifndef	MERCURY_RUNTIME_UTIL_H
+#define	MERCURY_RUNTIME_UTIL_H
+
+#include	<stdio.h>
+
+#ifndef HAVE_STRERROR
+extern	char	*strerror(int errnum);
+#endif
+
+extern	FILE	*MR_checked_fopen(const char *filename, const char *message,
+			const char *mode);
+extern	void	MR_checked_fclose(FILE *file, const char *filename);
+extern	void	MR_checked_atexit(void (*func)(void));
+
+#endif	/* MERCURY_RUNTIME_UTIL_H */
Index: mercury_strerror.c
===================================================================
RCS file: mercury_strerror.c
diff -N mercury_strerror.c
--- /tmp/cvstsWhFI	Thu Dec 27 18:05:44 2001
+++ /dev/null	Fri Dec  1 02:25:58 2000
@@ -1,33 +0,0 @@
-/*
-** Copyright (C) 2001 The University of Melbourne.
-** This file may only be copied under the terms of the GNU Library General
-** Public License - see the file COPYING.LIB in the Mercury distribution.
-*/
-
-/*
-** Apparently SunOS 4.1.3 doesn't have strerror()
-**	(!%^&!^% non-ANSI systems, grumble...)
-*/
-
-#include <stdio.h>			/* for NULL */
-#include "mercury_conf.h"		/* for (possibly) HAVE_STRERROR */
-#include "mercury_strerror.h"
-
-#ifndef HAVE_STRERROR
-
-extern	int	sys_nerr;
-extern	char	*sys_errlist[];
-
-char *
-strerror(int errnum)
-{
-	if (errnum >= 0 && errnum < sys_nerr && sys_errlist[errnum] != NULL) {
-		return sys_errlist[errnum];
-	} else {
-		static char buf[30];
-		sprintf(buf, "Error %d", errnum);
-		return buf;
-	}
-}
-
-#endif
Index: mercury_strerror.h
===================================================================
RCS file: mercury_strerror.h
diff -N mercury_strerror.h
--- /tmp/cvsLDOrCZ	Thu Dec 27 18:05:44 2001
+++ /dev/null	Fri Dec  1 02:25:58 2000
@@ -1,21 +0,0 @@
-/*
-** Copyright (C) 2001 The University of Melbourne.
-** This file may only be copied under the terms of the GNU Library General
-** Public License - see the file COPYING.LIB in the Mercury distribution.
-*/
-
-/*
-** Apparently SunOS 4.1.3 doesn't have strerror()
-**	(!%^&!^% non-ANSI systems, grumble...)
-*/
-
-#ifndef	MERCURY_STRERROR_H
-#define	MERCURY_STRERROR_H
-
-#ifndef HAVE_STRERROR
-
-extern	char	*strerror(int errnum);
-
-#endif	/* HAVE_STRERROR */
-
-#endif	/* MERCURY_STRERROR_H */
Index: mercury_trace_base.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.37
diff -u -b -r1.37 mercury_trace_base.c
--- mercury_trace_base.c	2001/12/19 05:00:54	1.37
+++ mercury_trace_base.c	2001/12/22 20:29:35
@@ -22,6 +22,7 @@
 #include "mercury_engine.h"
 #include "mercury_wrapper.h"
 #include "mercury_misc.h"
+#include "mercury_runtime_util.h"	/* for strerror() on some systems */
 #include "mercury_signal.h"	/* for MR_setup_signal() */
 #include <signal.h>		/* for SIGINT */
 #include <stdio.h>
cvs diff: Diffing GETOPT
cvs diff: Diffing machdeps
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list