This fixes the simple C interfacing issues recently reported by Jan (the 
signedness issue of char will probably be fixed for GCC 6, the duality 
pointer/System.Address probably _not_ unfortunately).

Tested on x86_64-suse-linux, applied on the mainline.


2015-11-30  Eric Botcazou  <ebotca...@adacore.com>

        * osint.adb: Add use type clause for CRTL.size_t.
        (C_String_Length): Return CRTL.size_t instead of Integer.
        (To_Path_String_Access): Take CRTL.size_t instead of Integer.
        (Get_Libraries_From_Registry): Use CRTL throughout.
        (To_Canonical_Dir_Spec): Use CRTL.size_t instead of Integer.
        (To_Canonical_File_List): Likewise.
        (To_Canonical_File_Spec): Likewise.
        (To_Canonical_Path_Spec): Likewise.
        (To_Host_Dir_Spec): Likewise.
        (To_Host_File_Spec): Likewise.
        (Update_Path): Use CRTL throughout.
        * s-shasto.adb: Add with clause for System.CRTL.
        (Initialize): Rename CRTL.strncpy instead of importing it manually.


-- 
Eric Botcazou
Index: osint.adb
===================================================================
--- osint.adb	(revision 231010)
+++ osint.adb	(working copy)
@@ -46,6 +46,8 @@ with GNAT.HTable;
 
 package body Osint is
 
+   use type CRTL.size_t;
+
    Running_Program : Program_Type := Unspecified;
    --  comment required here ???
 
@@ -135,12 +137,12 @@ package body Osint is
    --  A version of Smart_Find_File that also returns a cache of the file
    --  attributes for later reuse
 
-   function C_String_Length (S : Address) return Integer;
+   function C_String_Length (S : Address) return CRTL.size_t;
    --  Returns length of a C string (zero for a null address)
 
    function To_Path_String_Access
      (Path_Addr : Address;
-      Path_Len  : Integer) return String_Access;
+      Path_Len  : CRTL.size_t) return String_Access;
    --  Converts a C String to an Ada String. Are we doing this to avoid withing
    --  Interfaces.C.Strings ???
    --  Caller must free result.
@@ -419,27 +421,18 @@ package body Osint is
          pragma Import (C, C_Get_Libraries_From_Registry,
                         "__gnat_get_libraries_from_registry");
 
-         function Strlen (Str : Address) return Integer;
-         pragma Import (C, Strlen, "strlen");
-
-         procedure Strncpy (X : Address; Y : Address; Length : Integer);
-         pragma Import (C, Strncpy, "strncpy");
-
-         procedure C_Free (Str : Address);
-         pragma Import (C, C_Free, "free");
-
          Result_Ptr    : Address;
-         Result_Length : Integer;
+         Result_Length : CRTL.size_t;
          Out_String    : String_Ptr;
 
       begin
          Result_Ptr := C_Get_Libraries_From_Registry;
-         Result_Length := Strlen (Result_Ptr);
+         Result_Length := CRTL.strlen (Result_Ptr);
 
-         Out_String := new String (1 .. Result_Length);
-         Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
+         Out_String := new String (1 .. Integer (Result_Length));
+         CRTL.strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
 
-         C_Free (Result_Ptr);
+         CRTL.free (Result_Ptr);
 
          return Out_String;
       end Get_Libraries_From_Registry;
@@ -673,14 +666,12 @@ package body Osint is
    -- C_String_Length --
    ---------------------
 
-   function C_String_Length (S : Address) return Integer is
-      function Strlen (S : Address) return Integer;
-      pragma Import (C, Strlen, "strlen");
+   function C_String_Length (S : Address) return CRTL.size_t is
    begin
       if S = Null_Address then
          return 0;
       else
-         return Strlen (S);
+         return CRTL.strlen (S);
       end if;
    end C_String_Length;
 
@@ -2959,7 +2950,7 @@ package body Osint is
 
       C_Host_Dir         : String (1 .. Host_Dir'Length + 1);
       Canonical_Dir_Addr : Address;
-      Canonical_Dir_Len  : Integer;
+      Canonical_Dir_Len  : CRTL.size_t;
 
    begin
       C_Host_Dir (1 .. Host_Dir'Length) := Host_Dir;
@@ -3023,7 +3014,7 @@ package body Osint is
       declare
          Canonical_File_List : String_Access_List (1 .. Num_Files);
          Canonical_File_Addr : Address;
-         Canonical_File_Len  : Integer;
+         Canonical_File_Len  : CRTL.size_t;
 
       begin
          --  Retrieve the expanded directory names and build the list
@@ -3056,7 +3047,7 @@ package body Osint is
 
       C_Host_File         : String (1 .. Host_File'Length + 1);
       Canonical_File_Addr : Address;
-      Canonical_File_Len  : Integer;
+      Canonical_File_Len  : CRTL.size_t;
 
    begin
       C_Host_File (1 .. Host_File'Length) := Host_File;
@@ -3091,7 +3082,7 @@ package body Osint is
 
       C_Host_Path         : String (1 .. Host_Path'Length + 1);
       Canonical_Path_Addr : Address;
-      Canonical_Path_Len  : Integer;
+      Canonical_Path_Len  : CRTL.size_t;
 
    begin
       C_Host_Path (1 .. Host_Path'Length) := Host_Path;
@@ -3126,7 +3117,7 @@ package body Osint is
 
       C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1);
       Host_Dir_Addr   : Address;
-      Host_Dir_Len    : Integer;
+      Host_Dir_Len    : CRTL.size_t;
 
    begin
       C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir;
@@ -3158,7 +3149,7 @@ package body Osint is
 
       C_Canonical_File      : String (1 .. Canonical_File'Length + 1);
       Host_File_Addr : Address;
-      Host_File_Len  : Integer;
+      Host_File_Len  : CRTL.size_t;
 
    begin
       C_Canonical_File (1 .. Canonical_File'Length) := Canonical_File;
@@ -3181,9 +3172,9 @@ package body Osint is
 
    function To_Path_String_Access
      (Path_Addr : Address;
-      Path_Len  : Integer) return String_Access
+      Path_Len  : CRTL.size_t) return String_Access
    is
-      subtype Path_String is String (1 .. Path_Len);
+      subtype Path_String is String (1 .. Integer (Path_Len));
       type Path_String_Access is access Path_String;
 
       function Address_To_Access is new
@@ -3196,9 +3187,9 @@ package body Osint is
       Return_Val : String_Access;
 
    begin
-      Return_Val := new String (1 .. Path_Len);
+      Return_Val := new String (1 .. Integer (Path_Len));
 
-      for J in 1 .. Path_Len loop
+      for J in 1 .. Integer (Path_Len) loop
          Return_Val (J) := Path_Access (J);
       end loop;
 
@@ -3214,27 +3205,21 @@ package body Osint is
       function C_Update_Path (Path, Component : Address) return Address;
       pragma Import (C, C_Update_Path, "update_path");
 
-      function Strlen (Str : Address) return Integer;
-      pragma Import (C, Strlen, "strlen");
-
-      procedure Strncpy (X : Address; Y : Address; Length : Integer);
-      pragma Import (C, Strncpy, "strncpy");
-
       In_Length      : constant Integer := Path'Length;
       In_String      : String (1 .. In_Length + 1);
       Component_Name : aliased String := "GCC" & ASCII.NUL;
       Result_Ptr     : Address;
-      Result_Length  : Integer;
+      Result_Length  : CRTL.size_t;
       Out_String     : String_Ptr;
 
    begin
       In_String (1 .. In_Length) := Path.all;
       In_String (In_Length + 1) := ASCII.NUL;
       Result_Ptr := C_Update_Path (In_String'Address, Component_Name'Address);
-      Result_Length := Strlen (Result_Ptr);
+      Result_Length := CRTL.strlen (Result_Ptr);
 
-      Out_String := new String (1 .. Result_Length);
-      Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
+      Out_String := new String (1 .. Integer (Result_Length));
+      CRTL.strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
       return Out_String;
    end Update_Path;
 
Index: s-shasto.adb
===================================================================
--- s-shasto.adb	(revision 231010)
+++ s-shasto.adb	(working copy)
@@ -37,6 +37,7 @@ with System.Global_Locks;
 with System.Soft_Links;
 
 with System;
+with System.CRTL;
 with System.File_Control_Block;
 with System.File_IO;
 with System.HTable;
@@ -270,24 +271,26 @@ package body System.Shared_Storage is
       procedure Get_Env_Value_Ptr (Name, Length, Ptr : Address);
       pragma Import (C, Get_Env_Value_Ptr, "__gnat_getenv");
 
-      procedure Strncpy (Astring_Addr, Cstring : Address; N : Integer);
-      pragma Import (C, Strncpy, "strncpy");
+      subtype size_t is CRTL.size_t;
+
+      procedure Strncpy (dest, src : System.Address; n : size_t)
+        renames CRTL.strncpy;
 
       Dir_Name : aliased constant String :=
                    "SHARED_MEMORY_DIRECTORY" & ASCII.NUL;
 
-      Env_Value_Ptr    : aliased Address;
-      Env_Value_Length : aliased Integer;
+      Env_Value_Ptr : aliased Address;
+      Env_Value_Len : aliased Integer;
 
    begin
       if Dir = null then
          Get_Env_Value_Ptr
-           (Dir_Name'Address, Env_Value_Length'Address, Env_Value_Ptr'Address);
+           (Dir_Name'Address, Env_Value_Len'Address, Env_Value_Ptr'Address);
 
-         Dir := new String (1 .. Env_Value_Length);
+         Dir := new String (1 .. Env_Value_Len);
 
-         if Env_Value_Length > 0 then
-            Strncpy (Dir.all'Address, Env_Value_Ptr, Env_Value_Length);
+         if Env_Value_Len > 0 then
+            Strncpy (Dir.all'Address, Env_Value_Ptr, size_t (Env_Value_Len));
          end if;
 
          System.Global_Locks.Create_Lock (Global_Lock, Dir.all & "__lock");

Reply via email to