public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9691] Properly reset the port handle when closing
Date: Thu, 24 Mar 2022 10:33:57 +0000 (GMT)	[thread overview]
Message-ID: <20220324103357.E54D53857404@sourceware.org> (raw)

https://gcc.gnu.org/g:4c649dc71189f20ab8ed09b03a7353299f1022c8

commit r11-9691-g4c649dc71189f20ab8ed09b03a7353299f1022c8
Author: Pascal Obry <obry@adacore.com>
Date:   Thu Mar 24 11:30:05 2022 +0100

    Properly reset the port handle when closing
    
    When the serial port is closed, we need to ensure that the port handle is
    properly reset for it to be detected as closed.
    
    gcc/ada/
            PR ada/104767
            * libgnat/g-sercom__mingw.adb (Close): Reset port handle to -1.
            * libgnat/g-sercom__linux.adb (Close): Likewise.

Diff:
---
 gcc/ada/libgnat/g-sercom__linux.adb | 1 +
 gcc/ada/libgnat/g-sercom__mingw.adb | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/ada/libgnat/g-sercom__linux.adb b/gcc/ada/libgnat/g-sercom__linux.adb
index f7212e87cca..1ad48ca1720 100644
--- a/gcc/ada/libgnat/g-sercom__linux.adb
+++ b/gcc/ada/libgnat/g-sercom__linux.adb
@@ -382,6 +382,7 @@ package body GNAT.Serial_Communications is
    begin
       if Port.H /= -1 then
          Res := close (int (Port.H));
+         Port.H := -1;
       end if;
    end Close;
 
diff --git a/gcc/ada/libgnat/g-sercom__mingw.adb b/gcc/ada/libgnat/g-sercom__mingw.adb
index a0da5ff9434..1cf50905200 100644
--- a/gcc/ada/libgnat/g-sercom__mingw.adb
+++ b/gcc/ada/libgnat/g-sercom__mingw.adb
@@ -70,6 +70,7 @@ package body GNAT.Serial_Communications is
    begin
       if Port.H /= -1 then
          Success := CloseHandle (HANDLE (Port.H));
+         Port.H := -1;
 
          if Success = Win32.FALSE then
             Raise_Error ("error closing the port");


                 reply	other threads:[~2022-03-24 10:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220324103357.E54D53857404@sourceware.org \
    --to=ebotcazou@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).