harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r601033 - in /harmony/enhanced/drlvm/trunk/vm: port/include/port_sysencoding.h port/src/misc/linux/sysencoding.c port/src/misc/win/sysencoding.c vmcore/src/class_support/classloader.cpp vmcore/src/exception/exceptions_impl.cpp
Date Tue, 04 Dec 2007 18:46:23 GMT
Author: gshimansky
Date: Tue Dec  4 10:46:22 2007
New Revision: 601033

URL: http://svn.apache.org/viewvc?rev=601033&view=rev
Log:
Fixed HARMONY-5225
It is necessary to convert wide char message from windows to UTF8 to create an exception object
Also fixed exceptions code when an exception object cannot be created


Added:
    harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h   (with props)
    harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c   (with props)
    harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_impl.cpp

Added: harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h?rev=601033&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h Tue Dec  4 10:46:22 2007
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#ifndef _PORT_SYSENCODING_H_
+#define _PORT_SYSENCODING_H_
+
+/**
+ * @defgroup port_sysencoding Convert system messages to UTF8
+ * @ingroup port_apr
+ * @{
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Returns the length of buffer needed to hold NULL terminated UTF8
+ * string converted from system encoded message.
+ *
+ * @param system_message - pointer to NULL terminated string in system encoding
+ * @return - number of bytes needed to hold the converted string including final
+ * zero byte
+ */
+int port_get_utf8_converted_system_message_length(char *system_message);
+
+/**
+ * Converts system message from system encoding to UTF8
+ *
+ * @param[out] converted_message - pointer to buffer to hold converted message
+ * @param buffer_size - number of bytes in the converted_message buffer
+ * @param system_message - pointer to NULL terminated string in system encoding
+ */
+void port_convert_system_error_message_to_utf8(char *converted_message,
+    int buffer_size,
+    char *system_message);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _PORT_SYSENCODING_H_

Propchange: harmony/enhanced/drlvm/trunk/vm/port/include/port_sysencoding.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c?rev=601033&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c (added)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c Tue Dec  4 10:46:22
2007
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include "port_sysencoding.h"
+#include <string.h>
+
+int port_get_utf8_converted_system_message_length(char *system_message)
+{
+    return strlen(system_message) + 1;
+}
+
+void port_convert_system_error_message_to_utf8(char *converted_message,
+    int buffer_size,
+    char *system_message)
+{
+    strncpy(converted_message, system_message, buffer_size - 1);
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysencoding.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c?rev=601033&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c (added)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c Tue Dec  4 10:46:22 2007
@@ -0,0 +1,33 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include "port_sysencoding.h"
+#include <windows.h>
+
+int port_get_utf8_converted_system_message_length(char *system_message)
+{
+    return WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)system_message,
+        -1, NULL, 0, NULL, NULL);
+}
+
+void port_convert_system_error_message_to_utf8(char *converted_message,
+    int buffer_size,
+    char *system_message)
+{
+    WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)system_message, -1,
+        (LPSTR)converted_message, buffer_size, NULL, NULL);
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysencoding.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp?rev=601033&r1=601032&r2=601033&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Tue Dec  4 10:46:22
2007
@@ -52,6 +52,8 @@
 #include "jni_utils.h"
 #include "mem_alloc.h"
 
+#include "port_sysencoding.h"
+
 unsigned ClassLoader::m_capacity = 0;
 unsigned ClassLoader::m_unloadedBytes = 0;
 unsigned ClassLoader::m_nextEntry = 0;
@@ -1025,10 +1027,10 @@
     if( !handle || !just_loaded ) {
         // create error message
         char apr_error_message[1024];
-        natives_describe_error(status, apr_error_message, 
+        natives_describe_error(status, apr_error_message,
                 sizeof(apr_error_message));
 
-        std::stringstream message_stream;
+        std::stringstream UNREF message_stream;
         message_stream << "Failed loading library \"" << lib_name->bytes <<
"\": " 
                 << apr_error_message;
 
@@ -1036,11 +1038,21 @@
         TRACE2("classloader.native", "Loader (" << this << ") native library:
"
             << message_stream.str().c_str());
 
+        int converted_buffer_size =
+            port_get_utf8_converted_system_message_length(apr_error_message);
+        char *converted_error_message = (char *)STD_ALLOCA(converted_buffer_size);
+        port_convert_system_error_message_to_utf8(converted_error_message,
+            converted_buffer_size, apr_error_message);
+
+        std::stringstream converted_message_stream;
+        converted_message_stream << "Failed loading library \"" <<
+            lib_name->bytes << "\": " << converted_error_message;
+
         // unlock class loader
         cl_lock.ForceUnlock();
 
         // report exception
-        ReportException("java/lang/UnsatisfiedLinkError", message_stream);
+        ReportException("java/lang/UnsatisfiedLinkError", converted_message_stream);
         return;
     }
 
@@ -1937,7 +1949,11 @@
 {
     // raise exception
     jthrowable exn = exn_create(exn_name, message_stream.str().c_str());
-    exn_raise_object(exn);
+    if (exn)
+        exn_raise_object(exn);
+    else
+        // Exception could have failed to be created, e.g. because of OOME
+        assert(exn_raised());
 }
 
 void BootstrapClassLoader::ReportException(const char* exn_name, std::stringstream& message_stream)

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_impl.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_impl.cpp?rev=601033&r1=601032&r2=601033&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_impl.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_impl.cpp Tue Dec  4 10:46:22
2007
@@ -145,6 +145,7 @@
 
     if (!arg_obj) {
         exn_raise_object(VM_Global_State::loader_env->java_lang_OutOfMemoryError);
+        tmn_suspend_enable();
         return NULL;
     }
     jobject arg = oh_allocate_local_handle();



Mime
View raw message