subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hwri...@apache.org
Subject svn commit: r1023830 - in /subversion/branches/object-model/subversion: bindings/c++/include/Types.h tests/libsvn++/util-test.cpp
Date Mon, 18 Oct 2010 15:05:27 GMT
Author: hwright
Date: Mon Oct 18 15:05:27 2010
New Revision: 1023830

URL: http://svn.apache.org/viewvc?rev=1023830&view=rev
Log:
Index: subversion/bindings/c++/include/Types.h
===================================================================
--- subversion/bindings/c++/include/Types.h	(revision 1023810)
+++ subversion/bindings/c++/include/Types.h	(working copy)
@@ -80,14 +80,15 @@ class CStructWrapper
     inline
     CStructWrapper(const T *data)
     {
-      m_data = new RefCounter<T, DUP>(data);
+      m_data = data ? new RefCounter<T, DUP>(data) : NULL;
     }
 
     inline
     CStructWrapper(const CStructWrapper<T, DUP> &that)
     {
       m_data = that.m_data;
-      m_data->inc_ref();
+      if (m_data)
+        m_data->inc_ref();
     }
 
     inline CStructWrapper<T, DUP>&
@@ -96,27 +97,40 @@ class CStructWrapper
       // Self assignment
       if (&that == this)
         return *this;
-      
-      m_data->dec_ref();
-      if (m_data->refs() == 0)
-        delete m_data;
+     
+      if (m_data)
+        {
+          m_data->dec_ref();
+          if (m_data->refs() == 0)
+            delete m_data;
+        }
+
       m_data = that.m_data;
-      m_data->inc_ref();
+      if (m_data)
+        m_data->inc_ref();
 
       return *this;
     }
 
     inline ~CStructWrapper()
     {
+      if (!m_data)
+        return;
+
       m_data->dec_ref();
       if (m_data->refs() == 0)
         delete m_data;
     }
 
-    inline const T& operator* () const { return *m_data->ptr(); }
-    inline const T* operator-> () const { return m_data->ptr(); }
-    inline operator T const *() const { return m_data->ptr(); }
+    inline const T& operator* () const
+    { return *m_data->ptr(); }
 
+    inline const T* operator-> () const
+    { return m_data ? m_data->ptr() : NULL; }
+
+    inline operator T const *() const
+    { return m_data ? m_data->ptr() : NULL; }
+
   private:
     RefCounter<T, DUP> *m_data;
 };
Index: subversion/tests/libsvn++/util-test.cpp
===================================================================
--- subversion/tests/libsvn++/util-test.cpp	(revision 1023810)
+++ subversion/tests/libsvn++/util-test.cpp	(working copy)
@@ -205,6 +205,12 @@ test_null_objects(apr_pool_t *p)
   if (lock)
     path = lock.getPath();
 
+  Lock l2(lock);
+
+  Lock l3 = l2;
+
+  // To bad we can't do something interesting here and check for a segfault...
+
   return SVN_NO_ERROR;
 }
 

Modified:
    subversion/branches/object-model/subversion/bindings/c++/include/Types.h
    subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp

Modified: subversion/branches/object-model/subversion/bindings/c++/include/Types.h
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Types.h?rev=1023830&r1=1023829&r2=1023830&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Types.h (original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Types.h Mon Oct 18 15:05:27
2010
@@ -80,14 +80,15 @@ class CStructWrapper
     inline
     CStructWrapper(const T *data)
     {
-      m_data = new RefCounter<T, DUP>(data);
+      m_data = data ? new RefCounter<T, DUP>(data) : NULL;
     }
 
     inline
     CStructWrapper(const CStructWrapper<T, DUP> &that)
     {
       m_data = that.m_data;
-      m_data->inc_ref();
+      if (m_data)
+        m_data->inc_ref();
     }
 
     inline CStructWrapper<T, DUP>&
@@ -96,26 +97,39 @@ class CStructWrapper
       // Self assignment
       if (&that == this)
         return *this;
-      
-      m_data->dec_ref();
-      if (m_data->refs() == 0)
-        delete m_data;
+     
+      if (m_data)
+        {
+          m_data->dec_ref();
+          if (m_data->refs() == 0)
+            delete m_data;
+        }
+
       m_data = that.m_data;
-      m_data->inc_ref();
+      if (m_data)
+        m_data->inc_ref();
 
       return *this;
     }
 
     inline ~CStructWrapper()
     {
+      if (!m_data)
+        return;
+
       m_data->dec_ref();
       if (m_data->refs() == 0)
         delete m_data;
     }
 
-    inline const T& operator* () const { return *m_data->ptr(); }
-    inline const T* operator-> () const { return m_data->ptr(); }
-    inline operator T const *() const { return m_data->ptr(); }
+    inline const T& operator* () const
+    { return *m_data->ptr(); }
+
+    inline const T* operator-> () const
+    { return m_data ? m_data->ptr() : NULL; }
+
+    inline operator T const *() const
+    { return m_data ? m_data->ptr() : NULL; }
 
   private:
     RefCounter<T, DUP> *m_data;

Modified: subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/util-test.cpp?rev=1023830&r1=1023829&r2=1023830&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp (original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp Mon Oct 18 15:05:27
2010
@@ -199,12 +199,22 @@ test_struct_wrapping(apr_pool_t *p)
 static svn_error_t *
 test_null_objects(apr_pool_t *p)
 {
+  // This test is in no way comprehensive
+
   Lock lock(NULL);
   std::string path;
 
   if (lock)
     path = lock.getPath();
 
+  Lock l2(lock);
+
+  Lock l3 = l2;
+
+  lock = l2;
+
+  // To bad we can't do something interesting here and check for a segfault...
+
   return SVN_NO_ERROR;
 }
 



Mime
View raw message