[[[
    JavaHL: Add support for marking object disposed without deleting it,
used by the new Ra JNI code

    [ in subversion/bindings/javahl/native ]

    * SVNBase.cpp, SVNBase.h
      (markDisposed, assertNotDisposed, init): New function to support
tracking disposal state of the object
      (ASSERT_NOT_DISPOSED): New macro for derived object to include in the
beginning of the java call to make sure object has not been disposed
]]]
Index: subversion/bindings/javahl/native/SVNBase.cpp
===================================================================
--- subversion/bindings/javahl/native/SVNBase.cpp       (revision 1328758)
+++ subversion/bindings/javahl/native/SVNBase.cpp       (working copy)
@@ -26,15 +26,24 @@
 
 #include "SVNBase.h"
 #include "JNIUtil.h"
+#include "svn_private_config.h"
 
 SVNBase::SVNBase()
 : pool(JNIUtil::getPool())
 {
+  init();
 }
 
 SVNBase::SVNBase(SVN::Pool & parentPool)
 : pool(parentPool)
 {
+  init();
+}
+
+void
+SVNBase::init()
+{
+  disposed = false;
 }
 
 SVNBase::~SVNBase()
@@ -133,3 +142,21 @@ jobject SVNBase::createCppBoundObject(const char 
*clazzName)
 
   return jself;
 }
+
+void
+SVNBase::markDisposed()
+{
+  disposed = true;
+  pool.clear();
+}
+
+bool
+SVNBase::assertNotDisposed()
+{
+  if(disposed)
+  {
+    JNIUtil::throwError(_("SVNBase object accessed after being disposed"));
+  }
+
+  return disposed;
+}
Index: subversion/bindings/javahl/native/SVNBase.h
===================================================================
--- subversion/bindings/javahl/native/SVNBase.h (revision 1328758)
+++ subversion/bindings/javahl/native/SVNBase.h (working copy)
@@ -91,6 +91,20 @@ class SVNBase
   void disconnectCppObject(jobject jthis, jfieldID *fid, const char 
*className);
 
   /**
+   * Mark this object as disposed and clear the pool.
+   * Used in cases when C++ object resources need to be freed
+   * but association with java object could not be broken as there
+   * jobject wasn't available
+   */
+  void markDisposed();
+
+  /**
+   * Check that object that we are about to use is not disposed.
+   * Otherwise raise JNI exception and return true;
+   */
+  bool assertNotDisposed();
+
+  /**
    * Instantiates java object attached to this base object
    */
   jobject createCppBoundObject(const char *clazzName);
@@ -105,8 +119,26 @@ class SVNBase
   static void findCppAddrFieldID(jfieldID *fid, const char *className,
                                  JNIEnv *env);
 
+  void init();
 protected:
     SVN::Pool pool;
+
+    /**
+     * Indicates whether this object has been disposed.
+     * true - object is disposed and not available for use
+     * false - oject is alive and available for use
+     */
+    bool disposed;
+
 };
 
+#define ASSERT_NOT_DISPOSED(ret_val)    \
+  do                                    \
+  {                                     \
+    if(assertNotDisposed())             \
+    {                                   \
+      return ret_val ;                  \
+    }                                   \
+  } while(0)
+
 #endif // SVNBASE_H

Reply via email to