[gfortran] add SIGNAL and ALARM intrinsics

Bernhard Fischer rep.nop@aon.at
Sat Sep 16 20:20:00 GMT 2006


On Sun, Nov 20, 2005 at 10:07:19AM +0100, Andreas Jaeger wrote:
>FX Coudert <fxcoudert@gmail.com> writes:
>
>>>> Then you should at least use *status = (long) signal (*number, handler);
>>>> to shut up the warnings about the cast if that's intentional.
>>
>> Doesn't that only works on platforms where a pointer has the same size
>> as long?
>
>Which is most platforms except MS Windows on x86-64.  You should use
>intptr_t if it's defined...
>
>>> Plus a comment in the source would help too I guess.
>>
>> OK. Will do it when I understand the first point.
>

I'm attaching a patch to use intptr_t for the signals. I do not know if
the #if 0'd test is the proper thing to do and if that test will work as
expected, though.

Please let me know if the test is appropriate and commit or let me know
if it is ok so i can commit it.

TIA,
Bernhard
-------------- next part --------------
Index: libgfortran/intrinsics/signal.c
===================================================================
--- libgfortran/intrinsics/signal.c	(revision 107662)
+++ libgfortran/intrinsics/signal.c	(working copy)
@@ -37,19 +37,26 @@ Boston, MA 02110-1301, USA.  */
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
 #endif
+#if 0 && !defined HAVE_INTPTR_T && !defined __intptr_t_defined
+#if __WORDSIZE == 64
+typedef long int intptr_t;
+#else
+typedef int intptr_t;
+#endif
+#endif
 
 #include <errno.h>
 
 /* SIGNAL subroutine with PROCEDURE as handler  */
-extern void signal_sub (int *, void (*)(int), int *);
+extern void signal_sub (int *, void (*)(int), intptr_t *);
 iexport_proto(signal_sub);
 
 void
-signal_sub (int *number, void (*handler)(int), int *status)
+signal_sub (int *number, void (*handler)(int), intptr_t *status)
 {
 #ifdef HAVE_SIGNAL
   if (status != NULL)
-    *status = (int) signal (*number, handler);
+    *status = (intptr_t) signal (*number, handler);
   else
     signal (*number, handler);
 #else
@@ -62,17 +69,17 @@ iexport(signal_sub);
 
 
 /* SIGNAL subroutine with INTEGER as handler  */
-extern void signal_sub_int (int *, int *, int *);
+extern void signal_sub_int (int *, int *, intptr_t *);
 iexport_proto(signal_sub_int);
 
 void
-signal_sub_int (int *number, int *handler, int *status)
+signal_sub_int (int *number, int *handler, intptr_t *status)
 {
 #ifdef HAVE_SIGNAL
   if (status != NULL)
-    *status = (int) signal (*number, (void (*)(int)) *handler);
+    *status = (intptr_t) signal (*number, (void (*)(int)) handler);
   else
-    signal (*number, (void (*)(int)) *handler);
+    signal (*number, (void (*)(int)) handler);
 #else
   errno = ENOSYS;
   if (status != NULL)
@@ -89,7 +96,7 @@ iexport_proto(signal_func);
 int
 signal_func (int *number, void (*handler)(int))
 {
-  int status;
+  intptr_t status;
   signal_sub (number, handler, &status);
   return status;
 }
@@ -103,7 +110,7 @@ iexport_proto(signal_func_int);
 int
 signal_func_int (int *number, int *handler)
 {
-  int status;
+  intptr_t status;
   signal_sub_int (number, handler, &status);
   return status;
 }
Index: libgfortran/configure.ac
===================================================================
--- libgfortran/configure.ac	(revision 107662)
+++ libgfortran/configure.ac	(working copy)
@@ -160,6 +160,9 @@ AC_CHECK_HEADERS(sys/mman.h sys/types.h 
 AC_CHECK_HEADERS(fenv.h fptrap.h float.h)
 AC_CHECK_HEADER([complex.h],[AC_DEFINE([HAVE_COMPLEX_H], [1], [complex.h exists])])
 
+dnl check if intptr_t is defined
+AC_CHECK_TYPE([intptr_t],[long])
+
 AC_CHECK_MEMBERS([struct stat.st_blksize])
 AC_CHECK_MEMBERS([struct stat.st_blocks])
 AC_CHECK_MEMBERS([struct stat.st_rdev])


More information about the Fortran mailing list