OSDN Git Service

2008-08-18 Samuel Tardieu <sam@rfc1149.net>
authorsam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Aug 2008 09:09:24 +0000 (09:09 +0000)
committersam <sam@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Aug 2008 09:09:24 +0000 (09:09 +0000)
            Robert Dewar  <dewar@adacore.com>
    gcc/ada/
PR ada/30827
* bindgen.adb (Gen_Output_File_Ada): Zero-terminate the
version string.
Move comment in the right place.
* g-comver.adb (Version): Look for a zero-termination in
addition to a closing parenthesis.

2008-08-18  Robert Dewar  <dewar@adacore.com>
    gcc/testsuite/
PR ada/30827
* gnat.dg/test_version.adb: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@139192 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/bindgen.adb
gcc/ada/g-comver.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/test_version.adb [new file with mode: 0644]

index 47bcb8e..21e3e26 100644 (file)
@@ -1,4 +1,14 @@
 2008-08-18  Samuel Tardieu  <sam@rfc1149.net>
+            Robert Dewar  <dewar@adacore.com>
+
+       PR ada/30827
+       * bindgen.adb (Gen_Output_File_Ada): Zero-terminate the
+       version string.
+       Move comment in the right place.
+       * g-comver.adb (Version): Look for a zero-termination in
+       addition to a closing parenthesis.
+
+2008-08-18  Samuel Tardieu  <sam@rfc1149.net>
 
        * exp_ch13.adb, exp_disp.adb, sem_cat.adb, sem_ch10.adb,
        * sem_ch12.adb, sem_ch6.adb, sem_ch7.adb, sem_ch8.adb,
index 070651c..ccdf394 100644 (file)
@@ -2267,17 +2267,19 @@ package body Bindgen is
                WBI ("   gnat_exit_status : Integer;");
                WBI ("   pragma Import (C, gnat_exit_status);");
             end if;
-
-            --  Generate the GNAT_Version and Ada_Main_Program_Name info only
-            --  for the main program. Otherwise, it can lead under some
-            --  circumstances to a symbol duplication during the link (for
-            --  instance when a C program uses 2 Ada libraries)
          end if;
 
+         --  Generate the GNAT_Version and Ada_Main_Program_Name info only for
+         --  the main program. Otherwise, it can lead under some circumstances
+         --  to a symbol duplication during the link (for instance when a C
+         --  program uses two Ada libraries). Also zero terminate the string
+         --  so that its end can be found reliably at run time.
+
          WBI ("");
          WBI ("   GNAT_Version : constant String :=");
          WBI ("                    ""GNAT Version: " &
-                                Gnat_Version_String & """;");
+                                   Gnat_Version_String &
+                                   """ & ASCII.NUL;");
          WBI ("   pragma Export (C, GNAT_Version, ""__gnat_version"");");
 
          WBI ("");
index 2a0d120..ae3bf3b 100644 (file)
@@ -53,15 +53,18 @@ package body GNAT.Compiler_Version is
 
    function Version return String is
    begin
-      --  Search for terminating right paren
+      --  Search for terminating right paren or NUL ending the string
 
       for J in Ver_Prefix'Length + 1 .. GNAT_Version'Last loop
          if GNAT_Version (J) = ')' then
             return GNAT_Version (Ver_Prefix'Length + 1 .. J);
          end if;
+         if GNAT_Version (J) = Character'Val (0) then
+            return GNAT_Version (Ver_Prefix'Length + 1 .. J - 1);
+         end if;
       end loop;
 
-      --  This should not happen (no right paren found)
+      --  This should not happen (no right paren or NUL found)
 
       return GNAT_Version;
    end Version;
index 9eca6a0..56cd326 100644 (file)
@@ -1,3 +1,8 @@
+2008-08-18  Robert Dewar  <dewar@adacore.com>
+
+       PR ada/30827
+       * gnat.dg/test_version.adb: New.
+
 2008-08-18  Samuel Tardieu  <sam@rfc1149.net>
 
        PR ada/15808
diff --git a/gcc/testsuite/gnat.dg/test_version.adb b/gcc/testsuite/gnat.dg/test_version.adb
new file mode 100644 (file)
index 0000000..d7fa297
--- /dev/null
@@ -0,0 +1,13 @@
+-- { dg-do run }
+with GNAT.Compiler_Version;
+procedure Test_Version is
+   package Vsn is new GNAT.Compiler_Version;
+   use Vsn;
+   X : constant String := Version;
+begin
+   if X'Length = 46 then
+      -- 46 = Ver_Len_Max + Ver_Prefix
+      -- actual version should be shorter than this
+      raise Program_Error;
+   end if;
+end Test_Version;