Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Macro manager infinite loop

(1/3) > >>

oBFusCATed:
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))

--- End code ---

MortenMacFly:

--- Quote from: oBFusCATed on March 05, 2013, 12:35:26 am ---Can I skip it? What other macros should be fixed in a similar fashion?

--- End quote ---
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.

oBFusCATed:

--- Quote from: MortenMacFly on March 08, 2013, 05:28:37 am ---The philosophy for these macros was actually to fix what you get when resolving macros.

--- End quote ---
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?

MortenMacFly:
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.)

oBFusCATed:
Does this currently work?

Navigation

[0] Message Index

[#] Next page

Go to full version