فهرست منبع

variable_watch: Match client_data when finding duplicates

If a callback has the same data as another call, we don't want to delete
the old callback. This is because if the client_data is the same, it
might get deleted causing the new client_data to be bogus. Now, AddWatch
will return true if it will use the watch, false otherwise. Callers
should check the return value to know whether client_data was adopted by
the watch or not.
Ben Boeckel 12 سال پیش
والد
کامیت
e43e207c7b
2فایلهای تغییر یافته به همراه7 افزوده شده و 6 حذف شده
  1. 6 5
      Source/cmVariableWatch.cxx
  2. 1 1
      Source/cmVariableWatch.h

+ 6 - 5
Source/cmVariableWatch.cxx

@@ -52,7 +52,7 @@ cmVariableWatch::~cmVariableWatch()
     }
 }
 
-void cmVariableWatch::AddWatch(const std::string& variable,
+bool cmVariableWatch::AddWatch(const std::string& variable,
                                WatchMethod method, void* client_data /*=0*/,
                                DeleteData delete_data /*=0*/)
 {
@@ -65,14 +65,15 @@ void cmVariableWatch::AddWatch(const std::string& variable,
   for ( cc = 0; cc < vp->size(); cc ++ )
     {
     cmVariableWatch::Pair* pair = (*vp)[cc];
-    if ( pair->Method == method )
+    if ( pair->Method == method &&
+         client_data && client_data == pair->ClientData)
       {
-      delete pair;
-      (*vp)[cc] = p;
-      return;
+      // Callback already exists
+      return false;
       }
     }
   vp->push_back(p);
+  return true;
 }
 
 void cmVariableWatch::RemoveWatch(const std::string& variable,

+ 1 - 1
Source/cmVariableWatch.h

@@ -34,7 +34,7 @@ public:
   /**
    * Add watch to the variable
    */
-  void AddWatch(const std::string& variable, WatchMethod method,
+  bool AddWatch(const std::string& variable, WatchMethod method,
                 void* client_data=0, DeleteData delete_data=0);
   void RemoveWatch(const std::string& variable, WatchMethod method);