* added an extra parameter to ttai_typedconstbuilder.emit_pchar_const() to

indicate whether it should create a copy of the pchar or not

git-svn-id: trunk@34153 -
This commit is contained in:
Jonas Maebe 2016-07-19 14:30:36 +00:00
parent 68cbbe677a
commit 8fea7344c9
2 changed files with 17 additions and 5 deletions

View File

@ -332,7 +332,7 @@ type
{ emit a shortstring constant, and return its def }
function emit_shortstring_const(const str: shortstring): tdef;
{ emit a pchar string constant (the characters, not a pointer to them), and return its def }
function emit_pchar_const(str: pchar; len: pint): tdef;
function emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
{ emit a guid constant }
procedure emit_guid_const(const guid: tguid);
{ emit a procdef constant }
@ -1526,14 +1526,26 @@ implementation
end;
function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint): tdef;
function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
var
newstr: pchar;
begin
result:=carraydef.getreusable(cansichartype,len+1);
maybe_begin_aggregate(result);
if len=0 then
if (len=0) and
(not assigned(str) or
copypchar) then
emit_tai(Tai_const.Create_8bit(0),cansichartype)
else
emit_tai(Tai_string.Create_pchar(str,len+1),result);
begin
if copypchar then
begin
getmem(newstr,len+1);
move(str^,newstr^,len+1);
str:=newstr;
end;
emit_tai(Tai_string.Create_pchar(str,len+1),result);
end;
maybe_end_aggregate(result);
end;

View File

@ -166,7 +166,7 @@ procedure objcreatestringpoolentryintern(p: pchar; len: longint; pooltype: tcons
{ add the string to the approriate section }
tcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_new_section]);
def:=tcb.emit_pchar_const(pc,entry^.keylength);
def:=tcb.emit_pchar_const(pc,entry^.keylength,false);
current_asmdata.asmlists[al_objc_pools].concatList(
tcb.get_final_asmlist(strlab,def,stringsec,strlab.name,1)
);