mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
variable_watch: Don't share memory for callbacks
The command itself is owned by the cmMakefile class, but the
cmVariableWatch which holds a pointer to the cmVariableWatchCommand via
the client_data for the callback outlives the cmMakefile class in the Qt
GUI. This means that when the cmMakefile is destroyed, the variable
watch is still in effect, but with a stale pointer.
To fix this, each callback is now a separate entity completely and
doesn't rely on the command which spawned it at all.
An example CMakeLists.txt which demonstrates the issue (only displayed
in cmake-gui, so no tests can be written for it):
set(var 0)
variable_watch(var)
This commit is contained in:
@@ -14,13 +14,6 @@
|
||||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmVariableWatchCommandHandler
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string> VectorOfCommands;
|
||||
VectorOfCommands Commands;
|
||||
};
|
||||
|
||||
/** \class cmVariableWatchCommand
|
||||
* \brief Watch when the variable changes and invoke command
|
||||
*
|
||||
@@ -39,6 +32,9 @@ public:
|
||||
//! Default constructor
|
||||
cmVariableWatchCommand();
|
||||
|
||||
//! Destructor.
|
||||
~cmVariableWatchCommand();
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
* the CMakeLists.txt file.
|
||||
@@ -83,13 +79,8 @@ public:
|
||||
|
||||
cmTypeMacro(cmVariableWatchCommand, cmCommand);
|
||||
|
||||
void VariableAccessed(const std::string& variable, int access_type,
|
||||
const char* newValue, const cmMakefile* mf);
|
||||
|
||||
protected:
|
||||
std::map<std::string, cmVariableWatchCommandHandler> Handlers;
|
||||
|
||||
bool InCallback;
|
||||
std::set<std::string> WatchedVariables;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user