From nakama at ki.rim.or.jp  Tue May 23 09:54:12 2006
From: nakama at ki.rim.or.jp (Ei-ji Nakama)
Date: Tue, 23 May 2006 16:54:12 +0900
Subject: [Rd] Sys.setlocale upsets windows graphics device (PR#8887)
In-Reply-To: <Pine.LNX.4.64.0605221708150.10069@gannet.stats.ox.ac.uk>
References: <20060522080131.A0A2619A4F@slim.kubism.ku.dk>
	<dc41e1260605220701u5cbe3d1r6742a7e85b48c272@mail.gmail.com>
	<Pine.LNX.4.64.0605221708150.10069@gannet.stats.ox.ac.uk>
Message-ID: <dc41e1260605230054y1fda3723s59181042d2b23018@mail.gmail.com>

It clash similarly in the Japanese locale.

localeCP!= GetACP() .
It dies from msvcrt (mb*) the case where NULL is specified.

diff -ruN R-2.3.0.orig/src/gnuwin32/graphapp/buttons.c
R-2.3.0/src/gnuwin32/graphapp/buttons.c
--- R-2.3.0.orig/src/gnuwin32/graphapp/buttons.c        Mon Apr 10 07:20:00 2006
+++ R-2.3.0/src/gnuwin32/graphapp/buttons.c     Tue May 23 16:26:51 2006
@@ -132,9 +132,16 @@

        if(is_NT && (localeCP != GetACP())) {
            wchar_t wkind[100], wc[1000];
-           mbstowcs(wkind, kind, 100);
-           mbstowcs(wc, text, 1000);
-           hwnd = CreateWindowW(wkind, wc,
+           wchar_t *wkindp=wkind, *wcp=wc;
+           if(kind)
+               mbstowcs(wkindp, kind, 100);
+           else
+               wkindp=NULL;
+           if(text)
+               mbstowcs(wcp, text, 1000);
+           else
+               wcp=NULL;
+           hwnd = CreateWindowW(wkindp, wcp,
                                 (WS_CHILD | WS_VISIBLE) | style,
                                 r.x, r.y, r.width, r.height,
                                 current_window->handle,
diff -ruN R-2.3.0.orig/src/gnuwin32/graphapp/menus.c
R-2.3.0/src/gnuwin32/graphapp/menus.c
--- R-2.3.0.orig/src/gnuwin32/graphapp/menus.c  Mon Apr 10 07:20:00 2006
+++ R-2.3.0/src/gnuwin32/graphapp/menus.c       Tue May 23 15:36:14 2006
@@ -302,9 +302,12 @@
 BOOL myAppendMenu(HMENU h, UINT flags, UINT id, LPCTSTR name)
 {
     if(is_NT && (localeCP != GetACP())) {
-       wchar_t wc[100];
-       mbstowcs(wc, name, 100);
-       return AppendMenuW(h, flags, id, wc);
+       wchar_t wc[100], *wcp=wc;
+       if (name)
+         mbstowcs(wcp, name, 100);
+       else
+         wcp=NULL;
+       return AppendMenuW(h, flags, id, wcp);
     } else
        return AppendMenuA(h, flags, id, name);
 }
diff -ruN R-2.3.0.orig/src/gnuwin32/graphapp/windows.c
R-2.3.0/src/gnuwin32/graphapp/windows.c
--- R-2.3.0.orig/src/gnuwin32/graphapp/windows.c        Mon Apr 10 07:20:00 2006
+++ R-2.3.0/src/gnuwin32/graphapp/windows.c     Tue May 23 16:39:23 2006
@@ -455,13 +455,21 @@

                if(is_NT && (localeCP != GetACP())) {
                    wchar_t wkind[100], wc[1000];
-                   mbstowcs(wkind, (flags & Workspace) ? work_class_name
-                            : win_class_name, 100);
-                   mbstowcs(wc, name, 1000);
+                   wchar_t *wkindp=wkind, *wcp=wc;
+                   if((flags & Workspace) ? work_class_name
+                      : win_class_name)
+                       mbstowcs(wkindp, (flags & Workspace) ? work_class_name
+                                : win_class_name, 100);
+                   else
+                     wkindp=NULL;
+                   if(name)
+                       mbstowcs(wcp, name, 1000);
+                   else
+                       wcp=NULL;
                    hwnd = CreateWindowExW(
                        ex_style,
-                       wkind,
-                       wc, win_style,
+                       wkindp,
+                       wcp, win_style,
                        r.x, r.y, r.width, r.height,
                        (HWND) ((flags & ChildWindow) ?
                                current_window->handle : 0),


2006/5/23, Prof Brian Ripley <ripley at stats.ox.ac.uk>:
> On Mon, 22 May 2006, Ei-ji Nakama wrote:
>
> > If a return value of locale does not have a period, a function of libmingwex
> > gives back NULL in strchr and refers to NULL pointer in atoi.
> >
> > But it will be right to fix mingw...
> >
> > --- locales.R.orig      Mon Apr 10 07:19:19 2006
> > +++ locales.R   Mon May 22 22:55:21 2006
> > @@ -10,6 +10,7 @@
> > {
> >     category <- match(category, c("LC_ALL", "LC_COLLATE", "LC_CTYPE",
> >                                   "LC_MONETARY", "LC_NUMERIC", "LC_TIME"))
> > +    if(locale == "C") locale = "English_United States.1252");
> >     if(is.na(category)) stop("invalid 'category' argument")
> >     .Internal(setlocale(category, locale))
> > }
>
> Unfortunately that does not affect e.g. 'Rgui LC_ALL=C' so a more
> comprehensive C-level fix would be needed.
>
> I did wonder if mingwex was the problem, but in theory at least it knows
> about the C locale (cp = 0), and the crash was coming from MSVCRT.dll, in
> the conversion of an ASCII string to wchar.  Since it works in other
> Windows base locales it did seem specific to Thai (which is still a
> single-byte locale).
>
>
> > 2006/5/22, ripley at stats.ox.ac.uk <ripley at stats.ox.ac.uk>:
> >> On Mon, 22 May 2006, Edward wrote:
> >>
> >>> Hi,
> >>> We tried it on 3 separate windows XP computers using version 2.3.0.
> >>> The original locale is set for Thailand on all 3.
> >>> So how do we fix it? Is there another patch?
> >>
> >> Don't try to do graphics in the C locale on your computer?
> >>
> >> I suspect this is a font problem in Windows, in that your fonts may be
> >> specific to the Thai localization.  But without a means of reproducing
> >> this, I can only guess.
> >>
> >> If you can set up a debugger (see the rw-FAQ), you may be able to give us
> >> some additional clues as the where the crash is occuring.
> >>
> >>> And why does the crash not happen with earlier R versions (eg. 2.2.1) on the
> >>> same computer?
> >>
> >> Because of the issue mentioned in the CHANGES file, the change to the C
> >> locale was reverted by opening a graphics window.
> >>
> >>>
> >>> ---
> >>>> Sys.getlocale()
> >>> [1]
> >>> "LC_COLLATE=Thai_Thailand.874;LC_CTYPE=Thai_Thailand.874;LC_MONETARY=Thai_Thailand.874;LC_NUMERIC=C;LC_TIME=Thai_Thailand.874"
> >>> ---
> >>>
> >>> Thanks
> >>> Edward
> >>>
> >>> ----- Original Message ----- From: "Prof Brian Ripley"
> >>> <ripley at stats.ox.ac.uk>
> >>> To: <edward.m at psu.ac.th>
> >>> Cc: <R-bugs at biostat.ku.dk>
> >>> Sent: Monday, May 22, 2006 2:32 PM
> >>> Subject: Re: [Rd] Sys.setlocale upsets windows graphics device (PR#8887)
> >>>
> >>>
> >>>> Works perfectly for me.  There was a bug in 2.2.1, but it was fixed in
> >>>> 2.2.1 patched (see CHANGES).
> >>>>
> >>>> What locale were you changing from?  (This might be a Windows problem
> >>>> specific to your locale.)
> >>>>
> >>>> On Mon, 22 May 2006, edward.m at psu.ac.th wrote:
> >>>>
> >>>>> Full_Name: Edward McNeil
> >>>>> Version: 2.3.0
> >>>>> OS: Widows XP
> >>>>> Submission from: (NULL) (203.170.234.5)
> >>>>>
> >>>>>
> >>>>> Type the following:
> >>>>>
> >>>>>> Sys.setlocale("LC_ALL","C")
> >>>>>> hist(1:10)
> >>>>>
> >>>>> CRASH
> >>>>>
> >>>>> ______________________________________________
> >>>>> R-devel at r-project.org mailing list
> >>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>>>>
> >>>>>
> >>>>
> >>>> --
> >>>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> >>>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> >>>> University of Oxford,             Tel:  +44 1865 272861 (self)
> >>>> 1 South Parks Road,                     +44 1865 272866 (PA)
> >>>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> >>>
> >>>
> >>
> >> --
> >> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> >> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> >> University of Oxford,             Tel:  +44 1865 272861 (self)
> >> 1 South Parks Road,                     +44 1865 272866 (PA)
> >> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> >>
> >> ______________________________________________
> >> R-devel at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
> >
> >
> >
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>


-- 
EI-JI Nakama  <nakama at ki.rim.or.jp>
"\u4e2d\u9593\u6804\u6cbb"  <nakama at ki.rim.or.jp>



[Rd] Sys.setlocale upsets windows graphics device (PR#8887)
Ei-ji Nakama