* replace/restore_scanner use var in state to make sure the correct scanner is freed

This commit is contained in:
Michaël Van Canneyt 2024-01-31 13:47:17 +01:00 committed by Michael Van Canneyt
parent 8fa3c57c1b
commit 4443e83b75

View File

@ -35,6 +35,7 @@ interface
type
tscannerstate = record
new_scanner: tscannerfile;
old_scanner: tscannerfile;
old_filepos: tfileposinfo;
old_token: ttoken;
@ -166,7 +167,8 @@ implementation
{ creating a new scanner resets the block type, while we want to continue
in the current one }
old_block_type:=block_type;
current_scanner:=tscannerfile.Create('_Macro_.'+tempname,true);
sstate.new_scanner:=tscannerfile.Create('_Macro_.'+tempname,true);
set_current_scanner(sstate.new_scanner,False);
block_type:=old_block_type;
{ required for e.g. FpcDeepCopy record method (uses "out" parameter; field
names are escaped via &, so should not cause conflicts }
@ -178,8 +180,8 @@ implementation
begin
if sstate.valid then
begin
current_scanner.free;
current_scanner:=sstate.old_scanner;
sstate.new_scanner.free;
set_current_scanner(sstate.old_scanner,false);
current_filepos:=sstate.old_filepos;
token:=sstate.old_token;
current_settings.modeswitches:=sstate.old_modeswitches;