]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Simplify uses of readdir_gnat with object overlay
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 15 Jun 2022 15:41:00 +0000 (17:41 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 13 May 2024 08:03:27 +0000 (10:03 +0200)
Code cleanup; behavior is unaffected.

gcc/ada/

* libgnat/a-direct.adb (Start_Search_Internal): Combine subtype
and object declaration.
* libgnat/g-dirope.adb (Read): Replace convoluted unchecked
conversion with an overlay.

gcc/ada/libgnat/a-direct.adb
gcc/ada/libgnat/g-dirope.adb

index 9e399c1003e7e5558ba2f97dfcfeaa375aaf55f7..32e020c48c37b312b0bcd51a646b11cbf4c11591 100644 (file)
@@ -1367,9 +1367,7 @@ package body Ada.Directories is
          --  the Filter add it to our search vector.
 
          declare
-            subtype File_Name_String is String (1 .. File_Name_Len);
-
-            File_Name : constant File_Name_String
+            File_Name : constant String (1 .. File_Name_Len)
               with Import, Address => File_Name_Addr;
 
          begin
index 428d27d9e8deed253b511a0e46b4de878fdf9cee..d8ac0ec06f874f439860bdccc7ab69da5034b085 100644 (file)
@@ -34,7 +34,6 @@ with Ada.Characters.Handling;
 with Ada.Strings.Fixed;
 
 with Ada.Unchecked_Deallocation;
-with Ada.Unchecked_Conversion;
 
 with System;      use System;
 with System.CRTL; use System.CRTL;
@@ -677,24 +676,15 @@ package body GNAT.Directory_Operations is
       end if;
 
       declare
-         subtype Path_String is String (1 .. Filename_Len);
-         type    Path_String_Access is not null access constant Path_String;
-
-         function Address_To_Access is new
-           Ada.Unchecked_Conversion
-             (Source => Address,
-              Target => Path_String_Access);
-
-         Path_Access : constant Path_String_Access :=
-                         Address_To_Access (Filename_Addr);
-
+         Filename : constant String (1 .. Filename_Len)
+           with Import, Address => Filename_Addr;
       begin
          if Str'Length > Filename_Len then
             Last := Str'First + Filename_Len - 1;
-            Str (Str'First .. Last) := Path_Access.all;
+            Str (Str'First .. Last) := Filename;
          else
             Last := Str'Last;
-            Str := Path_Access (1 .. Str'Length);
+            Str := Filename (1 .. Str'Length);
          end if;
       end;
    end Read;