Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: oBFusCATed on March 05, 2013, 12:35:26 am

Title: Macro manager infinite loop
Post by: oBFusCATed on March 05, 2013, 12:35:26 am
OK, I've tried to use the $REMOVE_QUOTES{} macro with a variable as argument and C::B entered infinite loop.

To reproduce:
1. create a variable in build options - $TEST="-ftest -ftest2"
2. set compiler -> other options to $REMOVE_QUOTES{$TEST}
3. build

Looking at the code this infinite loop will happen if the argument to $REMOVE_QUOTES isn't quoted.

Here is a patch that fixes both problems, but I wonder if I really need the if statement that checks if the argument starts with '$'.
Can I skip it? What other macros should be fixed in a similar fashion?
@dev: Please comment on the above...
Code
Index: src/sdk/macrosmanager.cpp
===================================================================
--- src/sdk/macrosmanager.cpp   (revision 8898)
+++ src/sdk/macrosmanager.cpp   (working copy)
@@ -490,12 +490,16 @@ void MacrosManager::ReplaceMacros(wxString& buffer, ProjectBuildTarget* target,
     while (m_RE_RemoveQuotes.Matches(buffer))
     {
         search = m_RE_RemoveQuotes.GetMatch(buffer, 0);
-        const wxString content = m_RE_RemoveQuotes.GetMatch(buffer, 1);
+        wxString content = m_RE_RemoveQuotes.GetMatch(buffer, 1).Trim().Trim(false);
+        if (content.StartsWith(wxT("$")))
+            ReplaceMacros(content, target, subrequest);
         if (content.Len()>2 && content.StartsWith(wxT("\"")) && content.EndsWith(wxT("\"")))
         {
             replace = content.Mid(1,content.Len()-2); // with first and last char (the quotes) removed
             buffer.Replace(search, replace, false);
         }
+        else
+            buffer.Replace(search, content, false);
     }

     while (m_RE_Unix.Matches(buffer))
Title: Re: Macro manager infinite loop
Post by: MortenMacFly on March 08, 2013, 05:28:37 am
Can I skip it? What other macros should be fixed in a similar fashion?
the reason for this was that macros sometimes contain quotes while you don't want that, for example path'es in envvars. Assume you want to compile a path list that this can screw the compile argument. So the reason for checking for a $ is to address only such macros. If you believe there is more flexibility and there are use cases also for a more general (not limited to macros) use case, feel free to do.

The philosophy for these macros was actually to fix what you get when resolving macros.
Title: Re: Macro manager infinite loop
Post by: oBFusCATed on March 08, 2013, 09:19:02 am
The philosophy for these macros was actually to fix what you get when resolving macros.
I'm not sure I understand this.

Can you give me example use cases for this macro that you've used or you know are used in the field?

The test case example  $REMOVE_QUOTES{$TEST} is not one of them, because it didn't work.
What should be the result of this expansion $REMOVE_QUOTES{"bla bla $TEST bla bla"}?
I guess we don't want to replace $TEST in there and then remove the quotes from the expanded string?
We just want to remove the quotes, probably, but is this really useful?

Do you have some test cases? If you have can you post them so I can setup some little unit test project for this?
Title: Re: Macro manager infinite loop
Post by: MortenMacFly on March 09, 2013, 01:53:46 pm
I wanted to use path's from windows envvars like %USERPROFILE%. these come with quotes, if the path contains spaces. If you accumulate different path's together you end up in something like:
"$(USERPROFILE)Foo\Bar" -> ""C:\Users\Foo Bar\"Foo\Bar"
...which causes syntax errors for pros-processing tools.
Therefore changing this to:
"$REMOVE_QUOTES{$(USERPROFILE)}Foo\Bar"
...leads to: "C:\Users\Foo Bar\Foo\Bar"
...exactly what you want.

(Maybe it was related to %ProgramFiles%... I don't recall exactly.)
Title: Re: Macro manager infinite loop
Post by: oBFusCATed on March 09, 2013, 06:12:05 pm
Does this currently work?
Title: Re: Macro manager infinite loop
Post by: MortenMacFly on March 09, 2013, 06:26:20 pm
Does this currently work?
Yes - I did it for code at my work as it is needed there and now works this way.
Title: Re: Macro manager infinite loop
Post by: oBFusCATed on March 09, 2013, 06:37:18 pm
Okay, does it still work with my patch? :)
Title: Re: Macro manager infinite loop
Post by: MortenMacFly on March 09, 2013, 07:37:13 pm
Okay, does it still work with my patch? :)
I'll report back... applied it now an re-compiling...
Title: Re: Macro manager infinite loop
Post by: oBFusCATed on March 30, 2013, 03:11:48 pm
In svn...
Title: Re: Macro manager infinite loop
Post by: pr3dicine on April 03, 2013, 07:51:37 pm
would this work with my patch that i have as of now?
Title: Re: Macro manager infinite loop
Post by: MortenMacFly on April 04, 2013, 07:34:14 pm
would this work with my patch that i have as of now?
What patch?