Browse Source

Merged revision(s) 32515, 32573, 32575, 32579 from branches/svenbarth/packages:
Report a warning if a unit is used from an indirectly used package. We are doing this only for the units used in contained units though as in the "contains" section there can't be such units anyway (and just checking all loaded units would lead to false positives).

pkgutil.pas:
+ new procedure check_for_indirect_package_usages() which walks a TLinkedList of used units and warns on every unit that is from an indirectly imported package
pmodules.pas, proc_package:
* when checking all loaded units whether they are from a package or not also check for indirect package usages using the new procedure

........
pkgutil.pas, exportprocsym:
* use a temporary variable for the procdef
* restructure the if-expression a bit to make it better readable

........
pmodules.pas, finish_unit:
* also release the generated proc symbol if the init function isn't needed

........
pkgutil.pas, add_package_libs:
* fix exit condition (on Linux it probably worked by accident :/ )
........

git-svn-id: trunk@33518 -

svenbarth 9 years ago
parent
commit
1824a945cf
2 changed files with 41 additions and 9 deletions
  1. 33 7
      compiler/pkgutil.pas
  2. 8 2
      compiler/pmodules.pas

+ 33 - 7
compiler/pkgutil.pas

@@ -27,7 +27,7 @@ unit pkgutil;
 interface
 interface
 
 
   uses
   uses
-    fmodule,fpkg,link,cstreams;
+    fmodule,fpkg,link,cstreams,cclasses;
 
 
   procedure createimportlibfromexternals;
   procedure createimportlibfromexternals;
   Function RewritePPU(const PPUFn:String;OutStream:TCStream):Boolean;
   Function RewritePPU(const PPUFn:String;OutStream:TCStream):Boolean;
@@ -36,13 +36,14 @@ interface
   procedure add_package(const name:string;ignoreduplicates:boolean;direct:boolean);
   procedure add_package(const name:string;ignoreduplicates:boolean;direct:boolean);
   procedure add_package_unit_ref(package:tpackage);
   procedure add_package_unit_ref(package:tpackage);
   procedure add_package_libs(l:tlinker);
   procedure add_package_libs(l:tlinker);
+  procedure check_for_indirect_package_usages(modules:tlinkedlist);
 
 
 implementation
 implementation
 
 
   uses
   uses
     sysutils,
     sysutils,
     globtype,systems,
     globtype,systems,
-    cutils,cclasses,
+    cutils,
     globals,verbose,
     globals,verbose,
     symtype,symconst,symsym,symdef,symbase,symtable,
     symtype,symconst,symsym,symdef,symbase,symtable,
     ppu,entfile,fpcp,
     ppu,entfile,fpcp,
@@ -74,20 +75,22 @@ implementation
     var
     var
       i : longint;
       i : longint;
       item : TCmdStrListItem;
       item : TCmdStrListItem;
+      pd : tprocdef;
     begin
     begin
       for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
       for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
         begin
         begin
-          if not(tprocdef(tprocsym(sym).ProcdefList[i]).proccalloption in [pocall_internproc]) and
-              ((tprocdef(tprocsym(sym).ProcdefList[i]).procoptions*[po_external])=[]) and
+          pd:=tprocdef(tprocsym(sym).procdeflist[i]);
+          if not(pd.proccalloption in [pocall_internproc]) and
+              ((pd.procoptions*[po_external])=[]) and
               (
               (
                 (symtable.symtabletype in [globalsymtable,recordsymtable,objectsymtable]) or
                 (symtable.symtabletype in [globalsymtable,recordsymtable,objectsymtable]) or
                 (
                 (
                   (symtable.symtabletype=staticsymtable) and
                   (symtable.symtabletype=staticsymtable) and
-                  ([po_public,po_has_public_name]*tprocdef(tprocsym(sym).ProcdefList[i]).procoptions<>[])
+                  ([po_public,po_has_public_name]*pd.procoptions<>[])
                 )
                 )
               ) then
               ) then
             begin
             begin
-              exportallprocdefnames(tprocsym(sym),tprocdef(tprocsym(sym).ProcdefList[i]),[]);
+              exportallprocdefnames(tprocsym(sym),pd,[]);
             end;
             end;
         end;
         end;
     end;
     end;
@@ -480,7 +483,8 @@ implementation
       i : longint;
       i : longint;
       pkgname : tpathstr;
       pkgname : tpathstr;
     begin
     begin
-      if not (target_info.system in systems_indirect_var_imports) then
+      if target_info.system in systems_indirect_var_imports then
+        { we're using import libraries anyway }
         exit;
         exit;
       for i:=0 to packagelist.count-1 do
       for i:=0 to packagelist.count-1 do
         begin
         begin
@@ -502,6 +506,28 @@ implementation
     end;
     end;
 
 
 
 
+  procedure check_for_indirect_package_usages(modules:tlinkedlist);
+    var
+      uu : tused_unit;
+      pentry : ppackageentry;
+    begin
+      uu:=tused_unit(modules.first);
+      while assigned(uu) do
+        begin
+          if assigned(uu.u.package) then
+            begin
+              pentry:=ppackageentry(packagelist.find(uu.u.package.packagename^));
+              if not assigned(pentry) then
+                internalerror(2015112304);
+              if not pentry^.direct then
+                Message2(package_w_unit_from_indirect_package,uu.u.realmodulename^,uu.u.package.realpackagename^);
+            end;
+
+          uu:=tused_unit(uu.Next);
+        end;
+    end;
+
+
   procedure createimportlibfromexternals;
   procedure createimportlibfromexternals;
     var
     var
       alreadyloaded : tfpobjectlist;
       alreadyloaded : tfpobjectlist;

+ 8 - 2
compiler/pmodules.pas

@@ -1141,7 +1141,10 @@ type
            begin
            begin
              { first release the not used init procinfo }
              { first release the not used init procinfo }
              if assigned(init_procinfo) then
              if assigned(init_procinfo) then
-               release_main_proc(init_procinfo);
+               begin
+                 release_proc_symbol(init_procinfo.procdef);
+                 release_main_proc(init_procinfo);
+               end;
              init_procinfo:=gen_implicit_initfinal(uf_init,current_module.localsymtable);
              init_procinfo:=gen_implicit_initfinal(uf_init,current_module.localsymtable);
            end;
            end;
          { finalize? }
          { finalize? }
@@ -1725,7 +1728,10 @@ type
                 if (hp<>current_module) then
                 if (hp<>current_module) then
                   begin
                   begin
                     if not assigned(hp.package) then
                     if not assigned(hp.package) then
-                      pkg.addunit(hp)
+                      begin
+                        pkg.addunit(hp);
+                        check_for_indirect_package_usages(hp.used_units);
+                      end
                     else
                     else
                       begin
                       begin
                         pentry:=ppackageentry(packagelist.find(hp.package.packagename^));
                         pentry:=ppackageentry(packagelist.find(hp.package.packagename^));