[llvm] r205839 - YAMLIO: Encode ambiguous hex strings explicitly

Sean Silva chisophugis at gmail.com
Wed Apr 9 10:49:20 PDT 2014


On Wed, Apr 9, 2014 at 1:16 PM, David Majnemer <david.majnemer at gmail.com>wrote:

> YAML 1.1 has just zero as an octal prefix:
> http://www.yaml.org/spec/1.1/#id858600
>
> This seems to be the behavior of the most popular YAML readers I can get
> my hands on:
> irb(main):002:0> YAML.load("010")
> => 8
>
> >>> yaml.load("010")
> 8
>
>
> We get the distinction between strings and integers wrong without this
> change.  It's pretty easy to see this if you serialize a StringRef holding
> a decimal (like "3") or hexadecimal number (like "0x3"), we will write it
> out unquoted which turns it into a number.
>

This failure to correctly distinguish between numbers and strings is the
biggest problem IMO. Thanks for working on this David.

Regarding the strange octal behavior of other implementations: I hate going
against the spec, but if this patch is required for compatibility with
existing implementations I support it. IMO one of the big advantages of
using YAML is the easy interoperation with external tools and scripts.

One thing: I would at least like a small comment indicating that the "just
leading zero"-octal isn't actually needed by the spec, but that we use this
behavior (which results in perfectly compliant YAML either way) for
compatibility with other implementations.

-- Sean Silva


>
> On Wed Apr 09 2014 at 7:50:30 AM, Michael Spencer <bigcheesegs at gmail.com>
> wrote:
>
>> On Wed, Apr 9, 2014 at 8:56 AM, David Majnemer <david.majnemer at gmail.com>
>> wrote:
>> > Author: majnemer
>> > Date: Wed Apr  9 02:56:27 2014
>> > New Revision: 205839
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=205839&view=rev
>> > Log:
>> > YAMLIO: Encode ambiguous hex strings explicitly
>> >
>> > YAMLIO would turn a BinaryRef into the string 0000000004000000.
>> > However, the leading zero causes parsers to interpret it as being an
>> > octal number instead of a hexadecimal one.
>> >
>> > Instead, escape such strings as needed.
>> >
>>
>> This is wrong. In YAML all numbers are treated as decimal. Also this
>> changes the tag type of the value to !!str.
>>
>> The correct change is to fix the reader to always do decimal and
>> handle the 0x and 0o prefixes.
>>
>> See: http://www.yaml.org/spec/1.2/spec.html#id2805071
>>
>> - Michael Spencer
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140409/eb3fa427/attachment.html>


More information about the llvm-commits mailing list