diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-06-01 21:51:39 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-06-02 17:44:47 +0200 |
commit | dfbbed7c92715eb8ac4ac634076c29148e56a872 (patch) | |
tree | adeffb4de1e6578ca173ce082b8e09dcc00159a9 /src/grt | |
parent | 86967acd4b60325b3ac53aaac11268c396e74fa3 (diff) | |
download | ghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.tar.gz ghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.tar.bz2 ghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.zip |
grt-vstrings: refactor.
Diffstat (limited to 'src/grt')
-rw-r--r-- | src/grt/grt-vstrings.adb | 32 | ||||
-rw-r--r-- | src/grt/grt-vstrings.ads | 7 |
2 files changed, 13 insertions, 26 deletions
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; diff --git a/src/grt/grt-vstrings.ads b/src/grt/grt-vstrings.ads index 02d0504db..375f294a6 100644 --- a/src/grt/grt-vstrings.ads +++ b/src/grt/grt-vstrings.ads @@ -81,18 +81,15 @@ package Grt.Vstrings is procedure Copy (Rstr : Rstring; Str : in out String; Len : out Natural); private - subtype Fat_String is String (Positive); - type Fat_String_Acc is access Fat_String; - type Vstring is record - Str : Fat_String_Acc := null; + Str : Ghdl_C_String := null; Max : Natural := 0; Len : Natural := 0; end record; type Rstring is record -- String whose bounds is (1 .. Max). - Str : Fat_String_Acc := null; + Str : Ghdl_C_String := null; -- Last index in STR. Max : Natural := 0; |