Author: mturk Date: Sat Apr 18 10:09:16 2009 New Revision: 766286 URL: http://svn.apache.org/viewvc?rev=766286&view=rev Log: Fix return macros for wchar_t != jchar
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/shared/string.c commons/sandbox/runtime/trunk/src/main/native/test/testcase.c commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Sat Apr 18 10:09:16 2009 @@ -117,11 +117,20 @@ if ((V)) return (*_E)->NewStringUTF((_E), (const char *)(V)); \ else return NULL +#if CC_SIZEOF_WCHAR_T == 2 +/* wchat_t matches jchar */ #define RETURN_JWSTR(V) \ if ((V)) return (*_E)->NewString((_E), (const jchar *)(V), \ (jsize)wcslen((V))); \ else return NULL +#else +/* Presume utf32 fits into utf16. + * TODO: Figure out more optimised way of doing this. + */ +#define RETURN_JWSTR(V) ACR_NewJavaStringW(_E, (V)) + +#endif #define ACR_OS_WINDOWS 0x1000 #define ACR_OS_WIN64 0x1001 Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Sat Apr 18 10:09:16 2009 @@ -88,6 +88,12 @@ */ ACR_DECLARE(char *) ACR_GetJavaStringU(JNIEnv *env, jstring s); +/** Convert wchar_t to java string + * @param env Current JNI environment. + * @param s String to convert. + */ +ACR_DECLARE(jstring) ACR_NewJavaStringW(JNIEnv *_E, const wchar_t *s); + #ifdef __cplusplus } #endif Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Sat Apr 18 10:09:16 2009 @@ -52,23 +52,6 @@ /* * --------------------------------------------------------------------- - * begin of POSIX utilities - * --------------------------------------------------------------------- - */ - -struct iovec { - void *iov_base; /* Starting address */ - size_t iov_len; /* Number of bytes */ -}; - -/* - * --------------------------------------------------------------------- - * end of POSIX utilities - * --------------------------------------------------------------------- - */ - -/* - * --------------------------------------------------------------------- * begin of PEB declarations * Copied from http://source.winehq.org * and renamed RTL with ACR @@ -221,6 +204,23 @@ extern "C" { #endif +/* + * --------------------------------------------------------------------- + * begin of POSIX utilities + * --------------------------------------------------------------------- + */ + +struct iovec { + void *iov_base; /* Starting address */ + size_t iov_len; /* Number of bytes */ +}; + +/* + * --------------------------------------------------------------------- + * end of POSIX utilities + * --------------------------------------------------------------------- + */ + #ifndef WSA_NOT_ENOUGHT_MEMORY #define WSA_NOT_ENOUGHT_MEMORY 8 #endif Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sat Apr 18 10:09:16 2009 @@ -188,3 +188,26 @@ CSTR_RELEASE(s); return rv; } + +ACR_DECLARE(jstring) ACR_NewJavaStringW(JNIEnv *_E, const wchar_t *s) +{ + jstring r = NULL; + if (s) { + size_t len = wcslen(s); +#if CC_SIZEOF_WCHAR_T == 2 + r = (*_E)->NewString(_E, (const jchar *)s, len); +#else + jchar *cc; + if ((cc = ACR_Malloc(_E, THROW_FMARK, (len + 1) * sizeof(jchar)))) { + size_t i; + for (i = 0; i < len; i++) { + /* Simply assign utf32 to utf16 */ + cc[i] = (jchar)s[i]; + } + r = (*_E)->NewString(_E, cc, len); + free(cc); + } +#endif + } + return r; +} Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Sat Apr 18 10:09:16 2009 @@ -294,3 +294,8 @@ } return a; } + +ACR_JNI_EXPORT_DECLARE(jstring, TestPrivate, test028)(ACR_JNISTDARGS, int d) +{ + RETURN_JWSTR(L"Hello world"); +} Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=766286&r1=766285&r2=766286&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Sat Apr 18 10:09:16 2009 @@ -72,6 +72,8 @@ private static native int test026(Descriptor p, int i); private static native Descriptor[] test027(int size); + private static native String test028(int d); + protected void setUp() throws Exception @@ -521,5 +523,10 @@ Thread.sleep(200); } - + public void testUtf16String() + throws Throwable + { + String s = test028(0); + assertEquals("Equals", "Hello world", s); + } }