This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [1.7][python] File operation API to multibyte filenames fails.


On May  9 05:02, IWAMURO Motonori wrote:
> 2009/5/9 Corinna Vinschen <corinna-cygwin@cygwin.com>:
> > Cool.  Thanks for the patch.  This actually solves the problem.
> > I applied the patch with just a little tweak.
> 
> Thanks.
> 
> The following patch might be better.
> 
> --- a/winsup/cygwin/strfuncs.cc Thu May 07 12:29:17 2009 +0900
> +++ b/winsup/cygwin/strfuncs.cc Sat May 09 04:39:49 2009 +0900
> @@ -427,7 +427,9 @@
>          path names) is transform_chars in path.cc. */
>        if ((pw & 0xff00) == 0xf000)
>         pw &= 0xff;
> +      int eno = errno;
>        int bytes = f_wctomb (_REENT, buf, pw, charset, &ps);
> +      errno = eno;
>        /* Convert chars invalid in the current codepage to a sequence
>           ASCII SO; UTF-8 representation of invalid char. */
>        if (bytes == -1 && *charset != 'U'/*TF-8*/)

Thanks.  I implemented that differently by just storing and restoring
the errno value at function entry and exit.  The sys_wcstombs and
sys_mbstowcs functions are not supposed to set errno anyway.

> > Nevertheless, it looks like python has a problem as well. ?Why does it
> > check an errno if the functions returned successfully? ?That doesn't
> > sound right to me.
> 
> When the last readdir returns NULL, python detects the error because
> readdir keeps previous errno.
> 
> 1) ep = readdir(dirp); // ep->d_name == ".", errno == 0
>    Python check only ep != NULL. -> OK
> 2) ep = readdir(dirp); // ep->d_name == "..", errno == 0
>    Python check only ep != NULL. -> OK
> 3) ep = readdir(dirp); // ep->d_name == "\xe3\x82...", errno == 138
>    Python check only ep != NULL. -> OK
> 4) ep = readdir(dirp); // ep->d_name == "\xe3\x83...", errno == 138
>    Python check only ep != NULL. -> OK
> 5) ep = readdir(dirp); // ep == NULL, errno == 138
>    Python check ep == NULL and errno != 0. -> Fail!

Ouch, right.  It shows that I'm tired.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]