This patch adds a caf_runtime_error function to the non-MPI implementation of Coarray Fortran. It is based on the MPI function of the same name in mpi.c.

Ok to commit?

ChangeLog:

2011-07-14  Daniel Carrera  <dcarr...@gmail.com>

        * caf/single.c:  Include stdarg.h header.
        (caf_runtime_error): New function based on the function in
        mpi.c with the same name.
        (_gfortran_caf_init): Use caf_runtime_error.
        * caf/mpi.c (caf_runtime_error): Add a note to keep in sync
        with the function in single.c.
--
I'm not overweight, I'm undertall.
Index: libgfortran/caf/single.c
===================================================================
--- libgfortran/caf/single.c	(revision 176230)
+++ libgfortran/caf/single.c	(working copy)
@@ -28,6 +28,7 @@ see the files COPYING3 and COPYING.RUNTI
 #include <stdio.h>  /* For fputs and fprintf.  */
 #include <stdlib.h> /* For exit and malloc.  */
 #include <string.h> /* For memcpy and memset.  */
+#include <stdarg.h> /* For variadic arguments.  */
 
 /* Define GFC_CAF_CHECK to enable run-time checking.  */
 /* #define GFC_CAF_CHECK  1  */
@@ -40,6 +41,21 @@ see the files COPYING3 and COPYING.RUNTI
 caf_static_t *caf_static_list = NULL;
 
 
+/* Keep in sync with mpi.c.  */
+static void
+caf_runtime_error (int error, const char *message, ...)
+{
+  va_list ap;
+  fprintf (stderr, "Fortran runtime error.");
+  va_start (ap, message);
+  fprintf (stderr, message, ap);
+  va_end (ap);
+  fprintf (stderr, "\n");
+
+  /* FIXME: Shutdown the Fortran RTL to flush the buffer.  PR 43849.  */
+  exit (error);
+}
+
 void
 _gfortran_caf_init (int *argc __attribute__ ((unused)),
 		    char ***argv __attribute__ ((unused)),
@@ -73,12 +89,12 @@ _gfortran_caf_register (ptrdiff_t size, 
 
   if (unlikely (local == NULL || token == NULL))
     {
+      const char msg[] = "Failed to allocate coarray";
       if (stat)
 	{
 	  *stat = 1;
 	  if (errmsg_len > 0)
 	    {
-	      const char msg[] = "Failed to allocate coarray";
 	      int len = ((int) sizeof (msg) > errmsg_len) ? errmsg_len
 							  : (int) sizeof (msg);
 	      memcpy (errmsg, msg, len);
@@ -88,10 +104,7 @@ _gfortran_caf_register (ptrdiff_t size, 
 	  return NULL;
 	}
       else
-	{
-	  fprintf (stderr, "ERROR: Failed to allocate coarray");
-	  exit (1);
-	}
+	  caf_runtime_error (1, msg);
     }
 
   if (stat)
Index: libgfortran/caf/mpi.c
===================================================================
--- libgfortran/caf/mpi.c	(revision 176230)
+++ libgfortran/caf/mpi.c	(working copy)
@@ -47,6 +47,7 @@ static int caf_is_finalized;
 caf_static_t *caf_static_list = NULL;
 
 
+/* Keep in sync with single.c.  */
 static void
 caf_runtime_error (int error, const char *message, ...)
 {
@@ -62,7 +63,7 @@ caf_runtime_error (int error, const char
   MPI_Abort (MPI_COMM_WORLD, error);
 
   /* Should be unreachable, but to make sure also call exit.  */
-  exit (2);
+  exit (error);
 }
 
 

Reply via email to