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