[cfe-commits] r42562 - /cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h

Ted Kremenek kremenek at apple.com
Tue Oct 2 17:48:55 PDT 2007


Author: kremenek
Date: Tue Oct  2 19:48:55 2007
New Revision: 42562

URL: http://llvm.org/viewvc/llvm-project?rev=42562&view=rev
Log:
Fixed bug where intrusive_ptr_add_ref and intrusive_ptr_release were
not declared "static inline."

Removed member templates for operator= and copy constructor.  They simply
didn't work as expected.

Fixed reference counting bug when a smart pointer is assigned the
value of another smart pointer that refers to the same address.


Modified:
    cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h

Modified: cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h?rev=42562&r1=42561&r2=42562&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h (original)
+++ cfe/trunk/include/clang/Analysis/Support/IntrusiveSPtr.h Tue Oct  2 19:48:55 2007
@@ -64,11 +64,11 @@
 ///  particular naming was chosen to be compatible with
 ///  boost::intrusive_ptr, which provides similar functionality to
 ///  IntrusiveSPtr.
-void intrusive_ptr_add_ref(clang::RefCounted* p) { p->Retain(); }
+static inline void intrusive_ptr_add_ref(clang::RefCounted* p) { p->Retain(); }
 
 /// intrusive_ptr_release - The complement of intrusive_ptr_add_ref;
 ///  decrements the reference count of a RefCounted object.
-void intrusive_ptr_release(clang::RefCounted* p) { p->Release(); }
+static inline void intrusive_ptr_release(clang::RefCounted* p) { p->Release(); }
 
 namespace clang {
 
@@ -97,14 +97,7 @@
     retain(); 
   }
 
-  template <typename X>
-  IntrusiveSPtr(const IntrusiveSPtr<X>& S) {
-    Obj = static_cast<T*>(const_cast<X*>(S.getPtr()));
-    retain();
-  }
-  
-  template <typename X>
-  IntrusiveSPtr& operator=(const IntrusiveSPtr<X>& S) {
+  IntrusiveSPtr& operator=(const IntrusiveSPtr& S) {
     replace(static_cast<const T*>(S.getPtr()));
     return *this;
   }
@@ -127,7 +120,10 @@
   void retain() { if (Obj) intrusive_ptr_add_ref(Obj); }
   void release() { if (Obj) intrusive_ptr_release(Obj); }
 
-  void replace(const T* o) { 
+  void replace(const T* o) {
+    if (o == Obj)
+      return;
+    
     release();
     Obj = const_cast<T*>(o);
     retain();





More information about the cfe-commits mailing list