Browse Source

+ symtable.pas, tspecializesymtable.create: SymList and DefList do not need to own the symbols and defs as they are moved to another symtable before the specialize symtable is destroyed (avoids the need to call "extract" on those lists)
* pgenutil.pas, generate_specialization: Correctly change the ownership of extracted symbols and defs by calling ChangeOwner on the symbol/def which does all the magic of changing the owner and adding it to the corresponding list of the given symtable. This fixes Mantis #21550
* Adjusted tw21550.pp so that it enforces the generation of debug information which (as this was the option which caused the above mentioned bug to show)

git-svn-id: trunk@21270 -

svenbarth 13 years ago
parent
commit
810bd7ddab
3 changed files with 19 additions and 6 deletions
  1. 6 6
      compiler/pgenutil.pas
  2. 11 0
      compiler/symtable.pas
  3. 2 0
      tests/webtbs/tw21550.pp

+ 6 - 6
compiler/pgenutil.pas

@@ -494,17 +494,17 @@ uses
             for i:=tempst.SymList.Count-1 downto 0 do
             for i:=tempst.SymList.Count-1 downto 0 do
               begin
               begin
                 item:=tempst.SymList.Items[i];
                 item:=tempst.SymList.Items[i];
-                specializest.SymList.Add(tempst.SymList.NameOfIndex(i),item);
-                tsym(item).Owner:=specializest;
-                tempst.SymList.Extract(item);
+                { using changeowner the symbol is automatically added to the
+                  new symtable }
+                tsym(item).ChangeOwner(specializest);
               end;
               end;
 
 
             for i:=tempst.DefList.Count-1 downto 0 do
             for i:=tempst.DefList.Count-1 downto 0 do
               begin
               begin
                 item:=tempst.DefList.Items[i];
                 item:=tempst.DefList.Items[i];
-                specializest.DefList.Add(item);
-                tdef(item).owner:=specializest;
-                tempst.DefList.Extract(item);
+                { using changeowner the def is automatically added to the new
+                  symtable }
+                tdef(item).ChangeOwner(specializest);
               end;
               end;
 
 
             tempst.free;
             tempst.free;

+ 11 - 0
compiler/symtable.pas

@@ -168,6 +168,7 @@ interface
 
 
        tspecializesymtable = class(tglobalsymtable)
        tspecializesymtable = class(tglobalsymtable)
        public
        public
+          constructor create(const n : string;id:word);
           function iscurrentunit:boolean;override;
           function iscurrentunit:boolean;override;
        end;
        end;
 
 
@@ -1626,6 +1627,16 @@ implementation
                              tspecializesymtable
                              tspecializesymtable
 *****************************************************************************}
 *****************************************************************************}
 
 
+    constructor tspecializesymtable.create(const n : string;id:word);
+      begin
+        inherited create(n,id);
+        { the specialize symtable does not own the syms and defs as they are all
+          moved to a different symtable before the symtable is destroyed; this
+          avoids calls to "extract" }
+        symlist.ownsobjects:=false;
+        deflist.ownsobjects:=false;
+      end;
+
     function tspecializesymtable.iscurrentunit: boolean;
     function tspecializesymtable.iscurrentunit: boolean;
       begin
       begin
         Result := true;
         Result := true;

+ 2 - 0
tests/webtbs/tw21550.pp

@@ -1,3 +1,5 @@
+{%OPT=-gl}
+
 program tw21550;
 program tw21550;
 
 
 {$mode objfpc}
 {$mode objfpc}