On 11/23/16 2:30 PM, ketmar wrote:
On Wednesday, 23 November 2016 at 19:07:49 UTC, Chris wrote:
It has something to do with the smart quote, e.g.:

it is wrong binary search in `_d_switch_string()`.

strings for switch are lexically sorted, and compiler calls
`_d_switch_string()` to select one. the thing is that comparison in
`_d_switch_string()` is done with `memcmp()`. still not clear? ok, let's
see how cases are encoded:

body _d_switch_dstring()
       'U0027' (ca)
table[0] = 1, 'U0027'
table[1] = 1, 'U2019'

or, in memory:

table[0] = 1, 0x27, 0x00
table[1] = 1, 0x19, 0x20

so, memcmp for `table[1]` returns... 1! 'cause 0x27 is greater than
0x19. and binsearch is broken from here on. the same is true for
`_d_switch_ustring()`, of course.

this can be fixed either by using slow char-by-char comparisons in
druntime, or by fixing codegen, so it would sort strings as byte arrays.

Oh wow, so this is really an endian issue. On a big endian machine, the code would work. Interesting!

I think it makes the most sense to remove the memcmp, and do binary search based on actual char values.

Thanks for finding this.

-Steve

  • Switch ignores case (?) Chris via Digitalmars-d-learn
    • Re: Switch ignores case ... Steven Schveighoffer via Digitalmars-d-learn
      • Re: Switch ignores c... Chris via Digitalmars-d-learn
        • Re: Switch ignor... Steven Schveighoffer via Digitalmars-d-learn
          • Re: Switch i... Chris via Digitalmars-d-learn
            • Re: Swi... Jonathan M Davis via Digitalmars-d-learn
            • Re: Swi... ketmar via Digitalmars-d-learn
              • Re:... Chris via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
              • Re:... Steven Schveighoffer via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
                • ... Antonio Corbi via Digitalmars-d-learn
                • ... ketmar via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn

Reply via email to