Browse Source

* use dynamic arrays instead of getmem for resource strings

Michaël Van Canneyt 4 months ago
parent
commit
ef5c0a4ba8
1 changed files with 6 additions and 7 deletions
  1. 6 7
      compiler/cresstr.pas

+ 6 - 7
compiler/cresstr.pas

@@ -44,7 +44,7 @@ uses
       TResourceStringItem = class(TLinkedListItem)
       TResourceStringItem = class(TLinkedListItem)
         Sym   : TConstSym;
         Sym   : TConstSym;
         Name  : String;
         Name  : String;
-        AValue : PAnsiChar;
+        AValue : TAnsiCharDynArray;
         WValue : pcompilerwidestring; // just a reference, do not free.
         WValue : pcompilerwidestring; // just a reference, do not free.
         Len   : Longint; // in bytes, not characters
         Len   : Longint; // in bytes, not characters
         hash  : Cardinal;
         hash  : Cardinal;
@@ -92,8 +92,8 @@ uses
         else
         else
           begin
           begin
           Len:=asym.value.len;
           Len:=asym.value.len;
-          GetMem(AValue,Len);
-          Move(asym.value.valueptr^,AValue^,Len);
+          SetLength(AValue,Len);
+          Move(asym.value.valueptr^,AValue[0],Len);
           end;
           end;
         CalcHash;
         CalcHash;
       end;
       end;
@@ -101,8 +101,7 @@ uses
 
 
     destructor TResourceStringItem.Destroy;
     destructor TResourceStringItem.Destroy;
       begin
       begin
-        if Assigned(AValue) then
-          FreeMem(AValue);
+        AValue:=nil;
       end;
       end;
 
 
 
 
@@ -209,7 +208,7 @@ uses
               else
               else
                 begin
                 begin
                 if assigned(R.AValue) then
                 if assigned(R.AValue) then
-                  valuelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],R.AValue,R.Len,getansistringcodepage)
+                  valuelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],PAnsiChar(R.AValue),R.Len,getansistringcodepage)
                 end;
                 end;
               end;
               end;
             current_asmdata.asmlists[al_const].concat(cai_align.Create(sizeof(pint)));
             current_asmdata.asmlists[al_const].concat(cai_align.Create(sizeof(pint)));
@@ -293,7 +292,7 @@ uses
             if Not r.isUnicode then
             if Not r.isUnicode then
               begin
               begin
               initwidestring(W);
               initwidestring(W);
-              ascii2unicode(R.AValue,R.Len,current_settings.sourcecodepage,W);
+              ascii2unicode(PAnsiChar(R.AValue),R.Len,current_settings.sourcecodepage,W);
               end
               end
             else
             else
               begin
               begin