Skip to content

Usage of 'q*<' Array#pack modifier #124

Closed
dbussink opened this Issue Dec 7, 2012 · 2 comments

2 participants

@dbussink
dbussink commented Dec 7, 2012

Because of issue rubinius/rubinius#2075, I have the suspicion that Array#pack with the 'q<' modifier was intended in places where currently 'q<' is used.

On Rubinius this modifier fails to parse, because it doesn't mean anything. I believe that this working on MRI is a side effect, because this ends up being parsed as the 'q*' modifier, so the endianness modifier is ignored all together.

Reason for this argument:

[1, 2].pack('q*') => "\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00"

[1, 2].pack('q*<') => "\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00"
[1, 2].pack('q<*') => "\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00"

[1, 2].pack('q*>') => "\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00"
[1, 2].pack('q>*') => "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02"

As you can see here, 'q>' and 'q<' both end up as little endian. This problem probably hasn't happened because this code wasn't used on a big endian system where this probably would have shown.

Can anyone with more knowledge of moped confirm that this is indeed a correct rationale?

@dbussink dbussink referenced this issue in rubinius/rubinius Dec 7, 2012
Closed

Array.pack('q*<') not working #2075

@durran
Mongoid member
durran commented Dec 21, 2012

nice catch - thank you very much.

@durran durran closed this in ab03718 Dec 21, 2012
@dbussink

BTW, this isn't a Rubinius specific fix, it's more that it doesn't silently do something different on Rubinius :). Thanx for fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.