浏览代码

Fix compiler compilation with -dHEAPTRC.
This was brkoken because the -dHEAPTRC option
adds ppheap unit at top of the uses clause in pp.pas source,
which leads to a change in the loading order of the units.
This order change revealed that initialization of fpkg unit
was supposed to happen after globals unit.

Fixed here by testing if initdoneprocs local variable is assigned,
both in register_initdone_proc and in allocinitdoneprocs,
to avoid double initialization.

git-svn-id: trunk@34361 -

pierre 9 年之前
父节点
当前提交
8d1467157c
共有 1 个文件被更改,包括 26 次插入8 次删除
  1. 26 8
      compiler/globals.pas

+ 26 - 8
compiler/globals.pas

@@ -1388,8 +1388,17 @@ implementation
      pinitdoneentry=^tinitdoneentry;
 
 
-   var
-     initdoneprocs : TFPList;
+   const
+     initdoneprocs : TFPList = nil;
+
+
+   procedure allocinitdoneprocs;
+     begin
+       { Avoid double initialization }
+       if assigned(initdoneprocs) then
+         exit;
+       initdoneprocs:=tfplist.create;
+     end;
 
 
    procedure register_initdone_proc(init,done:tprocedure);
@@ -1399,6 +1408,13 @@ implementation
        new(entry);
        entry^.init:=init;
        entry^.done:=done;
+       { Do not rely on the fact that
+         globals unit initialization code
+         has already been executed.
+         Unit initialization order is too
+         uncertian for that. PM }
+       if not assigned(initdoneprocs) then
+         allocinitdoneprocs;
        initdoneprocs.add(entry);
      end;
 
@@ -1407,6 +1423,8 @@ implementation
      var
        i : longint;
      begin
+       if not assigned(initdoneprocs) then
+         exit;
        for i:=0 to initdoneprocs.count-1 do
          with pinitdoneentry(initdoneprocs[i])^ do
            if assigned(init) then
@@ -1418,6 +1436,8 @@ implementation
      var
        i : longint;
      begin
+       if not assigned(initdoneprocs) then
+         exit;
        for i:=0 to initdoneprocs.count-1 do
          with pinitdoneentry(initdoneprocs[i])^ do
            if assigned(done) then
@@ -1425,19 +1445,17 @@ implementation
      end;
 
 
-   procedure allocinitdoneprocs;
-     begin
-       initdoneprocs:=tfplist.create;
-     end;
-
-
    procedure freeinitdoneprocs;
      var
        i : longint;
      begin
+       if not assigned(initdoneprocs) then
+         exit;
        for i:=0 to initdoneprocs.count-1 do
          dispose(pinitdoneentry(initdoneprocs[i]));
        initdoneprocs.free;
+       { Reset variable, to be on the safe side }
+       initdoneprocs:=nil;
      end;