Browse Source

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

Michaël Van Canneyt 1 year ago
parent
commit
4443e83b75
1 changed files with 5 additions and 3 deletions
  1. 5 3
      compiler/symcreat.pas

+ 5 - 3
compiler/symcreat.pas

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