https://gcc.gnu.org/g:96d0cbed4ae81081b3f672cc0b0f1e57a3923e46
commit r17-1202-g96d0cbed4ae81081b3f672cc0b0f1e57a3923e46 Author: Piotr Trojanek <[email protected]> Date: Thu Apr 16 12:01:33 2026 +0200 ada: Simplify host and target suffix queries Code cleanup for host and target suffixes, which are stored in C runtime code. gcc/ada/ChangeLog: * libgnat/s-os_lib.adb (Get_Debuggable_Suffix, Get_Executable_Suffix, Get_Object_Suffix, Get_Target_Debuggable_Suffix, Get_Target_Executable_Suffix, Get_Target_Object_Suffix): Access strings like we do in Gnatlink. * adaint.c (__gnat_object_suffix, __gnat_executable_suffix, __gnat_debuggable_suffix): Now constants, just like the ones for target suffixes. Diff: --- gcc/ada/adaint.c | 45 +++--------------- gcc/ada/libgnat/s-os_lib.adb | 106 ++++++++----------------------------------- 2 files changed, 25 insertions(+), 126 deletions(-) diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index 5fb255717746..cf8851260676 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -698,51 +698,18 @@ __gnat_get_current_dir (char *dir, int *length) dir[*length] = '\0'; } -/* Return the suffix for object files. */ +/* Suffix for object files. */ -void -__gnat_get_object_suffix_ptr (int *len, const char **value) -{ - *value = HOST_OBJECT_SUFFIX; - - if (*value == 0) - *len = 0; - else - *len = strlen (*value); +const char *__gnat_object_suffix = HOST_OBJECT_SUFFIX; - return; -} +/* Suffix for executable files. */ -/* Return the suffix for executable files. */ - -void -__gnat_get_executable_suffix_ptr (int *len, const char **value) -{ - *value = HOST_EXECUTABLE_SUFFIX; - - if (!*value) - *len = 0; - else - *len = strlen (*value); +const char *__gnat_executable_suffix = HOST_EXECUTABLE_SUFFIX; - return; -} - -/* Return the suffix for debuggable files. Usually this is the same as the +/* Suffix for debuggable files. Usually this is the same as the executable extension. */ -void -__gnat_get_debuggable_suffix_ptr (int *len, const char **value) -{ - *value = HOST_EXECUTABLE_SUFFIX; - - if (*value == 0) - *len = 0; - else - *len = strlen (*value); - - return; -} +const char *__gnat_debuggable_suffix = HOST_EXECUTABLE_SUFFIX; /* Returns the OS filename and corresponding encoding. */ diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb index ae8ef2b1a08b..0caab7e045e0 100644 --- a/gcc/ada/libgnat/s-os_lib.adb +++ b/gcc/ada/libgnat/s-os_lib.adb @@ -35,6 +35,7 @@ with System.Case_Util; with System.CRTL; with System.Soft_Links; with Interfaces.C; +with Interfaces.C.Strings; package body System.OS_Lib is @@ -1034,22 +1035,11 @@ package body System.OS_Lib is --------------------------- function Get_Debuggable_Suffix return String_Access is - procedure Get_Suffix_Ptr (Length, Ptr : Address); - pragma Import (C, Get_Suffix_Ptr, "__gnat_get_debuggable_suffix_ptr"); - - Result : String_Access; - Suffix_Length : Integer; - Suffix_Ptr : Address; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_debuggable_suffix"); begin - Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy (Result.all'Address, Suffix_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Debuggable_Suffix; --------------------------- @@ -1057,22 +1047,11 @@ package body System.OS_Lib is --------------------------- function Get_Executable_Suffix return String_Access is - procedure Get_Suffix_Ptr (Length, Ptr : Address); - pragma Import (C, Get_Suffix_Ptr, "__gnat_get_executable_suffix_ptr"); - - Result : String_Access; - Suffix_Length : Integer; - Suffix_Ptr : Address; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_executable_suffix"); begin - Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy (Result.all'Address, Suffix_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Executable_Suffix; ----------------------- @@ -1080,22 +1059,11 @@ package body System.OS_Lib is ----------------------- function Get_Object_Suffix return String_Access is - procedure Get_Suffix_Ptr (Length, Ptr : Address); - pragma Import (C, Get_Suffix_Ptr, "__gnat_get_object_suffix_ptr"); - - Result : String_Access; - Suffix_Length : Integer; - Suffix_Ptr : Address; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_object_suffix"); begin - Get_Suffix_Ptr (Suffix_Length'Address, Suffix_Ptr'Address); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy (Result.all'Address, Suffix_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Object_Suffix; ---------------------------------- @@ -1103,23 +1071,11 @@ package body System.OS_Lib is ---------------------------------- function Get_Target_Debuggable_Suffix return String_Access is - Target_Exec_Ext_Ptr : Address; - pragma Import - (C, Target_Exec_Ext_Ptr, "__gnat_target_debuggable_extension"); - - Result : String_Access; - Suffix_Length : Integer; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_target_debuggable_extension"); begin - Suffix_Length := Integer (CRTL.strlen (Target_Exec_Ext_Ptr)); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy - (Result.all'Address, Target_Exec_Ext_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Target_Debuggable_Suffix; ---------------------------------- @@ -1127,23 +1083,11 @@ package body System.OS_Lib is ---------------------------------- function Get_Target_Executable_Suffix return String_Access is - Target_Exec_Ext_Ptr : Address; - pragma Import - (C, Target_Exec_Ext_Ptr, "__gnat_target_executable_extension"); - - Result : String_Access; - Suffix_Length : Integer; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_target_executable_extension"); begin - Suffix_Length := Integer (CRTL.strlen (Target_Exec_Ext_Ptr)); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy - (Result.all'Address, Target_Exec_Ext_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Target_Executable_Suffix; ------------------------------ @@ -1151,23 +1095,11 @@ package body System.OS_Lib is ------------------------------ function Get_Target_Object_Suffix return String_Access is - Target_Object_Ext_Ptr : Address; - pragma Import - (C, Target_Object_Ext_Ptr, "__gnat_target_object_extension"); - - Result : String_Access; - Suffix_Length : Integer; + Suffix : constant Interfaces.C.Strings.chars_ptr; + pragma Import (C, Suffix, "__gnat_target_object_extension"); begin - Suffix_Length := Integer (CRTL.strlen (Target_Object_Ext_Ptr)); - Result := new String (1 .. Suffix_Length); - - if Suffix_Length > 0 then - Strncpy - (Result.all'Address, Target_Object_Ext_Ptr, size_t (Suffix_Length)); - end if; - - return Result; + return new String'(Interfaces.C.Strings.Value (Suffix)); end Get_Target_Object_Suffix; ------------
