From dfbbed7c92715eb8ac4ac634076c29148e56a872 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sat, 1 Jun 2019 21:51:39 +0200 Subject: grt-vstrings: refactor. --- src/grt/grt-vstrings.adb | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/grt/grt-vstrings.adb') diff --git a/src/grt/grt-vstrings.adb b/src/grt/grt-vstrings.adb index 818701fa0..fe1dc8040 100644 --- a/src/grt/grt-vstrings.adb +++ b/src/grt/grt-vstrings.adb @@ -24,22 +24,12 @@ -- covered by the GNU Public License. with Grt.Errors; use Grt.Errors; +with Grt.C; use Grt.C; package body Grt.Vstrings is - procedure Free (Fs : Fat_String_Acc); - pragma Import (C, Free); - - function Malloc (Len : Natural) return Fat_String_Acc; - pragma Import (C, Malloc); - - function Realloc (Ptr : Fat_String_Acc; Len : Natural) - return Fat_String_Acc; - pragma Import (C, Realloc); - - procedure Free (Vstr : in out Vstring) is begin - Free (Vstr.Str); + Free (To_Address (Vstr.Str)); Vstr := (Str => null, Max => 0, Len => 0); @@ -67,7 +57,8 @@ package body Grt.Vstrings is while Nmax < Nlen loop Nmax := Nmax * 2; end loop; - Vstr.Str := Realloc (Vstr.Str, Nmax); + Vstr.Str := To_Ghdl_C_String + (Realloc (To_Address (Vstr.Str), size_t (Nmax))); if Vstr.Str = null then Internal_Error ("grt.vstrings.grow: memory exhausted"); end if; @@ -113,17 +104,17 @@ package body Grt.Vstrings is function Get_Address (Vstr : Vstring) return Address is begin - return Vstr.Str.all'Address; + return To_Address (Vstr.Str); end Get_Address; function Get_C_String (Vstr : Vstring) return Ghdl_C_String is begin - return To_Ghdl_C_String (Vstr.Str.all'Address); + return Vstr.Str; end Get_C_String; procedure Free (Rstr : in out Rstring) is begin - Free (Rstr.Str); + Free (To_Address (Rstr.Str)); Rstr := (Str => null, Max => 0, First => 0); @@ -138,7 +129,7 @@ package body Grt.Vstrings is is Len : constant Natural := Length (Rstr); Nlen : constant Natural := Len + Min; - Nstr : Fat_String_Acc; + Nstr : Ghdl_C_String; Nfirst : Natural; Nmax : Natural; begin @@ -153,11 +144,11 @@ package body Grt.Vstrings is while Nmax < Nlen loop Nmax := Nmax * 2; end loop; - Nstr := Malloc (Nmax); + Nstr := To_Ghdl_C_String (Malloc (size_t (Nmax))); Nfirst := Nmax + 1 - Len; if Rstr.Str /= null then Nstr (Nfirst .. Nmax) := Rstr.Str (Rstr.First .. Rstr.Max); - Free (Rstr.Str); + Free (To_Address (Rstr.Str)); end if; Rstr := (Str => Nstr, Max => Nmax, @@ -189,8 +180,7 @@ package body Grt.Vstrings is Rstr.Str (Rstr.First .. Rstr.First + L - 1) := Str (1 .. L); end Prepend; - function Get_Address (Rstr : Rstring) return Address - is + function Get_Address (Rstr : Rstring) return Address is begin return Rstr.Str (Rstr.First)'Address; end Get_Address; -- cgit v1.2.3