aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt/grt-vstrings.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-06-01 21:51:39 +0200
committerTristan Gingold <tgingold@free.fr>2019-06-02 17:44:47 +0200
commitdfbbed7c92715eb8ac4ac634076c29148e56a872 (patch)
treeadeffb4de1e6578ca173ce082b8e09dcc00159a9 /src/grt/grt-vstrings.adb
parent86967acd4b60325b3ac53aaac11268c396e74fa3 (diff)
downloadghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.tar.gz
ghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.tar.bz2
ghdl-dfbbed7c92715eb8ac4ac634076c29148e56a872.zip
grt-vstrings: refactor.
Diffstat (limited to 'src/grt/grt-vstrings.adb')
-rw-r--r--src/grt/grt-vstrings.adb32
1 files changed, 11 insertions, 21 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;