You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/10/21 08:38:55 UTC
svn commit: r1534037 - in /subversion/trunk/subversion:
bindings/javahl/native/JNIUtil.cpp include/private/svn_subr_private.h
libsvn_subr/win32_xlate.c libsvn_subr/win32_xlate.h
Author: brane
Date: Mon Oct 21 06:38:54 2013
New Revision: 1534037
URL: http://svn.apache.org/r1534037
Log:
Add a Windows-specific conversion function from UTF-18 to UTF-8.
Use it in JNIUtil.cpp instead of the APR internal function.
* subversion/libsvn_subr/win32_xlate.h
(svn_subr__win32_utf8_to_utf16): Declaration moved from here to ...
* subversion/include/private/svn_subr_private.h
(svn_subr__win32_utf8_to_utf16): ... here.
(svn_subr__win32_utf16_to_utf8): New prototype.
* subversion/libsvn_subr/win32_xlate.c
(svn_subr__win32_utf8_to_utf16): Calculate the length of the source
string only once, and null-terminate it just before returning it.
(svn_subr__win32_utf16_to_utf8): Implement here.
* subversion/bindings/javahl/native/JNIUtil.cpp: Do not include the private
APR header arch/win32/apr_arch_utf8.h.
(JNIUtil::JNIGlobalInit): Use svn_subr__win32_utf16_to_utf8.
Modified:
subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
subversion/trunk/subversion/include/private/svn_subr_private.h
subversion/trunk/subversion/libsvn_subr/win32_xlate.c
subversion/trunk/subversion/libsvn_subr/win32_xlate.h
Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1534037&r1=1534036&r2=1534037&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp Mon Oct 21 06:38:54 2013
@@ -55,15 +55,6 @@
#include "svn_cache_config.h"
#include "private/svn_atomic.h"
#include "svn_private_config.h"
-#ifdef WIN32
-/* FIXME: We're using an internal APR header here, which means we
- have to build Subversion with APR sources. This being Win32-only,
- that should be fine for now, but a better solution must be found in
- combination with issue #850. */
-extern "C" {
-#include <arch/win32/apr_arch_utf8.h>
-};
-#endif
#include "SVNBase.h"
#include "JNIMutex.h"
@@ -314,30 +305,22 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
WCHAR ucs2_path[MAX_PATH];
char *utf8_path;
const char *internal_path;
- apr_pool_t *pool;
- apr_status_t apr_err;
- apr_size_t inwords, outbytes;
- unsigned int outlength;
+ svn_error_t *err;
+ apr_pool_t *pool = svn_pool_create(g_pool);
- pool = svn_pool_create(g_pool);
/* get dll name - our locale info will be in '../share/locale' */
- inwords = sizeof(ucs2_path) / sizeof(ucs2_path[0]);
HINSTANCE moduleHandle = GetModuleHandle("libsvnjavahl-1");
- GetModuleFileNameW(moduleHandle, ucs2_path, inwords);
- inwords = lstrlenW(ucs2_path);
- outbytes = outlength = 3 * (inwords + 1);
- utf8_path = reinterpret_cast<char *>(apr_palloc(pool, outlength));
- apr_err = apr_conv_ucs2_to_utf8((const apr_wchar_t *) ucs2_path,
- &inwords, utf8_path, &outbytes);
- if (!apr_err && (inwords > 0 || outbytes == 0))
- apr_err = APR_INCOMPLETE;
- if (apr_err)
+ GetModuleFileNameW(moduleHandle, ucs2_path,
+ sizeof(ucs2_path) / sizeof(ucs2_path[0]));
+ err = svn_subr__win32_utf16_to_utf8(&utf8_path, ucs2_path, pool);
+ if (err)
{
if (stderr)
- fprintf(stderr, "Can't convert module path to UTF-8");
- return FALSE;
+ svn_handle_error2(err, stderr, false, "svn: ");
+ svn_error_clear(err);
+ return false;
}
- utf8_path[outlength - outbytes] = '\0';
+
internal_path = svn_dirent_internal_style(utf8_path, pool);
/* get base path name */
internal_path = svn_dirent_dirname(internal_path, pool);
Modified: subversion/trunk/subversion/include/private/svn_subr_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_subr_private.h?rev=1534037&r1=1534036&r2=1534037&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_subr_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_subr_private.h Mon Oct 21 06:38:54 2013
@@ -474,6 +474,27 @@ void svn_config__set_read_only(svn_confi
/** @} */
+#if defined(WIN32) || defined(DOXYGEN)
+/**
+ * @defgroup svn_win32_private Private Windows-specific API
+ * @{
+ */
+
+/* On Windows: Convert the UTF-8 string SRC to UTF-16. */
+svn_error_t *
+svn_subr__win32_utf8_to_utf16(const WCHAR **result,
+ const char *src,
+ apr_pool_t *result_pool);
+
+/* On Windows: Convert the UTF-18 string SRC to UTF-8. */
+svn_error_t *
+svn_subr__win32_utf16_to_utf8(const char **result,
+ const WCHAR *src,
+ apr_pool_t *result_pool);
+
+/** @} */
+#endif /* WIN32 || DOXYGEN*/
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Modified: subversion/trunk/subversion/libsvn_subr/win32_xlate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/win32_xlate.c?rev=1534037&r1=1534036&r2=1534037&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/win32_xlate.c (original)
+++ subversion/trunk/subversion/libsvn_subr/win32_xlate.c Mon Oct 21 06:38:54 2013
@@ -47,6 +47,7 @@ typedef int win32_xlate__dummy;
#include "svn_string.h"
#include "svn_utf.h"
#include "private/svn_atomic.h"
+#include "private/svn_subr_private.h"
#include "win32_xlate.h"
@@ -242,10 +243,11 @@ svn_subr__win32_utf8_to_utf16(const WCHA
const char *src,
apr_pool_t *result_pool)
{
- WCHAR * wide_str;
+ WCHAR *wide_str;
int retval, wide_count;
+ const int utf8_count = strlen(src);
- retval = MultiByteToWideChar(CP_UTF8, 0, src, -1, NULL, 0);
+ retval = MultiByteToWideChar(CP_UTF8, 0, src, utf8_count, NULL, 0);
if (retval == 0)
return svn_error_wrap_apr(apr_get_os_error(),
@@ -253,18 +255,50 @@ svn_subr__win32_utf8_to_utf16(const WCHA
wide_count = retval + 1;
wide_str = apr_palloc(result_pool, wide_count * sizeof(WCHAR));
- wide_str[wide_count] = 0;
- retval = MultiByteToWideChar(CP_UTF8, 0, src, -1, wide_str, wide_count);
+ retval = MultiByteToWideChar(CP_UTF8, 0, src, utf8_count,
+ wide_str, wide_count);
if (retval == 0)
return svn_error_wrap_apr(apr_get_os_error(),
_("Conversion to UTF-16 failed"));
+ wide_str[wide_count] = 0;
*result = wide_str;
return SVN_NO_ERROR;
}
+svn_error_t *
+svn_subr__win32_utf16_to_utf8(const char **result,
+ const WCHAR *src,
+ apr_pool_t *result_pool)
+{
+ char *utf8_str;
+ int retval, utf8_count;
+ const int wide_count = lstrlenW(src);
+
+ retval = WideCharToMultiByte(CP_UTF8, 0, src, wide_count,
+ NULL, 0, NULL, FALSE);
+
+ if (retval == 0)
+ return svn_error_wrap_apr(apr_get_os_error(),
+ _("Conversion to UTF-16 failed"));
+
+ utf8_count = retval + 1;
+ utf8_str = apr_palloc(result_pool, utf8_count * sizeof(WCHAR));
+
+ retval = WideCharToMultiByte(CP_UTF8, 0, src, wide_count,
+ utf8_str, utf8_count, NULL, FALSE);
+
+ if (retval == 0)
+ return svn_error_wrap_apr(apr_get_os_error(),
+ _("Conversion from UTF-16 failed"));
+
+ utf8_str[utf8_count] = 0;
+ *result = utf8_str;
+
+ return SVN_NO_ERROR;
+}
#endif /* WIN32 */
Modified: subversion/trunk/subversion/libsvn_subr/win32_xlate.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/win32_xlate.h?rev=1534037&r1=1534036&r2=1534037&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/win32_xlate.h (original)
+++ subversion/trunk/subversion/libsvn_subr/win32_xlate.h Mon Oct 21 06:38:54 2013
@@ -47,12 +47,6 @@ apr_status_t svn_subr__win32_xlate_to_st
svn_stringbuf_t **dest,
apr_pool_t *pool);
-/* On Windows: Convert the utf-8 string SRC to utf-16/ucs2. */
-svn_error_t *
-svn_subr__win32_utf8_to_utf16(const WCHAR **result,
- const char *src,
- apr_pool_t *result_pool);
-
#endif /* WIN32 */
#endif /* SVN_LIBSVN_SUBR_WIN32_XLATE_H */