Hi guys, A new patch is attached but still fail on the windows. It *seems* VM do not support CP936.
1. I have tried to hard code "CP936" in the luniglob.c, make the file.encoding always be CP936. The vm failed to launch with the message "HMYEXEL054E vm inner fault: can not create java/lang/String, FAILED to invoke JVM" (The original msg is Chinese, I am translating it) 2. I have tried to hard code "UTF-8" in the luniglob.c, make the file.encoding always be UTF-8. The vm sucessfully launch and tests have been passed. Does somebody know where the vm load the String? And what does "HMYEXEL054E" mean? On Sat, Jul 18, 2009 at 11:10 AM, Nathan Beyer <ndbe...@apache.org> wrote: > On Fri, Jul 17, 2009 at 6:03 AM, Alexey > Varlamov<alexey.v.varla...@gmail.com> wrote: > > 2009/7/17, Nathan Beyer <ndbe...@apache.org>: > >> On Thu, Jul 16, 2009 at 8:50 PM, Nathan Beyer<ndbe...@apache.org> > wrote: > >> > On Thu, Jul 16, 2009 at 8:35 PM, Nathan Beyer<ndbe...@apache.org> > wrote: > >> >> On Thu, Jul 16, 2009 at 8:26 PM, Nathan Beyer<ndbe...@apache.org> > wrote: > >> >>> On Thu, Jul 16, 2009 at 8:18 PM, Charles Lee<littlee1...@gmail.com> > wrote: > >> >>>> Hi Nathan, > >> >>>> > >> >>>> What I got is 936, the code page identifier. Is there a api for us > to map > >> >>>> 936 to the gb2312? > >> >>> > >> >>> Oh, the 'identifier' bit was missing - yeah, we'll need to translate > >> >>> that into a name of some sort. I'll poke around a bit and see what I > >> >>> can find. > >> >> > >> >> We'll probably just have to put in a mapping ourselves based on the > >> >> documentation. We'd call GetACP [1] and map that to a known alias in > >> >> java.nio.charset that matches the definitions[2] of the identifiers. > >> >> > >> >> [1] http://msdn.microsoft.com/en-us/library/dd318070%28VS.85%29.aspx > >> >> [2] http://msdn.microsoft.com/en-us/library/dd317756%28VS.85%29.aspx > >> > > >> > This may be better - APR has a function for getting the OS default > >> > encoding. This would work across all platforms that APR supports and I > >> > believe we already use APR. > >> > > >> > > http://apr.apache.org/docs/apr/1.3/group__apr__portabile.html#g6e21845a4a5f3b7dd107b2beea50c91e > >> > >> However, the Windows version of this is simply - return > >> apr_psprintf(pool, "CP%u", (unsigned) GetACP());. Which is essentially > >> "CP" + codePageId. > >> > >> And the Unix version of this method doesn't look very good for our > purposes. > >> > > >> > -Nathan > > > > Yep - that's why APR was not used here initially. I guess your idea of > > GetACP() + hardcoded mapping is the most suitable approach. We already > > have similar solution for timezone detection, see > > working_vm\vm\port\src\misc\win\timezone.c (which also should be moved > > to classlib eventually, HARMONY-2053). > > I'd be inclined to combine these all together into the portlib > (luni?). Perhaps in some sort of OS environment portion, which can be > used by the rest of the class library. > > -Nathan > > > > > -- > > Alexey > > > -- Yours sincerely, Charles Lee
Index: modules/luni/src/main/native/luni/shared/luniglob.c ===================================================================== --- modules/luni/src/main/native/luni/shared/luniglob.c +++ modules/luni/src/main/native/luni/shared/luniglob.c @@ -29,6 +29,7 @@ #include "hyport.h" #include "strhelp.h" #include "hycomp.h" +#include "helpers.h" static UDATA keyInitCount = 0; @@ -156,7 +157,7 @@ JNI_OnLoad (JavaVM * vm, void *reserved) (*vmInterface)->GetSystemProperty (vmInterface, "file.encoding", &propVal); if (propVal == NULL) { /* FIXME provide appropriate non-dummy value */ - propRes = (*vmInterface)->SetSystemProperty (vmInterface, "file.encoding", "8859_1"); + propRes = (*vmInterface)->SetSystemProperty (vmInterface, "file.encoding", charset()); if (VMI_ERROR_NONE != propRes) { /* goto fail2; */ } Index: modules/luni/src/main/native/luni/unix/helpers.c ===================================================================== --- modules/luni/src/main/native/luni/unix/helpers.c +++ modules/luni/src/main/native/luni/unix/helpers.c @@ -220,3 +220,41 @@ setDefaultServerSocketOptions (JNIEnv * env, hysocket_t socketP) hysock_setopt_bool (socketP, HY_SOL_SOCKET, HY_SO_REUSEADDR, &value); } + +/* Get charset from the OS */ +inline char* charset() { + #define MAXBUFF 64 + char * codec = NULL; + char * ret = NULL; + int cur = 0; + short flag = 0; + setlocale(LC_CTYPE, ""); + codec = setlocale(LC_CTYPE, NULL); + // get codeset from language[_territory][.codese...@modifier] + char * locale = malloc(MAXBUFF * sizeof(char)); + while (*codec) { + if (!flag) { + if (*codec != '.') { + codec++; + continue; + } else { + flag = 1; + codec++; + } + } else { + if (*codec == '@') { + break; + } else { + locale[cur++] = (*codec); + codec++; + } + } + } + locale[cur] = '\0'; + if (!locale) { + ret = NULL; + } else { + ret = locale; + } + return ret; +} Index: modules/luni/src/main/native/luni/unix/helpers.h ===================================================================== --- modules/luni/src/main/native/luni/unix/helpers.h +++ modules/luni/src/main/native/luni/unix/helpers.h @@ -35,4 +35,5 @@ void setPlatformBindOptions (JNIEnv * env, hysocket_t socketP); I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time); I_32 setPlatformReadOnly (JNIEnv * env, char *path); int portCmp (const void **a, const void **b); +char *charset(); #endif /* helpers_h */ Index: modules/luni/src/main/native/luni/windows/helpers.c ===================================================================== --- modules/luni/src/main/native/luni/windows/helpers.c +++ modules/luni/src/main/native/luni/windows/helpers.c @@ -25,6 +25,7 @@ #include <windows.h> #include <winbase.h> #include <stdlib.h> +#include <stdio.h> #include <LMCONS.H> #include <direct.h> @@ -476,3 +477,33 @@ void setDefaultServerSocketOptions (JNIEnv * env, hysocket_t socketP) { } + +/* Get charset from the OS */ +char *charset() { +#ifdef _UNICODE + int i; +#endif +#if defined(_WIN32_WCE) + LCID locale = GetUserDefaultCID(); +#else + LCID locale = GetThreadLocale(); +#endif + int len = GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE, NULL, 0); + char *ret = malloc((len * sizeof(TCHAR)) + 2); + if (0 < GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE, (TCHAR*)(ret+2), len)) { + ret[0] = 'C'; + ret[1] = 'P'; +#ifdef _UNICODE + for (i=0; i < len; i++) { + ret[i+2] = (char)((TCHAR*)(ret+2))[i]; + } +#endif + return ret; + } +#ifdef _UNICODE + swprintf(ret, "CP%u", (unsigned) GetACP()); +#else + sprintf(ret, "CP%u", (unsigned) GetACP()); +#endif + return ret; +} Index: modules/luni/src/main/native/luni/windows/helpers.h ===================================================================== --- modules/luni/src/main/native/luni/windows/helpers.h +++ modules/luni/src/main/native/luni/windows/helpers.h @@ -34,4 +34,5 @@ I_32 getPlatformIsReadOnly (JNIEnv * env, char *path); void setPlatformBindOptions (JNIEnv * env, hysocket_t socketP); I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time); I_32 setPlatformReadOnly (JNIEnv * env, char *path); +char *charset(); #endif /* helpers_h */