subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1499026 - in /subversion/trunk/subversion/bindings/javahl/native: CreateJ.cpp CreateJ.h JNIUtil.cpp JNIUtil.h
Date Tue, 02 Jul 2013 17:19:30 GMT
Author: brane
Date: Tue Jul  2 17:19:30 2013
New Revision: 1499026

URL: http://svn.apache.org/r1499026
Log:
Add some infrastructure bits to JavaHL.

[in subversion/bindings/javahl/native]
* CreateJ.h, CreateJ.cpp (CreateJ::StringSet): Make argument const*.
* JNIUtil.h (JNIUtil::checkJavaException): Declare new helper.
  (SVN_JNI_CATCH) New; converts Java exceptions to svn_error_t*.
  JNIUtil.cpp (exception_to_cstring): New helper; hoist logic out of
   JNIUtil::thrownExceptionToCString.
  (JNIUtil::thrownExceptionToCString): Just call exception_to_cstring.
  (JNIUtil::checkJavaException): Implement.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
    subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
    subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/trunk/subversion/bindings/javahl/native/JNIUtil.h

Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp?rev=1499026&r1=1499025&r2=1499026&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.cpp Tue Jul  2 17:19:30 2013
@@ -1124,7 +1124,7 @@ CreateJ::RevisionRangeList(svn_rangelist
 }
 
 jobject
-CreateJ::StringSet(apr_array_header_t *strings)
+CreateJ::StringSet(const apr_array_header_t *strings)
 {
   std::vector<jobject> jstrs;
 

Modified: subversion/trunk/subversion/bindings/javahl/native/CreateJ.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/CreateJ.h?rev=1499026&r1=1499025&r2=1499026&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/CreateJ.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/CreateJ.h Tue Jul  2 17:19:30 2013
@@ -84,7 +84,7 @@ class CreateJ
   RevisionRangeList(svn_rangelist_t *ranges);
 
   static jobject
-  StringSet(apr_array_header_t *strings);
+  StringSet(const apr_array_header_t *strings);
 
   static jobject
   PropertyMap(apr_hash_t *prop_hash);

Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1499026&r1=1499025&r2=1499026&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp Tue Jul  2 17:19:30 2013
@@ -705,11 +705,11 @@ bool JNIUtil::isJavaExceptionThrown()
   return false;
 }
 
-const char *
-JNIUtil::thrownExceptionToCString(SVN::Pool &in_pool)
+namespace {
+const char* exception_to_cstring(apr_pool_t* pool)
 {
   const char *msg;
-  JNIEnv *env = getEnv();
+  JNIEnv *env = JNIUtil::getEnv();
   if (env->ExceptionCheck())
     {
       jthrowable t = env->ExceptionOccurred();
@@ -718,12 +718,12 @@ JNIUtil::thrownExceptionToCString(SVN::P
         {
           jclass clazz = env->FindClass("java/lang/Throwable");
           getMessage = env->GetMethodID(clazz, "getMessage",
-                                        "(V)Ljava/lang/String;");
+                                        "()Ljava/lang/String;");
           env->DeleteLocalRef(clazz);
         }
       jstring jmsg = (jstring) env->CallObjectMethod(t, getMessage);
       JNIStringHolder tmp(jmsg);
-      msg = tmp.pstrdup(in_pool.getPool());
+      msg = tmp.pstrdup(pool);
       // ### Conditionally add t.printStackTrace() to msg?
     }
   else
@@ -732,6 +732,24 @@ JNIUtil::thrownExceptionToCString(SVN::P
     }
   return msg;
 }
+} // anonymous namespace
+
+const char *
+JNIUtil::thrownExceptionToCString(SVN::Pool &in_pool)
+{
+  return exception_to_cstring(in_pool.getPool());
+}
+
+svn_error_t*
+JNIUtil::checkJavaException(apr_status_t errorcode)
+{
+  if (!getEnv()->ExceptionCheck())
+    return SVN_NO_ERROR;
+  svn_error_t* err = svn_error_create(errorcode, NULL, NULL);
+  err->message = apr_psprintf(err->pool, _("Java exception: %s"),
+                              exception_to_cstring(err->pool));
+  return err;
+}
 
 /**
  * Create a Java string from a native UTF-8 string.

Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.h?rev=1499026&r1=1499025&r2=1499026&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.h Tue Jul  2 17:19:30 2013
@@ -40,6 +40,8 @@ class SVNBase;
 #include <vector>
 struct svn_error_t;
 
+#include "svn_error.h"
+
 #define JAVA_PACKAGE "org/apache/subversion/javahl"
 
 struct svn_string_t;
@@ -109,6 +111,12 @@ class JNIUtil
   static const char *thrownExceptionToCString(SVN::Pool &in_pool);
 
   /**
+   * Check if a Java exception was thrown and convert it to a
+   * Subversion error, using @a errorcode as the generic error code.
+   */
+  static svn_error_t* checkJavaException(apr_status_t errorcode);
+
+  /**
    * Throw a Java exception corresponding to err, and run
    * svn_error_clear() on err.
    */
@@ -301,4 +309,10 @@ class JNIUtil
     }                                                   \
   } while (0)
 
+#define SVN_JNI_CATCH(statement, errorcode)             \
+  do {                                                  \
+    do { statement; } while(0);                         \
+    SVN_ERR(JNIUtil::checkJavaException((errorcode)));  \
+  } while(0)
+
 #endif  // JNIUTIL_H



Mime
View raw message