News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

The 21 June 2016 build (10868) is out.

Started by killerbot, June 21, 2016, 08:46:31 PM

Previous topic - Next topic

Pecan

When a workspace with only one project is closed, then another loaded, it's possible for the newly loaded project to be assigned the same memory address as the closed project.

Thus, any test against the previously loaded projects address will match, and macrosmanager.cpp will not replace the macros for the second project.

Below is the fix. I'll apply after review by other team members.

Index: src/sdk/macrosmanager.cpp
===================================================================
--- src/sdk/macrosmanager.cpp (revision 10889)
+++ src/sdk/macrosmanager.cpp (working copy)
@@ -269,7 +269,7 @@
         m_Macros[_T("MAKEFILE")]             = wxEmptyString;
         m_Macros[_T("ALL_PROJECT_FILES")]    = wxEmptyString;
     }
-    else if (project != m_LastProject)
+    else if ( (project != m_LastProject) or (project->GetTitle() != m_ProjectName) )
     {
         m_LastTarget      = nullptr; // reset last target when project changes
         m_ProjectWxFileName.Assign(project->GetFilename());
@@ -340,7 +340,7 @@
         m_TargetFilename       = wxEmptyString;
         m_LastTarget           = nullptr;
     }
-    else if (target != m_LastTarget)
+    else if ( (target != m_LastTarget) or (target->GetTitle() != m_TargetName) )
     {
         wxFileName tod(target->GetOutputFilename());
         m_TargetOutputDir      = UnixFilename(tod.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
@@ -455,7 +455,8 @@
                 target = project->GetBuildTarget(project->GetActiveBuildTarget());
         }
     }
-    if (project != m_LastProject || target != m_LastTarget || (editor && (editor->GetFilename() != m_ActiveEditorFilename)) )
+    if (project != m_LastProject || target != m_LastTarget || (editor && (editor->GetFilename() != m_ActiveEditorFilename))
+         || (project && (project->GetTitle() != m_ProjectName)) || (target && (target->GetTitle() != m_TargetName)) )
         RecalcVars(project, editor, target);

     wxString search;

blauzahn

What if the checked attributes of the 2 projects are the same? This is quite probable when
you load a different version of the same project (e.g. a backup). Ideally, the
solution does not depend on any attribute at all. Would it make sense to set
m_LastProject to nullptr on close or would that contradict its purpose?

Until then, I welcome an improvement like yours.


Pecan

Quote from: blauzahn on July 26, 2016, 06:37:55 AM
What if the checked attributes of the 2 projects are the same? ...

Good point.
So, we need a unique attribute.

Question: Is it always true that the absolute form of the project filename (.cbp) is unique for all projects?


Pecan

Quote from: blauzahn on July 26, 2016, 06:37:55 AM
What if the checked attributes of the 2 projects are the same?

New patch to assure that the secondary attribute comparison is unique.
Also using the shorter comparisons first as a short circuit to the result.

Index: src/sdk/macrosmanager.cpp
===================================================================
--- src/sdk/macrosmanager.cpp (revision 10889)
+++ src/sdk/macrosmanager.cpp (working copy)
@@ -269,7 +269,10 @@
         m_Macros[_T("MAKEFILE")]             = wxEmptyString;
         m_Macros[_T("ALL_PROJECT_FILES")]    = wxEmptyString;
     }
-    else if (project != m_LastProject)
+    else if ( (project != m_LastProject) || (project->GetTitle() != m_ProjectName)
+                || (UnixFilename(project->GetBasePath()) != m_ProjectDir)
+                || (UnixFilename(project->GetFilename()) != m_ProjectFilename)
+             )
     {
         m_LastTarget      = nullptr; // reset last target when project changes
         m_ProjectWxFileName.Assign(project->GetFilename());
@@ -340,7 +343,7 @@
         m_TargetFilename       = wxEmptyString;
         m_LastTarget           = nullptr;
     }
-    else if (target != m_LastTarget)
+    else if ( (target != m_LastTarget) or (target->GetTitle() != m_TargetName) )
     {
         wxFileName tod(target->GetOutputFilename());
         m_TargetOutputDir      = UnixFilename(tod.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
@@ -455,7 +458,10 @@
                 target = project->GetBuildTarget(project->GetActiveBuildTarget());
         }
     }
-    if (project != m_LastProject || target != m_LastTarget || (editor && (editor->GetFilename() != m_ActiveEditorFilename)) )
+    if ( (project != m_LastProject) || (target != m_LastTarget) || (editor && (editor->GetFilename() != m_ActiveEditorFilename))
+            || (project && (UnixFilename(project->GetBasePath()) != m_ProjectDir))
+            || (project && (UnixFilename(project->GetFilename()) != m_ProjectFilename))
+            || (target && (target->GetTitle() != m_TargetName)) )
         RecalcVars(project, editor, target);

     wxString search;

Oleg_Sam

Thank you for this patch. Now its all work fine!

Pecan

Corrected patch.
Comparison on m_ProjectFilename was incorrect.


Index: src/sdk/macrosmanager.cpp
===================================================================
--- src/sdk/macrosmanager.cpp (revision 10889)
+++ src/sdk/macrosmanager.cpp (working copy)
@@ -269,7 +269,10 @@
         m_Macros[_T("MAKEFILE")]             = wxEmptyString;
         m_Macros[_T("ALL_PROJECT_FILES")]    = wxEmptyString;
     }
-    else if (project != m_LastProject)
+    else if ( (project != m_LastProject) || (project->GetTitle() != m_ProjectName)
+                || (UnixFilename(project->GetBasePath()) != m_ProjectDir)
+                || (UnixFilename(m_ProjectWxFileName.GetFullName()) != m_ProjectFilename)
+             )
     {
         m_LastTarget      = nullptr; // reset last target when project changes
         m_ProjectWxFileName.Assign(project->GetFilename());
@@ -340,7 +343,7 @@
         m_TargetFilename       = wxEmptyString;
         m_LastTarget           = nullptr;
     }
-    else if (target != m_LastTarget)
+    else if ( (target != m_LastTarget) or (target->GetTitle() != m_TargetName) )
     {
         wxFileName tod(target->GetOutputFilename());
         m_TargetOutputDir      = UnixFilename(tod.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
@@ -455,7 +458,10 @@
                 target = project->GetBuildTarget(project->GetActiveBuildTarget());
         }
     }
-    if (project != m_LastProject || target != m_LastTarget || (editor && (editor->GetFilename() != m_ActiveEditorFilename)) )
+    if (project != m_LastProject || target != m_LastTarget || (editor && (editor->GetFilename() != m_ActiveEditorFilename))
+                    || (project && (UnixFilename(project->GetBasePath()) != m_ProjectDir))
+                    || (UnixFilename(m_ProjectWxFileName.GetFullName()) != m_ProjectFilename)
+                    || (target && (target->GetTitle() != m_TargetName)) )
         RecalcVars(project, editor, target);

     wxString search;

oBFusCATed

Why don't you detect project close event and set the m_lastproject to null?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Pecan

#22
Quote from: oBFusCATed on August 02, 2016, 03:56:35 AM
Why don't you detect project close event and set the m_lastproject to null?

cbEvent_Project_Closed is not called during the compilation of a workspace.
The macros have to be reset before compilation of a project in a workspace.

I'll try working with WorkSpaceChanged() event. But macrosmanager get called in so many places outside of events..... the conditions are mind boggling.

oBFusCATed

You can leave the pointer comparison probably, just make sure that the pointer is reset when there is no project loaded. Everything else should probably stay the same.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Pecan

Quote from: oBFusCATed on August 02, 2016, 09:01:37 PM
You can leave the pointer comparison probably, just make sure that the pointer is reset when there is no project loaded. Everything else should probably stay the same.

I have spent hours trapping events, hoping to find one that could be used to reliably reset the old project pointer in macros manager. 

Unfortunately, there is no CB event that can be used to reliably reset the last project pointer to zero when multiple projects exist within a workspace and the user does a full workspace build.

The pointer must be reset between compiles of projects within a workspace as well as project activation, open and close.

The compiler events can be used to reset the pointer just before a compile, but these events are (erroneously) invoked by the CodeCompletion plugin so many times it's a turkey shoot to figure out if it's a CodeCompletion call or a real request for compilation. The current comparisons are less overhead then resetting the project pointer for erroneous compilation events.

Using complilation events would also miss the needed project events reset.

The current patch is the only method I can find to reliably reset the old project pointer for both api macro translation calls (cb core, plugins, scripts, etc) and which catch all events that require macro translation.

I welcome further suggestions.

oBFusCATed

Quote from: Pecan on August 03, 2016, 05:30:04 PM
The current comparisons are less overhead then resetting the project pointer for erroneous compilation events.
I'm concerned about the robustness and not the performance. I'll give it a try hopefully soon.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Andy356

#26
Hi guys,

I just noticed that -std=c11 is not available as a standard compiler flag. It's trivial to enable it in "Other compiler options", or add it as a new flag, but still, it should be a flag provided by default...

Edit: The compiler is GCC 6.1. The man page lists c11 as a valid flag. (Thanks, stahta01)

stahta01

FYI: Compiler flags are per compiler; you should state which compiler is missing the option that needs it.

Quote from: Andy356 on August 11, 2016, 06:18:02 PM
Hi guys,

I just noticed that -std=c11 is not available as a standard compiler flag. It's trivial to enable it in "Other compiler options", or add it as a new flag, but still, it should be a flag provided by default...
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

pcoquill

Hi,
My antivirus (AVG) indicates the presence of a trojan virus in one dll: Inject3.AVPH.
Any information about this ?

Regards, Patrick

Jenna

Quote from: pcoquill on August 24, 2016, 12:51:25 PM
Hi,
My antivirus (AVG) indicates the presence of a trojan virus in one dll: Inject3.AVPH.
Any information about this ?

Regards, Patrick
Most likely a false positive (not the first one).

You should test it on http://virustotal.com .