* use dynamic arrays instead of getmem for resource strings

This commit is contained in:
Michaël Van Canneyt 2025-03-18 10:50:11 +01:00
parent 1547f28a40
commit ef5c0a4ba8

View File

@ -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); SetLength(AValue,Len);
Move(asym.value.valueptr^,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 AValue:=nil;
FreeMem(AValue);
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