[PATCH] [MinGW] PR libgcj/29151 Unconditionally create UNICODE environment

Marco Trudel mtrudel@gmx.ch
Sat Nov 18 09:46:00 GMT 2006


Mohan Embar wrote:
> Hi All,
> 
> This fixes PR libgcj/29151.

Cool! Good work!


thanks
Marco

> We were specifying the
> CREATE_UNICODE_ENVIRONMENT for the CreateProcess()
> call, but were not creating one except for UNICODE
> builds.
> 
> This is for the 4.2 branch. I would have committed
> it without asking except that I don't know whether
> we're allowed to commit things here at the moment.
> 
> -- Mohan
> http://www.thisiscool.com/
> http://www.animalsong.org/
> 
> 2006-11-17  Mohan Embar  <gnustuff@thisiscool.com>
> 
> 	PR libgcj/29151:
> 	* java/lang/natWin32Process.cc (startProcess): Unconditionally
> 	create a UNICODE environment for CreateProcess call.
> 
> Index: java/lang/natWin32Process.cc
> ===================================================================
> --- java/lang/natWin32Process.cc	(revision 118954)
> +++ java/lang/natWin32Process.cc	(working copy)
> @@ -240,8 +240,10 @@
>      }
>    *cmdLineCurPos = _T('\0');
>  
> -  // Get the environment, if any.
> -  LPTSTR env = NULL;
> +  // Get the environment, if any. Unconditionally
> +  // create a UNICODE environment, even on ANSI
> +  // builds.
> +  LPWSTR env = NULL;
>    if (envp)
>      {
>        elts = elements (envp);
> @@ -250,22 +252,22 @@
>        for (int i = 0; i < envp->length; ++i)
>          envLen += (elts[i]->length() + 1);
>  
> -      env = (LPTSTR) _Jv_Malloc ((envLen + 1) * sizeof(TCHAR));
> +      env = (LPWSTR) _Jv_Malloc ((envLen + 1) * sizeof(WCHAR));
>  
>        int j = 0;
>        for (int i = 0; i < envp->length; ++i)
>          {
> -          jint len = elts[i]->length();
> +          jstring elt = elts[i];
> +          jint len = elt->length();
>            
> -          JV_TEMP_STRING_WIN32(thiselt, elts[i]);
> -          _tcscpy(env + j, thiselt);
> +          wcsncpy(env + j, (LPCWSTR) JvGetStringChars(elt), len);
>            
>            j += len;
>            
> -          // Skip past the null terminator that _tcscpy just inserted.
> -          j++;
> +          // Insert the null terminator and skip past it.
> +          env[j++] = 0;
>          }
> -      *(env + j) = _T('\0');
> +      *(env + j) = 0;
>      }
>  
>    // Get the working directory path, if specified.
> 
> 
> 



More information about the Java-patches mailing list