After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 656694 - getDefs fails to resolve local function names if same global name exist.
getDefs fails to resolve local function names if same global name exist.
Status: RESOLVED OBSOLETE
Product: doxygen
Classification: Other
Component: general
1.8.2-SVN
Other Linux
: Normal major
: ---
Assigned To: Dimitri van Heesch
Dimitri van Heesch
[moved_to_github]
Depends on:
Blocks:
 
 
Reported: 2011-08-16 20:02 UTC by Henrik
Modified: 2018-07-30 10:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
util.cpp getDefs: stop loop if filename matches currentFile (849 bytes, patch)
2011-08-17 21:24 UTC, Henrik
none Details | Review
Resolving duplicated external names in util.cpp/getDefs (11.54 KB, patch)
2011-10-04 17:41 UTC, Henrik
none Details | Review

Description Henrik 2011-08-16 20:02:36 UTC
In case of multiple source files that define and implement same function names, the resolution of the names in util.cpp method getDefs creates a link to the first defined function. This leads to strange call/caller graphs, where links are generated to otherwise unrelated source code.

After _MUCH_ tracing and debugging basically starting from the graph generation and move backwards to the code.l and finally locating the problem code in util.cpp. There is a lot of code in getDefs, (who is the happy coder?), so I might not have covered all situations, but now doxygen generates much better call/caller graphs for me.

The core of the fix is approx line 4090. Stop the loop if the currentFile matches the file name of the member definition:

bool goodMatch=false;
while (md && !goodMatch)
{
  members.append(md);
  if(currentFile&&fd&&currentFile->getPath()==fd->getPath() && currentFile->localName()==fd->localName()) goodMatch=true;
}

Please consider applying or suggest a better fix.

Here is the patch with the debugging code left in.

Index: src/util.cpp
===================================================================
--- src/util.cpp	(revision 772)
+++ src/util.cpp	(working copy)
@@ -3714,7 +3766,7 @@
     FileDef *currentFile,
     bool checkCV
     )
-{
+{ bool debug=false;
   fd=0, md=0, cd=0, nd=0, gd=0;
   if (memberName.isEmpty()) return FALSE; /* empty name => nothing to link */
 
@@ -3733,8 +3785,10 @@
     scopeName=scopeName.left(is); 
     pm=im+2;
   }
-  //printf("result after scope corrections scope=%s name=%s\n",
-  //          scopeName.data(),memberName.data());
+
+  //if(debug)
+  //printf("--- --- util.cpp getDefs: result after scope corrections scope=%s, name=%s, current file %s\n",
+  //          scopeName.data(),memberName.data(),currentFile->localName().data());
 
   QCString mName=memberName;
   QCString mScope;
@@ -3754,7 +3808,7 @@
   //printf("mScope=`%s' mName=`%s'\n",mScope.data(),mName.data());
 
   MemberName *mn = Doxygen::memberNameSDict->find(mName);
-  //printf("mName=%s mn=%p\n",mName.data(),mn);
+  //if(debug) printf("--- --- mName=%s mn=%p\n",mName.data(),mn);
 
   if ((!forceEmptyScope || scopeName.isEmpty()) && // this was changed for bug638856, forceEmptyScope => empty scopeName
       mn && !(scopeName.isEmpty() && mScope.isEmpty()))
@@ -3774,7 +3828,8 @@
       }
 
       ClassDef *fcd=getResolvedClass(Doxygen::globalScope,0,className);
-      //printf("Trying class scope %s: %p\n",className.data(),fcd);
+      if(debug) printf("--- --- Trying class scope %s: isLinkable %i, maxInheritanceDepth %i\n",className.data(),(fcd&&fcd->isLinkable()),maxInheritanceDepth);
+
       // todo: fill in correct fileScope!
       if (fcd &&  // is it a documented class
           fcd->isLinkable() 
@@ -3821,7 +3876,7 @@
         {
           delete argList; argList=0;
         }
-        if (mdist==maxInheritanceDepth && args && strcmp(args,"()")==0)
+        if (mdist==maxInheritanceDepth && args && strcmp(args,"()")==0) // XXX 
           // no exact match found, but if args="()" an arbitrary member will do
         {
           //printf("  >Searching for arbitrary member\n");
@@ -3919,11 +3974,12 @@
 
 
   // maybe an namespace, file or group member ?
+  //if(debug)
   //printf("Testing for global symbol scopeName=`%s' mScope=`%s' :: mName=`%s'\n",
   //              scopeName.data(),mScope.data(),mName.data());
   if ((mn=Doxygen::functionNameSDict->find(mName))) // name is known
   {
-    //printf("  >symbol name found\n");
+    //if(debug) printf("  >symbol name %s found\n",mName.data());
     NamespaceDef *fnd=0;
     int scopeOffset=scopeName.length();
     do
@@ -3943,14 +3999,14 @@
           fnd->isLinkable()
          )
       {
-        //printf("Function inside existing namespace `%s'\n",namespaceName.data());
+        //if(debug) printf("Function inside existing namespace `%s'\n",namespaceName.data());
         bool found=FALSE;
         MemberListIterator mmli(*mn);
         MemberDef *mmd;
         for (mmli.toFirst();((mmd=mmli.current()) && !found);++mmli)
         {
-          //printf("mmd->getNamespaceDef()=%p fnd=%p\n",
-          //    mmd->getNamespaceDef(),fnd);
+          //if(debug) printf("mmd->getNamespaceDef()=%p fnd=%p\n",mmd->getNamespaceDef(),fnd);
+
           if (mmd->getNamespaceDef()==fnd /* && mmd->isLinkable() */ )
           { // namespace is found
             bool match=TRUE;
@@ -3963,7 +4019,7 @@
               match=matchArguments2(
                   mmd->getOuterScope(),mmd->getFileDef(),mmdAl.pointer(),
                   fnd,mmd->getFileDef(),argList,
-                  checkCV); 
+                  checkCV);
             }
             if (match)
             {
@@ -3997,12 +4053,14 @@
           {
             md=0; // avoid returning things we cannot link to
             nd=0;
+            if (debug) printf("--- --a util.cpp getDefs returns FALSE");
             return FALSE; // match found but not linkable
           }
           else
           {
             gd=md->getGroupDef();
             if (gd && gd->isLinkable()) nd=0; else gd=0;
+            if (debug) printf("--- --b util.cpp getDefs returns TRUE");
             return TRUE;
           }
         }
@@ -4031,11 +4089,16 @@
       {
         // no exact match found, but if args="()" an arbitrary 
         // member will do
+    	bool goodMatch=false;
         md=mn->last();
-        while (md /* && md->isLinkable()*/)
+        while (md /* && md->isLinkable()*/ &&!goodMatch)
         {
-          //printf("Found member `%s'\n",md->name().data());
-          //printf("member is linkable md->name()=`%s'\n",md->name().data());
+          if (debug)
+          {
+        	printf("--- *** util.cpp getDefs Found member %s ",md->name().data());
+            printf("member is linkable md->name()=%s ",md->name().data());
+            printf("file=%s\n",md->getFileDef()->localName().data());
+          }
           fd=md->getFileDef();
           gd=md->getGroupDef();
           if (
@@ -4043,6 +4106,7 @@
              )
           {
             members.append(md);
+            if(currentFile&&fd&&currentFile->getPath()==fd->getPath() && currentFile->localName()==fd->localName()) goodMatch=true;
           }
           md=mn->prev();
         }
@@ -4057,6 +4121,7 @@
         fd=md->getFileDef();
         gd=md->getGroupDef();
         //printf("fd=%p gd=%p gd->isLinkable()=%d\n",fd,gd,gd->isLinkable());
+        if (debug) printf("--- --c util.cpp getDefs returns TRUE. File = %s, CurrentFile=%s \n",fd->localName().data(),currentFile->localName().data());
         if (gd && gd->isLinkable()) fd=0; else gd=0;
         return TRUE;
       }
@@ -4064,6 +4129,8 @@
   }
 
   // no nothing found
+  if (debug) printf("--- --d util.cpp getDefs returns FALSE");
+
   return FALSE;
 }
Comment 1 Henrik 2011-08-17 21:24:07 UTC
Created attachment 194085 [details] [review]
util.cpp getDefs: stop loop if filename matches currentFile

This is a patch against latest in SVN with just the change.
Comment 2 Henrik 2011-10-04 17:41:27 UTC
Created attachment 198236 [details] [review]
Resolving duplicated external names in util.cpp/getDefs

This patch implements the following two strategies for resolving duplicated names. First, is the name is defined in current file, use the local name. Secondly try to match the names using the prototype definition.
Comment 3 Henrik 2012-01-11 18:01:46 UTC
Any comments to this patch?
Comment 4 Dimitri van Heesch 2012-11-18 11:08:01 UTC
Changed version 'latest' to '1.8.2-SVN' so I can remove 'latest' as an option as it is a moving target.
Comment 5 André Klapper 2018-07-30 10:10:45 UTC
As discussed in https://github.com/doxygen/doxygen/pull/734 , Doxygen has moved its issue tracking to 

   https://github.com/doxygen/doxygen/issues

All Doxygen tickets in GNOME Bugzilla have been migrated to Github. You can subscribe and participate in the new ticket in Github. You can find the corresponding Github ticket by searching for its Bugzilla ID (number) in Github.

Hence I am closing this GNOME Bugzilla ticket.
Please use the corresponding ticket in Github instead. Thanks a lot!