Răsfoiți Sursa

Target copy ctor should copy internal state

Ideally we should never copy cmTarget instances, but it is a pain to
remove current uses of it.  The pimplized portion of cmTarget has mostly
members that cache results, but some are part of the object state.
These should be copied in the copy ctor instead of re-initialized.
Brad King 16 ani în urmă
părinte
comite
02f85f98c6
1 a modificat fișierele cu 9 adăugiri și 3 ștergeri
  1. 9 3
      Source/cmTarget.cxx

+ 9 - 3
Source/cmTarget.cxx

@@ -55,6 +55,12 @@ public:
     {
     {
     this->SourceFileFlagsConstructed = false;
     this->SourceFileFlagsConstructed = false;
     }
     }
+  cmTargetInternals(cmTargetInternals const& r)
+    {
+    // Only some of these entries are part of the object state.
+    // Others not copied here are result caches.
+    this->SourceEntries = r.SourceEntries;
+    }
   typedef cmTarget::SourceFileFlags SourceFileFlags;
   typedef cmTarget::SourceFileFlags SourceFileFlags;
   std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
   std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
   bool SourceFileFlagsConstructed;
   bool SourceFileFlagsConstructed;
@@ -4354,12 +4360,12 @@ cmTargetInternalPointer::cmTargetInternalPointer()
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 cmTargetInternalPointer
 cmTargetInternalPointer
-::cmTargetInternalPointer(cmTargetInternalPointer const&)
+::cmTargetInternalPointer(cmTargetInternalPointer const& r)
 {
 {
   // Ideally cmTarget instances should never be copied.  However until
   // Ideally cmTarget instances should never be copied.  However until
   // we can make a sweep to remove that, this copy constructor avoids
   // we can make a sweep to remove that, this copy constructor avoids
   // allowing the resources (Internals) to be copied.
   // allowing the resources (Internals) to be copied.
-  this->Pointer = new cmTargetInternals;
+  this->Pointer = new cmTargetInternals(*r.Pointer);
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
@@ -4377,7 +4383,7 @@ cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
   // we can make a sweep to remove that, this copy constructor avoids
   // we can make a sweep to remove that, this copy constructor avoids
   // allowing the resources (Internals) to be copied.
   // allowing the resources (Internals) to be copied.
   cmTargetInternals* oldPointer = this->Pointer;
   cmTargetInternals* oldPointer = this->Pointer;
-  this->Pointer = new cmTargetInternals;
+  this->Pointer = new cmTargetInternals(*r.Pointer);
   delete oldPointer;
   delete oldPointer;
   return *this;
   return *this;
 }
 }