public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler
@ 2023-10-16 17:11 Tobias Burnus
  2023-10-16 18:31 ` Harald Anlauf
  2023-10-17 11:26 ` [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Stanislav Maslovski
  0 siblings, 2 replies; 8+ messages in thread
From: Tobias Burnus @ 2023-10-16 17:11 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

Yesterday, someone was confused because the signal handler did not work.

It turned out that the created Fortran procedure used as handler used
pass by reference - and 'signal' passed the it by value.

This patch adds the 'passed by value' to the wording:

"@var{HANDLER} to be executed with a single integer argument passed by
value"

OK for mainline?

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: signal-doc.diff --]
[-- Type: text/x-patch, Size: 1189 bytes --]

fortran/intrinsic.texi: Add 'passed by value' to signal handler

gcc/fortran/ChangeLog:

	* intrinsic.texi (signal): Mention that the argument
	passed to the signal handler procedure is passed by reference.

diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 6c7ad03a02c..3620209e00a 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -13168,10 +13168,10 @@ end program test_sign
 @table @asis
 @item @emph{Description}:
 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
-@var{HANDLER} to be executed with a single integer argument when signal
-@var{NUMBER} occurs.  If @var{HANDLER} is an integer, it can be used to
-turn off handling of signal @var{NUMBER} or revert to its default
-action.  See @code{signal(2)}.
+@var{HANDLER} to be executed with a single integer argument passed by
+value when signal @var{NUMBER} occurs.  If @var{HANDLER} is an integer,
+it can be used to turn off handling of signal @var{NUMBER} or revert to
+its default action.  See @code{signal(2)}.
 
 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
 is supplied, it is set to the value returned by @code{signal(2)}.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler
  2023-10-16 17:11 [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Tobias Burnus
@ 2023-10-16 18:31 ` Harald Anlauf
  2023-10-16 18:37   ` Steve Kargl
  2023-10-17  7:47   ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry (was: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler) Tobias Burnus
  2023-10-17 11:26 ` [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Stanislav Maslovski
  1 sibling, 2 replies; 8+ messages in thread
From: Harald Anlauf @ 2023-10-16 18:31 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

Hi Tobias,

Am 16.10.23 um 19:11 schrieb Tobias Burnus:
> Yesterday, someone was confused because the signal handler did not work.
>
> It turned out that the created Fortran procedure used as handler used
> pass by reference - and 'signal' passed the it by value.
>
> This patch adds the 'passed by value' to the wording:
>
> "@var{HANDLER} to be executed with a single integer argument passed by
> value"
>
> OK for mainline?

I think the patch qualifies as obvious.

While at it, you might consider removing the comment a few lines below
the place you are changing,

@c TODO: What should the interface of the handler be?  Does it take
arguments?

and enhance the given example by e.g.:

subroutine handler_print (signal_number)
   integer, value :: signal_number
   print *, "In handler_print: received signal number", signal_number
end subroutine handler_print

Thanks,
Harald

> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201,
> 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer:
> Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München;
> Registergericht München, HRB 106955


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler
  2023-10-16 18:31 ` Harald Anlauf
@ 2023-10-16 18:37   ` Steve Kargl
  2023-10-17  7:47   ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry (was: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler) Tobias Burnus
  1 sibling, 0 replies; 8+ messages in thread
From: Steve Kargl @ 2023-10-16 18:37 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: Tobias Burnus, gcc-patches, fortran

On Mon, Oct 16, 2023 at 08:31:20PM +0200, Harald Anlauf wrote:
> 
> Am 16.10.23 um 19:11 schrieb Tobias Burnus:
> > Yesterday, someone was confused because the signal handler did not work.
> > 
> > It turned out that the created Fortran procedure used as handler used
> > pass by reference - and 'signal' passed the it by value.
> > 
> > This patch adds the 'passed by value' to the wording:
> > 
> > "@var{HANDLER} to be executed with a single integer argument passed by
> > value"
> > 
> > OK for mainline?
> 
> I think the patch qualifies as obvious.
> 
> While at it, you might consider removing the comment a few lines below
> the place you are changing,
> 
> @c TODO: What should the interface of the handler be?  Does it take
> arguments?
> 
> and enhance the given example by e.g.:
> 
> subroutine handler_print (signal_number)
>   integer, value :: signal_number
>   print *, "In handler_print: received signal number", signal_number
> end subroutine handler_print
> 

Good suggestion, Harald.  I was composing a similar email
when I saw yours pop into by inbox.

-- 
Steve

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry (was: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler)
  2023-10-16 18:31 ` Harald Anlauf
  2023-10-16 18:37   ` Steve Kargl
@ 2023-10-17  7:47   ` Tobias Burnus
  2023-10-17 17:02     ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry Harald Anlauf
  1 sibling, 1 reply; 8+ messages in thread
From: Tobias Burnus @ 2023-10-17  7:47 UTC (permalink / raw)
  To: Harald Anlauf, gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 849 bytes --]

Hi Harald,

On 16.10.23 20:31, Harald Anlauf wrote:
> Hi Tobias,
>
> Am 16.10.23 um 19:11 schrieb Tobias Burnus:
>> OK for mainline?
>
> I think the patch qualifies as obvious.
>
> While at it, you might consider removing the comment a few lines below
> the place you are changing,
>
> @c TODO: What should the interface of the handler be?  Does it take
> arguments?
>
> and enhance the given example by e.g.:

Updated version attached – I will commit it later today, unless anyone
has follow-up suggestions before.

Thanks for the suggestions,

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: signal-doc-v2.diff --]
[-- Type: text/x-patch, Size: 2196 bytes --]

fortran/intrinsic.texi: Improve SIGNAL intrinsic entry

gcc/fortran/ChangeLog:

	* intrinsic.texi (signal): Mention that the argument
	passed to the signal handler procedure is passed by reference.
	Extend example.

diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 6c7ad03a02c..fe446fc8a9d 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -13168,10 +13168,10 @@ end program test_sign
 @table @asis
 @item @emph{Description}:
 @code{SIGNAL(NUMBER, HANDLER [, STATUS])} causes external subroutine
-@var{HANDLER} to be executed with a single integer argument when signal
-@var{NUMBER} occurs.  If @var{HANDLER} is an integer, it can be used to
-turn off handling of signal @var{NUMBER} or revert to its default
-action.  See @code{signal(2)}.
+@var{HANDLER} to be executed with a single integer argument passed by
+value when signal @var{NUMBER} occurs.  If @var{HANDLER} is an integer,
+it can be used to turn off handling of signal @var{NUMBER} or revert to
+its default action.  See @code{signal(2)}.
 
 If @code{SIGNAL} is called as a subroutine and the @var{STATUS} argument
 is supplied, it is set to the value returned by @code{signal(2)}.
@@ -13197,19 +13197,25 @@ Subroutine, function
 @item @var{STATUS} @tab (Optional) @var{STATUS} shall be a scalar
 integer. It has @code{INTENT(OUT)}.
 @end multitable
-@c TODO: What should the interface of the handler be?  Does it take arguments?
 
 @item @emph{Return value}:
 The @code{SIGNAL} function returns the value returned by @code{signal(2)}.
 
 @item @emph{Example}:
 @smallexample
+module m_handler
+contains
+  ! POSIX.1-2017:  void (*func)(int)
+  subroutine handler_print(signum) bind(C)
+    use iso_c_binding, only: c_int
+    integer(c_int), value :: signum
+    print *, 'handler_print invoked with signum =', signum
+  end subroutine
+end module
 program test_signal
-  intrinsic signal
-  external handler_print
-
-  call signal (12, handler_print)
-  call signal (10, 1)
+  use m_handler
+  call signal (12, handler_print)  ! 12 = SIGUSR3 (on some systems)
+  call signal (10, 1)  ! 10 = SIGUSR1 and 1 = SIG_IGN (on some systems)
 
   call sleep (30)
 end program test_signal

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler
  2023-10-16 17:11 [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Tobias Burnus
  2023-10-16 18:31 ` Harald Anlauf
@ 2023-10-17 11:26 ` Stanislav Maslovski
  1 sibling, 0 replies; 8+ messages in thread
From: Stanislav Maslovski @ 2023-10-17 11:26 UTC (permalink / raw)
  To: fortran

Hi,

On Mon, Oct 16, 2023 at 07:11:46PM +0200, Tobias Burnus wrote:
> Yesterday, someone was confused because the signal handler did not work.
> 
> It turned out that the created Fortran procedure used as handler used
> pass by reference - and 'signal' passed the it by value.

Many thanks! Indeed, it was not clear that the argument is passed by
value (although, I could guess that as signal() is modeled on a C
function of the same name...)

-- 
Stanislav Maslovski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry
  2023-10-17  7:47   ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry (was: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler) Tobias Burnus
@ 2023-10-17 17:02     ` Harald Anlauf
  2023-10-17 17:36       ` Tobias Burnus
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Anlauf @ 2023-10-17 17:02 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

Tobias,

your latest patch - which you already pushed - removes the
intrinsic declaration of signal.

This can lead to a user's confusion and undesired results when
the code is compiled e.g. with -std=f2018, because

   call signal (10, 1)  ! 10 = SIGUSR1 and 1 = SIG_IGN (on some systems)

could be mapped to the wrong external instead of the
libgfortran function _gfortran_signal_sub_int etc., or you
could get other compile-time errors with the example code.

I strongly recommend to restore the intrinsic declaration.

Cheers,
Harald

Am 17.10.23 um 09:47 schrieb Tobias Burnus:
> Hi Harald,
>
> On 16.10.23 20:31, Harald Anlauf wrote:
>> Hi Tobias,
>>
>> Am 16.10.23 um 19:11 schrieb Tobias Burnus:
>>> OK for mainline?
>>
>> I think the patch qualifies as obvious.
>>
>> While at it, you might consider removing the comment a few lines below
>> the place you are changing,
>>
>> @c TODO: What should the interface of the handler be?  Does it take
>> arguments?
>>
>> and enhance the given example by e.g.:
>
> Updated version attached – I will commit it later today, unless anyone
> has follow-up suggestions before.
>
> Thanks for the suggestions,
>
> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201,
> 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer:
> Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München;
> Registergericht München, HRB 106955


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry
  2023-10-17 17:02     ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry Harald Anlauf
@ 2023-10-17 17:36       ` Tobias Burnus
  2023-10-17 18:05         ` Harald Anlauf
  0 siblings, 1 reply; 8+ messages in thread
From: Tobias Burnus @ 2023-10-17 17:36 UTC (permalink / raw)
  To: Harald Anlauf, gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 541 bytes --]

Hi Harald,

On 17.10.23 19:02, Harald Anlauf wrote:
> your latest patch - which you already pushed - removes the
> intrinsic declaration of signal.

Only to 'signal' or also to 'sleep'? I have now added both in the attach
patch.

(Not yet committed.)

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: 0001-fortran-intrinsic.texi-Add-intrinsic-to-SIGNAL-examp.patch --]
[-- Type: text/x-patch, Size: 863 bytes --]

From bad72a07e572e4e0ac5ae9c25b9a234d98b1258f Mon Sep 17 00:00:00 2001
From: Tobias Burnus <tobias@codesourcery.com>
Date: Tue, 17 Oct 2023 19:35:18 +0200
Subject: [PATCH] fortran/intrinsic.texi: Add 'intrinsic' to SIGNAL example

gcc/fortran/ChangeLog:

	* intrinsic.texi (signal): Add 'intrinsic :: signal, sleep' to
	the example to make it safer.
---
 gcc/fortran/intrinsic.texi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 0db557d5a38..d1407186aea 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -13214,6 +13214,7 @@ contains
 end module
 program test_signal
   use m_handler
+  intrinsic :: signal, sleep
   call signal (12, handler_print)  ! 12 = SIGUSR2 (on some systems)
   call signal (10, 1)  ! 10 = SIGUSR1 and 1 = SIG_IGN (on some systems)
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry
  2023-10-17 17:36       ` Tobias Burnus
@ 2023-10-17 18:05         ` Harald Anlauf
  0 siblings, 0 replies; 8+ messages in thread
From: Harald Anlauf @ 2023-10-17 18:05 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

Hi Tobias,

On 10/17/23 19:36, Tobias Burnus wrote:
> Hi Harald,
>
> On 17.10.23 19:02, Harald Anlauf wrote:
>> your latest patch - which you already pushed - removes the
>> intrinsic declaration of signal.
>
> Only to 'signal' or also to 'sleep'? I have now added both in the attach
> patch.

you are right: both should be declared as intrinsic.

Thanks,
Harald

> (Not yet committed.)
>
> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201,
> 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer:
> Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München;
> Registergericht München, HRB 106955


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-17 18:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-16 17:11 [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Tobias Burnus
2023-10-16 18:31 ` Harald Anlauf
2023-10-16 18:37   ` Steve Kargl
2023-10-17  7:47   ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry (was: [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler) Tobias Burnus
2023-10-17 17:02     ` [patch] fortran/intrinsic.texi: Improve SIGNAL intrinsic entry Harald Anlauf
2023-10-17 17:36       ` Tobias Burnus
2023-10-17 18:05         ` Harald Anlauf
2023-10-17 11:26 ` [patch] fortran/intrinsic.texi: Add 'passed by value' to signal handler Stanislav Maslovski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).