Browse Source

Fix for Mantis #29745.

symdef.pas, getansistringdef:
  * use a temporary, non-defaware symtablestack to create the ansistringdef

+ added test

git-svn-id: trunk@33214 -
svenbarth 9 years ago
parent
commit
27ab1c61c5
3 changed files with 45 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 8 0
      compiler/symdef.pas
  3. 36 0
      tests/webtbs/tw29745.pp

+ 1 - 0
.gitattributes

@@ -14975,6 +14975,7 @@ tests/webtbs/tw29620.pp svneol=native#text/plain
 tests/webtbs/tw2966.pp svneol=native#text/plain
 tests/webtbs/tw29669.pp svneol=native#text/plain
 tests/webtbs/tw29669a.pp svneol=native#text/plain
+tests/webtbs/tw29745.pp svneol=native#text/pascal
 tests/webtbs/tw2975.pp svneol=native#text/plain
 tests/webtbs/tw2976.pp svneol=native#text/plain
 tests/webtbs/tw29792.pp svneol=native#text/pascal

+ 8 - 0
compiler/symdef.pas

@@ -1215,6 +1215,7 @@ implementation
     function getansistringdef:tstringdef;
       var
         symtable:tsymtable;
+        oldstack : tsymtablestack;
       begin
         { if a codepage is explicitly defined in this mudule we need to return
           a replacement for ansistring def }
@@ -1231,9 +1232,16 @@ implementation
                   symtable:=current_module.globalsymtable
                 else
                   symtable:=current_module.localsymtable;
+                { create a temporary stack as it's not good (TM) to mess around
+                  with the order if the unit contains generics or helpers; don't
+                  use a def aware symtablestack though }
+                oldstack:=symtablestack;
+                symtablestack:=tsymtablestack.create;
                 symtablestack.push(symtable);
                 current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage,true);
                 symtablestack.pop(symtable);
+                symtablestack.free;
+                symtablestack:=oldstack;
               end;
             result:=tstringdef(current_module.ansistrdef);
           end

+ 36 - 0
tests/webtbs/tw29745.pp

@@ -0,0 +1,36 @@
+{ %NORUN }
+
+program tw29745;
+
+{$apptype console}
+{$ifdef fpc}
+{$mode objfpc}
+{$h+}
+{$codepage utf8}
+{$endif}
+
+uses Classes;
+
+type
+  TFoo = class helper for TStream
+  public
+    procedure Bar;
+  end;
+
+  procedure TFoo.Bar;
+  begin
+  end;
+
+var
+  s: string = '';
+  m: TStream;
+begin
+  m := TMemoryStream.Create;
+  try
+    m.Bar;
+  finally
+    m.Free;
+  end;
+  writeln(defaultsystemcodepage);
+end.
+