Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

Macro expansion infinite loop.

<< < (8/11) > >>

ollydbg:

--- Quote from: Huki on March 06, 2015, 10:22:15 am ---...
Can someone confirm whether reverting commit 9933 (i.e., adding back the sanity check) solves the issue?

--- End quote ---
I did it in my pc, and it still hangs on the minimal project by OBF.


--- Quote from: MortenMacFly on March 05, 2015, 05:38:21 am ---Same for me until the changes in trunk were no longer compatible with the branch.
A rebase and merge would help to continue testing.

--- End quote ---
I have rebased in my local git copy, do I need to release all the rebased patches?


--- Quote ---However, what I noticed was that many methods of base classes were missing. That's what the wx replacements were for, for example.

--- End quote ---
I remember wx's macros are handled correctly with my patches. I will test it again.

ollydbg:

--- Quote from: ollydbg on March 07, 2015, 08:00:30 am ---...
I remember wx's macros are handled correctly with my patches. I will test it again.

--- End quote ---
I don't see some thing wrong with a simple wx(wx3.0) project created by wizard. So, I what is exact problem you have?

I did test with my patches on our codeblocks.cbp. I notice one issue, in the file sdk\configmanager.cpp
In the function:

--- Code: ---TiXmlElement* ConfigManager::AssertPath(wxString& path)
{
    Collapse(path);

    wxString illegal(_T(" -:.\"\'$&()[]<>+#")); // our parser will skip to the end of this source file


--- End code ---
It looks like the parser will skip to the end of the file, and comment out of the line don't expose the issue, so I will try to see what is the problem is. I think it is not hard to fix. (Maybe, this bug also exists on our trunk, I haven't tested it yet).

ollydbg:

--- Quote from: ollydbg on March 07, 2015, 08:25:26 am ---...
I notice one issue, in the file sdk\configmanager.cpp
In the function:

--- Code: ---TiXmlElement* ConfigManager::AssertPath(wxString& path)
{
    Collapse(path);

    wxString illegal(_T(" -:.\"\'$&()[]<>+#")); // our parser will skip to the end of this source file


--- End code ---
It looks like the parser will skip to the end of the file, and comment out of the line don't expose the issue, so I will try to see what is the problem is. I think it is not hard to fix. (Maybe, this bug also exists on our trunk, I haven't tested it yet).

--- End quote ---
Here is a test case for our cc which fails in my patch serials.

--- Code: ---#define wxCONCAT_HELPER(text, line) text ## line

#define wxT(x) wxCONCAT_HELPER(L, x)

#define _T(x) wxT(x)

wxString illegal(_T(" -:.\"\'$&()[]<>+#"));

int aaa;


//a //aaa

--- End code ---

EDIT:
I found the reason, it caused by those code when expansion macros:

--- Code: ---    // 5. handling stringizing operator #
    for (int pos = expandedText.Find(_T("#"));
         pos != wxNOT_FOUND;
         pos = expandedText.Find(_T("#")))
    {

--- End code ---
In-fact we should skip the cases that # is inside a literal

ollydbg:
Git patches attached against(rebased on) current svn trunk head.
It also fixes the "#" issue in my previous post. :)


[attachment deleted by admin]

Huki:

--- Quote from: ollydbg on March 07, 2015, 08:00:30 am ---
--- Quote from: Huki on March 06, 2015, 10:22:15 am ---...
Can someone confirm whether reverting commit 9933 (i.e., adding back the sanity check) solves the issue?

--- End quote ---
I did it in my pc, and it still hangs on the minimal project by OBF.
--- End quote ---
You're right, commit 9933 is not related with this issue: it only deals with macros like "#define AAA x+y+AAA".
I tried the obf's minimal project and I can already suggest a fix:
In ReplaceBufferText() we have:

--- Code: ---        if (m_RepeatReplaceCount >= s_MaxRepeatReplaceCount)
        {
            m_TokenIndex = m_BufferLen - m_FirstRemainingLength;
            m_PeekAvailable = false;
            SkipToEOL(false);
            return false;
        }

--- End code ---
Simply change the return to "return true;" and it will fix the problem. It works by skipping (i..e, not parsing) the problem variable "int min;" in the Test struct. If we return false, we stop the current repeat replacement, but later in ParserThread() we will start a new replacement on the same token. :( That's why we get the infinite loop.

It's also a good idea to reset the UndoToken like you did in your original patch. But I am not sure if SkipToEOL() is really required. I suggest a patch like this:

--- Code: ---@@ -1812,13 +1812,18 @@ bool Tokenizer::ReplaceBufferText(const wxString& target)
     if (m_RepeatReplaceCount > 0)
     {
         if (m_RepeatReplaceCount >= s_MaxRepeatReplaceCount)
         {
             m_TokenIndex = m_BufferLen - m_FirstRemainingLength;
+
+            // Reset undo token
+            m_SavedTokenIndex   = m_UndoTokenIndex = m_TokenIndex;
+            m_SavedLineNumber   = m_UndoLineNumber = m_LineNumber;
+            m_SavedNestingLevel = m_UndoNestLevel  = m_NestLevel;
+
             m_PeekAvailable = false;
-            SkipToEOL(false);
-            return false;
+            return true; // NOTE: we have to skip the problem token by returning true.
         }
         else
             ++m_RepeatReplaceCount;
     }
     else  // Set replace parsing state, and save first replace token index

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version