This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR30947 - resolving ALARM


On Thursday 08 March 2007 01:52:27 Brooks Moses wrote:

> Right now, for 4.2, I think the right answer is to remove the cast on
> STATUS, document that it must be an INTEGER(4), and add code to the
> appropriate gfc_check function to test for that.  Anything else strikes
> me as too risky at this late date.

As suggested by Brooks, attached patch adds a check to ensure that the status 
argument of ALARM is of default integer kind (not INTEGER(4), as this is more 
consistent with other implementations). Accordingly, the conversion of status 
argument in iresolve.c was removed. Further, the documentation was changed to 
match Brooks' recommendation.

The changes to gfortran.h and trans-intrinsic.c shown in the last patch were 
added by accident and removed in this one.

gcc/fortran/
2007-03-08  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/30947
	* check.c (gfc_check_alarm_sub): Added check for default integer 
	kind of status argument.
        * iresolve.c (gfc_resolve_alarm_sub): Removed conversion of 
	status argument.
        * intrinsic.texi (ALARM): Extended documentation.

libgfortran/
2007-03-08  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/30947
        * intrinsics/signal.c (alarm_sub_int): Avoid SEGFAULT with 
	integer arguments.

Tested on i686-pc-linux-gnu.

Ok for trunk and 4.2?

	Daniel

Index: gcc/fortran/iresolve.c
===================================================================
--- gcc/fortran/iresolve.c	(revision 122639)
+++ gcc/fortran/iresolve.c	(working copy)
@@ -2386,8 +2386,6 @@
 
   if (seconds->ts.kind != gfc_c_int_kind)
     gfc_convert_type (seconds, &ts, 2);
-  if (status != NULL && status->ts.kind != gfc_c_int_kind)
-    gfc_convert_type (status, &ts, 2);
 
   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
 }
Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(revision 122639)
+++ gcc/fortran/check.c	(working copy)
@@ -2999,6 +2999,9 @@
   if (type_check (status, 2, BT_INTEGER) == FAILURE)
     return FAILURE;
 
+  if (kind_value_check (status, 2, gfc_default_integer_kind) == FAILURE)
+    return FAILURE;
+
   return SUCCESS;
 }
 
Index: gcc/fortran/intrinsic.texi
===================================================================
--- gcc/fortran/intrinsic.texi	(revision 122640)
+++ gcc/fortran/intrinsic.texi	(working copy)
@@ -782,7 +785,7 @@
 @table @asis
 @item @emph{Description}:
 @code{ALARM(SECONDS, HANDLER [, STATUS])} causes external subroutine @var{HANDLER}
-to be executed after a delay of @var{SECONDS} by using @code{alarm(1)} to
+to be executed after a delay of @var{SECONDS} by using @code{alarm(2)} to
 set up a signal and @code{signal(2)} to catch it. If @var{STATUS} is
 supplied, it will be returned with the number of seconds remaining until
 any previously scheduled alarm was due to be delivered, or zero if there
@@ -802,10 +805,11 @@
 @item @var{SECONDS} @tab The type of the argument shall be a scalar
 @code{INTEGER}. It is @code{INTENT(IN)}.
 @item @var{HANDLER} @tab Signal handler (@code{INTEGER FUNCTION} or
-@code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar.
-@code{INTEGER}. It is @code{INTENT(IN)}.
+@code{SUBROUTINE}) or dummy/global @code{INTEGER} scalar. The scalar 
+values may be either @code{SIG_IGN=1} to ignore the alarm generated 
+or @code{SIG_DFL=0} to set the default action. It is @code{INTENT(IN)}.
 @item @var{STATUS}  @tab (Optional) @var{STATUS} shall be a scalar
-@code{INTEGER} variable. It is @code{INTENT(OUT)}.
+variable of the default @code{INTEGER} kind. It is @code{INTENT(OUT)}.
 @end multitable
 
 @item @emph{Example}:
Index: libgfortran/intrinsics/signal.c
===================================================================
--- libgfortran/intrinsics/signal.c	(revision 122639)
+++ libgfortran/intrinsics/signal.c	(working copy)
@@ -170,14 +170,14 @@
 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
   if (status != NULL)
     {
-      if (signal (SIGALRM, (void (*)(int)) handler) == SIG_ERR)
+      if (signal (SIGALRM, (void (*)(int)) *handler) == SIG_ERR)
 	*status = -1;
       else
 	*status = alarm (*seconds);
     }
   else
     {
-      signal (SIGALRM, (void (*)(int)) handler);
+      signal (SIGALRM, (void (*)(int)) *handler);
       alarm (*seconds);
     }
 #else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]