public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Hans-Bernhard Bröker" <HBBroeker@t-online.de>
To: cygwin@cygwin.com
Subject: Re: [:xdigit:] does not work with std::wstring in a Cygwin environment
Date: Tue, 15 Feb 2022 02:36:08 +0100	[thread overview]
Message-ID: <03ac7dd2-7082-2bb1-6c1b-c230764216e2@t-online.de> (raw)
In-Reply-To: <87tud2mxn1.fsf@Rainer.invalid>

Am 13.02.2022 um 19:25 schrieb Achim Gratz:
> Gans, Markus writes:
>> This seems to be an internal Cygwin error:
>> 
>> https://www.reddit.com/r/cpp_questions/comments/sp52gq/xdigit_does_not_work_with_stdwstring_in_a_cygwin/
>
>> 
[…]
>> Question: Why does Cygwin not detect the letters a, b, c, d, e, and
>> f as hexadecimal digits in a wide string?

[...]

> There is no OS specific configuration for Cygwin explicitly, instead
> there is one for newlib that actually gets used.

This piqued my curiosity, so I had a look at how libstdc++ is built.  I
found that at least for one crucial source file, called
ctype_members.cc, cygwin builds do _not_ use the newlib edition, but
rather the "generic" one.  And that may very well be the problem here.

The superficial cause of the problem is that member function
_M_initialize_ctype() in
libstdc++-v3/config/locale/generic/ctype_member.cc fills most of its
array _M_wmask[] with zeroes instead of meaningful character class 
identifiers.

The slightly deeper reason is that the companion array _M_bit[] is also
suspiciously full of zeroes.

But the real problem, IMHO, is that the type ctype<wchar_t>::mask is
just a plain char.  That overflows the looped shift used to fill
_M_bit[], which in turn leads to nonsense in _M_wmask[].

I didn't manage to find where this ctype<wchar_t>::mask is defined, but 
the way it's used here cannot work if it's defined as plain char.  The
newlib edition of ctype_members.cc loops over just 8 bits instead of
16, which would allow this to work.

So we either have to pick up a different type definition of 
ctype<wchar_t>::mask, or a different edition of ctype_members.cc --- I 
guess it should be the newlib one.

  reply	other threads:[~2022-02-15  1:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 16:02 Gans, Markus
2022-02-11 19:35 ` Corinna Vinschen
2022-02-13 18:25 ` Achim Gratz
2022-02-15  1:36   ` Hans-Bernhard Bröker [this message]
2022-02-17 23:11     ` Hans-Bernhard Bröker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03ac7dd2-7082-2bb1-6c1b-c230764216e2@t-online.de \
    --to=hbbroeker@t-online.de \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).