subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1566578 - in /subversion/trunk/subversion/bindings/javahl/native: ./ jniwrapper/
Date Mon, 10 Feb 2014 11:01:39 GMT
Author: brane
Date: Mon Feb 10 11:01:38 2014
New Revision: 1566578

URL: http://svn.apache.org/r1566578
Log:
Do not include svn_private_config.h in JavaHL internal headers;
this can cause a mess when compiling without NLS on some platforms.
Specifically, the C++ <string> header might include libintl.h and
then fall afoul of the macro replacements of gettext &Co. from
our private header.

[in subversion/bindings/javahl/native]

* jniwrapper/jni_env.hpp: Do not include svn_private_config.h.
  (Java::Env::error_create_global_reference,
   Java::Env::error_get_contents_string,
   Java::Env::error_release_null_string,
   Java::Env::error_create_object_array,
   Java::Env::error_create_array,
   Java::Env::error_get_contents_array,
   Java::Env::error_release_null_array): New message translation methods.
    Use these wherever _() was formerly used in the header.
* jniwrapper/jni_exception.hpp
  (Java::Exception::throw_java_exception): Move implementation out-of-line.
* jniwrapper/jni_string.hpp
  (Java::String::MutableContents::set_value): Move implementation out-of-line.
* jniwrapper/jni_stack.hpp
  (unknown_cxx_exception_message, caught_java_exception_error):
   New message translation functions. Use these wherever _() was formerly
   used in the header.
* jniwrapper/jni_base.cpp: Include svn_private_config.h.
  (Java::Env::error_create_global_reference,
   Java::Env::error_get_contents_string,
   Java::Env::error_release_null_string,
   Java::Env::error_create_object_array,
   Java::Env::error_create_array,
   Java::Env::error_get_contents_array,
   Java::Env::error_release_null_array,
   Java::String::MutableContents::set_value,
   Java::Exception::throw_java_exception,
   unknown_cxx_exception_message,
   caught_java_exception_error): Implement here.

* jniwrapper/jni_string_map.hpp: Do nto include svn_private_config.h ...
* jniwrapper/jni_string_map.cpp: ... but include it here instead.

* NativeStream.hpp: Do not include svn_private_config.h.
  (JavaHL::NativeInputStream::set_stream,
   JavaHL::NativeOutpuStream::set_stream): Move implementation out-of-line.
* NativeStream.hpp
  (JavaHL::NativeInputStream::set_stream,
   JavaHL::NativeOutpuStream::set_stream): Implement here.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/NativeStream.cpp
    subversion/trunk/subversion/bindings/javahl/native/NativeStream.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_env.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_stack.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp

Modified: subversion/trunk/subversion/bindings/javahl/native/NativeStream.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/NativeStream.cpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/NativeStream.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/NativeStream.cpp Mon Feb 10 11:01:38
2014
@@ -37,6 +37,13 @@ const char* const NativeInputStream::m_c
 
 NativeInputStream::~NativeInputStream() {}
 
+void NativeInputStream::set_stream(svn_stream_t* stream)
+{
+  if (m_stream)
+    throw std::logic_error(_("Native input stream is already bound"));
+  m_stream = stream;
+}
+
 NativeInputStream*
 NativeInputStream::get_self(::Java::Env env, jobject jthis)
 {
@@ -129,6 +136,13 @@ const char* const NativeOutputStream::m_
 
 NativeOutputStream::~NativeOutputStream() {}
 
+void NativeOutputStream::set_stream(svn_stream_t* stream)
+{
+  if (m_stream)
+    throw std::logic_error(_("Native output stream is already bound"));
+  m_stream = stream;
+}
+
 NativeOutputStream*
 NativeOutputStream::get_self(::Java::Env env, jobject jthis)
 {

Modified: subversion/trunk/subversion/bindings/javahl/native/NativeStream.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/NativeStream.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/NativeStream.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/NativeStream.hpp Mon Feb 10 11:01:38
2014
@@ -31,7 +31,6 @@
 #include "SVNBase.h"
 
 #include "svn_io.h"
-#include "svn_private_config.h"
 
 namespace JavaHL {
 
@@ -67,12 +66,7 @@ public:
    * Sets the @a stream that this object will own.
    * Do not call this function if a stream was passed to the constructor.
    */
-  void set_stream(svn_stream_t* stream)
-    {
-      if (m_stream)
-        throw std::logic_error(_("Native input stream is already bound"));
-      m_stream = stream;
-    }
+  void set_stream(svn_stream_t* stream);
 
   /**
    * Create the Java object that binds to this native object.
@@ -167,12 +161,7 @@ public:
    * Sets the @a stream that this object will own.
    * Do not call this function if a stream was passed to the constructor.
    */
-  void set_stream(svn_stream_t* stream)
-    {
-      if (m_stream)
-        throw std::logic_error(_("Native output stream is already bound"));
-      m_stream = stream;
-    }
+  void set_stream(svn_stream_t* stream);
 
   /**
    * Create the Java object that binds to this native object.

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp Mon Feb 10
11:01:38 2014
@@ -35,6 +35,9 @@
 #include "../JNIUtil.h"
 bool initialize_jni_util(JNIEnv *env);
 
+#include "svn_private_config.h"
+
+
 // Global library initializaiton
 
 /**
@@ -92,6 +95,54 @@ void Env::static_init(::JavaVM* jvm)
   m_jvm = jvm;
 }
 
+const char* Env::error_create_global_reference() throw()
+{
+  return _("Could not create global reference");
+}
+
+const char* Env::error_get_contents_string() throw()
+{
+  return _("Could not get contents of Java String");
+}
+
+const char* Env::error_release_null_string() throw()
+{
+  return _("Can not release contents of a null String");
+}
+
+const char* Env::error_create_object_array() throw()
+{
+  return _("Could not create Object array");
+}
+
+namespace {
+// The typed array error messages are always fatal, so allocating the
+// error messages on the heap does not really constitute a memory
+// leak.
+const char* error_printf(const char* fmt, const char* type)
+{
+  const apr_size_t bufsize = 512;
+  char *msg = new char[bufsize];
+  apr_snprintf(msg, bufsize, fmt, type);
+  return msg;
+}
+} // anonymous namespace
+
+const char* Env::error_create_array(const char* type) throw()
+{
+  return error_printf(_("Could not create %sArray"), type);
+}
+
+const char* error_get_contents_array(const char* type) throw()
+{
+  return error_printf(_("Could not get %s array contents"), type);
+}
+
+const char* error_release_null_array(const char* type) throw()
+{
+  return error_printf(_("Can not release contents of a null %sArray"), type);
+}
+
 ::JNIEnv* Env::env_from_jvm()
 {
   if (m_jvm)
@@ -201,9 +252,37 @@ jstring Class::get_name() const
 
 const char* const String::m_class_name = "java/lang/String";
 
+void String::MutableContents::set_value(const char* new_text)
+{
+  if (!m_new_text)
+    throw std::invalid_argument(
+        _("Cannot set String contents to null"));
+  if (m_text)
+    {
+      m_new_text = new_text;
+      m_length = jsize(::std::strlen(new_text));
+    }
+  else
+    throw std::logic_error(
+        _("Cannot change the contents of a null String"));
+}
 
 // class Java::Exception
 
+void Exception::throw_java_exception() const
+{
+  if (instantiated()
+      ? m_env.Throw(throwable())
+      : m_env.ThrowNew(m_class, NULL))
+    throw std::runtime_error(_("Could not throw Java exception"));
+}
+
+void Exception::throw_java_exception(const char* message) const
+{
+  if (m_env.ThrowNew(m_class, message))
+    throw std::runtime_error(_("Could not throw Java exception"));
+}
+
 jstring Exception::get_message() const
 {
   if (instantiated())
@@ -269,4 +348,14 @@ void handle_svn_error(Env env, ::svn_err
   throw SignalExceptionThrown();
 }
 
+const char* unknown_cxx_exception_message() throw()
+{
+  return _("Caught unknown C++ exception");
+}
+
+svn_error_t* caught_java_exception_error(apr_status_t status) throw()
+{
+  return svn_error_create(status, NULL, _("Java exception"));
+}
+
 } // namespace Java

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_env.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_env.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_env.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_env.hpp Mon Feb 10 11:01:38
2014
@@ -28,8 +28,6 @@
 #include <cstdarg>
 #include <stdexcept>
 
-#include "svn_private_config.h"
-
 #ifdef SVN_JAVAHL_DEBUG
 #  ifndef SVN_JAVAHL_JNIWRAPPER_LOG
 #    include <iostream>
@@ -150,8 +148,6 @@ private:
   jfieldID m_fid;
 };
 
-
-
 /**
  * Encapsulation of a JNI environment reference.
  *
@@ -199,7 +195,7 @@ public:
       jobject ret = m_env->NewGlobalRef(obj);
       check_java_exception();
       if (!ret)
-        throw_java_out_of_memory(_("Could not create global reference"));
+        throw_java_out_of_memory(error_create_global_reference());
       return ret;
     }
 
@@ -346,8 +342,7 @@ public:
       const char* text = m_env->GetStringUTFChars(str, is_copy);
       check_java_exception();
       if (!text)
-        throw_java_out_of_memory(
-              _("Could not get contents of Java String"));
+        throw_java_out_of_memory(error_get_contents_string());
       return text;
     }
 
@@ -355,8 +350,7 @@ public:
   void ReleaseStringUTFChars(jstring str, const char* new_text) const
     {
       if (!str)
-        throw std::logic_error(
-              _("Can not release contents of a null String"));
+        throw std::logic_error(error_release_null_string());
       m_env->ReleaseStringUTFChars(str, new_text);
     }
 
@@ -479,7 +473,7 @@ public:
     {
       jobjectArray array = m_env->NewObjectArray(length, cls, init);
       if (!array)
-        throw_java_out_of_memory(_("Could not create Object array"));
+        throw_java_out_of_memory(error_create_object_array());
       return array;
     }
 
@@ -505,7 +499,7 @@ public:
     {                                                                   \
       T##Array array = m_env->New##N##Array(length);                    \
       if (!array)                                                       \
-        throw_java_out_of_memory(_("Could not create "#T" array"));     \
+        throw_java_out_of_memory(error_create_array(#T));               \
       return array;                                                     \
     }                                                                   \
   T* Get##N##ArrayElements(T##Array array, jboolean* is_copy) const     \
@@ -516,15 +510,13 @@ public:
       T* data = m_env->Get##N##ArrayElements(array, is_copy);           \
       check_java_exception();                                           \
       if (!data)                                                        \
-        throw_java_out_of_memory(                                       \
-            _("Could not get "#N" array contents"));                    \
+        throw_java_out_of_memory(error_get_contents_array(#N));         \
       return data;                                                      \
     }                                                                   \
   void Release##N##ArrayElements(T##Array array, T* data, jint mode) const \
     {                                                                   \
       if (!array)                                                       \
-        throw std::logic_error(                                         \
-            _("Can not release contents of a null "#T"Array"));         \
+        throw std::logic_error(error_release_null_array(#T));           \
       m_env->Release##N##ArrayElements(array, data, mode);              \
     }
 
@@ -564,8 +556,19 @@ private:
 
   void throw_java_out_of_memory(const char* message) const;
 
+  // We cannont use svn_private_config.h in a header, so we move the
+  // actual message translations into the implementation file.
+  static const char* error_create_global_reference() throw();
+  static const char* error_get_contents_string() throw();
+  static const char* error_release_null_string() throw();
+
+  static const char* error_create_object_array() throw();
+  static const char* error_create_array(const char* type) throw();
+  static const char* error_get_contents_array(const char* type) throw();
+  static const char* error_release_null_array(const char* type) throw();
+
 public:
-  /* This static initializer must only be called by JNI_OnLoad */
+  // This static initializer must only be called by JNI_OnLoad
   static void static_init(::JavaVM*);
 };
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp Mon Feb
10 11:01:38 2014
@@ -82,13 +82,7 @@ public:
    * It is an error to call this method if an existing @c jthrowable
    * object was wrapped.
    */
-  void throw_java_exception() const
-    {
-      if (instantiated()
-          ? m_env.Throw(throwable())
-          : m_env.ThrowNew(m_class, NULL))
-        throw std::runtime_error(_("Could not throw Java exception"));
-    }
+  void throw_java_exception() const;
 
   /**
    * Raises a Java exception of the concrete class with the given
@@ -97,11 +91,7 @@ public:
    * It is an error to call this method if an existing @c jthrowable
    * object was wrapped.
    */
-  void throw_java_exception(const char* message) const
-    {
-      if (m_env.ThrowNew(m_class, message))
-        throw std::runtime_error(_("Could not throw Java exception"));
-    }
+  void throw_java_exception(const char* message) const;
 
   /**
    * Checks if an existing @c jthrowable object was wrapped.

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_stack.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_stack.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_stack.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_stack.hpp Mon Feb 10
11:01:38 2014
@@ -112,8 +112,8 @@
     }                                                                   \
   catch (...)                                                           \
     {                                                                   \
-      X(::Java::Env(jenv))                                              \
-        .throw_java_exception(_("Caught unknown C++ exception"));       \
+      const char* const msg = Java::unknown_cxx_exception_message();    \
+      X(::Java::Env(jenv)).throw_java_exception(msg);                   \
     }
 
 /**
@@ -161,7 +161,7 @@
   catch (const ::Java::SignalExceptionThrown&)                          \
     {                                                                   \
       SVN_JAVAHL_ASSERT_EXCEPTION_THROWN((E));                          \
-      return svn_error_create((C), NULL, _("Java exception"));          \
+      return Java::caught_java_exception_error((C));                    \
     }                                                                   \
   catch (const ::std::exception& ex)                                    \
     {                                                                   \
@@ -171,7 +171,7 @@
     }                                                                   \
   catch (...)                                                           \
     {                                                                   \
-      const char* const msg = _("Caught unknown C++ exception");        \
+      const char* const msg = Java::unknown_cxx_exception_message();    \
       ::Java::RuntimeException((E)).throw_java_exception(msg);          \
       return svn_error_create((C), NULL, msg);                          \
     }
@@ -201,6 +201,20 @@ namespace Java {
  */
 void handle_svn_error(Env env, svn_error_t* err);
 
+/**
+ * Return a localized error string for an unknown C++ exception.
+ *
+ * @since New in 1.9.
+ */
+const char* unknown_cxx_exception_message() throw();
+
+/**
+ * Create an svn_error_t for a caught Java exception.
+ *
+ * @since New in 1.9.
+ */
+svn_error_t* caught_java_exception_error(apr_status_t status) throw();
+
 } // namespace Java
 
 #endif // SVN_JAVAHL_JNIWRAPPER_STACK_HPP

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string.hpp Mon Feb 10
11:01:38 2014
@@ -196,20 +196,7 @@ public:
      * @throw std::invalid_argument if the @a new_text is @c null
      * @throw std::logic_error if this is a @c null or immutable string
      */
-    void set_value(const char* new_text)
-      {
-        if (!m_new_text)
-          throw std::invalid_argument(
-              _("Cannot set String contents to null"));
-        if (m_text)
-          {
-            m_new_text = new_text;
-            m_length = jsize(::std::strlen(new_text));
-          }
-        else
-          throw std::logic_error(
-              _("Cannot change the contents of a null String"));
-      }
+    void set_value(const char* new_text);
 
   private:
     const char* m_new_text;

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp Mon Feb
10 11:01:38 2014
@@ -26,6 +26,8 @@
 #include "jni_string.hpp"
 #include "jni_string_map.hpp"
 
+#include "svn_private_config.h"
+
 namespace Java {
 
 // Class Java::BaseMap

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp?rev=1566578&r1=1566577&r2=1566578&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp Mon Feb
10 11:01:38 2014
@@ -31,8 +31,6 @@
 #include "jni_env.hpp"
 #include "jni_object.hpp"
 
-#include "svn_private_config.h"
-
 namespace Java {
 
 /**



Mime
View raw message