Author Topic: CodeBlocks cash when "Find declaration " on some symbol  (Read 20912 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #15 on: February 23, 2011, 12:51:38 pm »
Instead of all this copying (not sure how wxStringTokenizer is implemented though... :oops:)?
I'm not sure whether Tokenizer will depend on the wxString, so I just do a copy to avoid the risk :).

Quote
And what about the commented stuff? You change functionality here... was that on purpose (what about side-effects)?
Yes, I do change the functionality, but I'm not sure why we care about "local" characters of a token.

So, my patch is only a "candidate to avoid crash". :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #16 on: February 23, 2011, 12:53:32 pm »
I'm not sure whether Tokenizer will depend on the wxString, so I just do a copy to avoid the risk :).
Checking the sources revealed a copy is made internally. So you don't need to do this. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #17 on: February 27, 2011, 03:57:25 am »
the code snippet:
Code
        if (!token->m_IsLocal) // global symbols are linked once
        {
            //Manager::Get()->GetMessageManager()->DebugLog("Removing ancestor string from %s", token->m_Name.c_str(), token->m_Name.c_str());
            token->m_AncestorsString.Clear();
        }
was added in rev 1711 by rick22 with the log:

Quote
rickg22  2006-1-11 15:19:20            
Revamped the CodeCompletion plugin, Stage 1. Reparsing after saving files is much faster now. Also, the code completion functionality is much faster due to the searchtree structure.
Known issues: The Class browser is NOT updated when using the cache. WARNING: Might cause crashes if you have the cache enabled. Please disable it.

I'm not sure why a token with m_IsLocal==true does NOT allowed to remove the m_AncestorsString. But currently rick is not maintain the CC's code, So I guess he nearly forget something. I'll PM him about this.

From my point of view, there is no reason we should keep the ancestorstring if we already use it to calculate the hierarchy. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #18 on: February 27, 2011, 06:58:22 am »
see the source code:

Code
void TokensTree::RecalcData()
{
#if CC_TOKEN_DEBUG_OUTPUT
    wxStopWatch sw;
#endif

    TRACE(_T("RecalcData() : Calculating full inheritance tree."));
    // first loop to convert ancestors string to token indices for each token
    for (size_t i = 0; i < size(); ++i)
    {
        Token* token = at(i);
        if (!token)
            continue;

        if (!(token->m_TokenKind & (tkClass | tkTypedef | tkEnum | tkNamespace)))
            continue;
        if (token->m_AncestorsString.IsEmpty())
            continue;
        // only local symbols might change inheritance
//        if (!token->m_IsLocal)
//            continue;



the last two line was comment out in rev 2855 by mandrav.

Note: currently, the function RecalcData() is not used in CC. we use a new method to dynamically call the hierarchy. which is:

Code
class A :public B,C{};
class D :public B,C{};
class C :public X{};

Once the parser finish parsing, then, A's ancestorString is "B,C", D's ancestorString is "B,C", and C's ancestorString is "X".
Now, every thing is OK, we do not call RecalcData(). What's RecalcData() does can divided to two stages:

1, transform the ancestorString to ancestor Idx on evey tokens of the tree. so, A's ancestorIdx will have index to Token B, and index C
   D's ancestorIdx will have index to Token B, and index C ; D's ancestorIdx will have index to Token X. no further hierarchy is calculated.    meanwhile, all the ancestorString will be cleared.(as they were transform to Idxs)

2, calculate the full hierarchy, which means a recursive function call:
   A's ancestorIdx will have index to Token B, Token C and Token X.  (Token X added by calculate the hierarchy)
   D's ancestorIdx will have index to Token B, and Token C and Token X. (Token X added by calculate the hierarchy)
   C's ancestorIdx will have index to Token X. (the same as stage 1)

The currently way we use was "calculate the fully hierarchy on the Tokens we would like to use". which means if we want to query information of Token A, we only calculate the "stage 1 and stage 2" on the exact token A.


BTW:
This thread was suggested to move to CC's sub forum to record such info. :D


  


« Last Edit: February 27, 2011, 07:15:12 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #19 on: February 27, 2011, 07:28:20 am »
patch v2.
Code
Index: token.cpp
===================================================================
--- token.cpp (revision 7028)
+++ token.cpp (working copy)
@@ -1039,8 +1039,12 @@
 
     TRACE(_T("RecalcInheritanceChain() : Token %s, Ancestors %s"), token->m_Name.wx_str(),
           token->m_AncestorsString.wx_str());
-
     wxStringTokenizer tkz(token->m_AncestorsString, _T(","));
+
+    TRACE(_T("RecalcInheritanceChain() : Removing ancestor string from %s"), token->m_Name.wx_str());
+    token->m_AncestorsString.Clear();
+
+
     while (tkz.HasMoreTokens())
     {
         wxString ancestor = tkz.GetNextToken();
@@ -1111,11 +1115,6 @@
 
         token->m_DirectAncestors = token->m_Ancestors;
 
-        if (!token->m_IsLocal) // global symbols are linked once
-        {
-            TRACE(_T("RecalcInheritanceChain() : Removing ancestor string from %s"), token->m_Name.wx_str());
-            token->m_AncestorsString.Clear();
-        }
     }
 
 #if CC_TOKEN_DEBUG_OUTPUT

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #20 on: February 27, 2011, 07:35:48 am »
@loaden:
I think the way you use in rev 6306 is still accepted if we can avoid the crash on calculating the class/namespace hierarchy. :D
http://forums.codeblocks.org/index.php/topic,14167.msg95899.html#msg95899
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #21 on: February 27, 2011, 09:00:00 am »
thanks for your work. Will this patch apply on next nightly build?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #22 on: February 27, 2011, 12:17:44 pm »
I'm not sure why a token with m_IsLocal==true does NOT allowed to remove the m_AncestorsString. But currently rick is not maintain the CC's code, So I guess he nearly forget something. I'll PM him about this.
he replied that he can't not remember that. :(

thanks for your work. Will this patch apply on next nightly build?
depend on devs (mostly, Morten or Loaden). :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #23 on: May 24, 2011, 04:22:09 am »
thanks for your work. Will this patch apply on next nightly build?
FYI:
Hi, nanyu, the revision 7157 has this fixed. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nanyu

  • Almost regular
  • **
  • Posts: 188
  • nanyu
Re: CodeBlocks cash when "Find declaration " on some symbol
« Reply #24 on: June 06, 2011, 04:54:16 pm »
thanks for your work. Will this patch apply on next nightly build?
FYI:
Hi, nanyu, the revision 7157 has this fixed. :D
thk for your work.