[gfortran] add SIGNAL and ALARM intrinsics

Jakub Jelinek jakub@redhat.com
Sat Nov 19 19:48:00 GMT 2005


On Sat, Nov 19, 2005 at 08:16:03PM +0100, FX Coudert wrote:
> >+#ifdef HAVE_SIGNAL
> >+  if (status != NULL)
> >+    *status = (int) signal (*number, handler);
> >+  else
> >+    signal (*number, handler);
> >+#else
> >
> >(twice in that file) can't be right.  signal returns a function pointer
> >or SIG_ERR.  Casting a pointer to int is wrong.
> 
> Well, I'm just doing things the way g77 did. The g77 docs explicitly say:
> 
> ---------------
> Due to the side effects performed by this intrinsic, the function form 
> is not recommended.
> 
> Warning: If the returned value is stored in an INTEGER(KIND=1) (default 
> INTEGER) argument, truncation of the original return value occurs on 
> some systems (such as Alphas, which have 64-bit pointers but 32-bit 
> default integers), with no warning issued by g77 under normal circumstances.
> 
> Therefore, the following code fragment might silently fail on some systems:
> 
>      INTEGER RTN
>      EXTERNAL MYHNDL
>      RTN = SIGNAL(signum, MYHNDL)
>      ...
>      ! Restore original handler:
>      RTN = SIGNAL(signum, RTN)
> 
> The reason for the failure is that `RTN' might not hold all the 
> information on the original handler for the signal, thus restoring an 
> invalid handler. This bug could manifest itself as a spurious run-time 
> failure at an arbitrary point later during the program's execution, for 
> example.
> ---------------
> 
> I think it's clear enough. Though, if people think it's better to change 
> this behaviour, we could do it.

Then you should at least use *status = (long) signal (*number, handler);
to shut up the warnings about the cast if that's intentional.
With *status = (int) signal (*number, handler); it will warn:
../../../libgfortran/intrinsics/signal.c:52: warning: cast from pointer to integer of different size
../../../libgfortran/intrinsics/signal.c:73: warning: cast to pointer from integer of different size
../../../libgfortran/intrinsics/signal.c:73: warning: cast from pointer to integer of different size
../../../libgfortran/intrinsics/signal.c:75: warning: cast to pointer from integer of different size

	Jakub



More information about the Fortran mailing list