[MacRuby] #769: String::ord with packed array in MacRuby
#769: String::ord with packed array in MacRuby ---------------------------------+------------------------------------------ Reporter: babs.devs@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Keywords: binary, pack, ord, ordinal, String, String::ord ---------------------------------+------------------------------------------ When attempting to get the ordinal from a character of an array packed to a binary string, MacRuby returns inconsistent values, and sometimes seg. faults. {{{ sha1 = ["94f389bf5d9af4511597d035e69d1be9510b50c7"].pack("H*") sha1[0].ord #Macirb has returned: # 63, 96, 65428(most often), 65535, and seg. faults #Irb returns: 148 foo = ['bar'].pack('H*') foo[1].ord #Macirb:65456 Irb:176 "cat"[0].ord #Works as expected }}} Tested with Ruby 1.9.1 and Macruby 6/23/10 nightly. -- Ticket URL: <http://www.macruby.org/trac/ticket/769> MacRuby <http://macruby.org/>
#769: String::ord with packed array in MacRuby ---------------------------------+------------------------------------------ Reporter: babs.devs@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Keywords: binary, pack, ord, ordinal, String, String::ord ---------------------------------+------------------------------------------ Comment(by babs.devs@…): Replying to [ticket:769 babs.devs@…]:
When attempting to get the ordinal from a character of an array packed to a binary string, MacRuby returns inconsistent values, and sometimes seg. faults.
{{{ sha1 = ["94f389bf5d9af4511597d035e69d1be9510b50c7"].pack("H*") sha1[0].ord #Macirb has returned: # 63, 96, 65428(most often), 65535, and seg. faults #Irb returns: 148
foo = ['bar'].pack('H*') foo[1].ord #Macirb:65456 Irb:176
"cat"[0].ord #Works as expected }}}
Tested with Ruby 1.9.1 and Macruby 6/23/10 nightly.
It looks like this might just be a fundamental misunderstanding on my part about how Ruby 1.9 vs MacRuby handle encoding. But I don't know enough to say one way or the other. {{{ foo = ["bar"].pack("H*") first_char = foo[0] p first_char #Macruby:"\xBA" Ruby:"\xBA" p first_char.encoding #Macruby:<Encoding:ASCII-8BIT> Ruby:<Encoding:ASCII-8BIT> p first_char.ord #Macruby: 65466 Ruby:186 first_char.each_codepoint {|cp| p cp} #Macruby: 65466 Ruby:186 first_char.each_char {|ch| p ch} #Macruby: "ᄎ" Ruby:"\xBA" }}} I would expect that since they the same encoding (& bytesize is the same), the last line would output "\xBA" in both cases. Is that an incorrect assumption? I've been trying to wrap my head around the encoding stuff, and possible discrepancies between 1.9 and MacRuby, so any help is much appreciated. Thanks, Babs *Tested with Ruby 1.9.2 and 07/07/10 Nightly MacRuby -- Ticket URL: <http://www.macruby.org/trac/ticket/769#comment:1> MacRuby <http://macruby.org/>
#769: String::ord with packed array in MacRuby ---------------------------------+------------------------------------------ Reporter: babs.devs@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: binary, pack, ord, ordinal, String, String::ord ---------------------------------+------------------------------------------ Changes (by lsansonetti@…): * milestone: MacRuby 0.7 => Comment: I believe you're hitting a MacRuby bug here. Our String#ord method does not behave like Ruby 1.9. -- Ticket URL: <http://www.macruby.org/trac/ticket/769#comment:2> MacRuby <http://macruby.org/>
#769: String::ord with packed array in MacRuby ---------------------------------+------------------------------------------ Reporter: babs.devs@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: binary, pack, ord, ordinal, String, String::ord ---------------------------------+------------------------------------------ Comment(by babs.devs@…): Replying to [comment:2 lsansonetti@…]:
I believe you're hitting a MacRuby bug here. Our String#ord method does not behave like Ruby 1.9.
Oh, ok. I was sure it was just a facepalm moment on my part, thanks for the heads up. I ended up hacking around this by doing something like this: {{{ foo[0].force_encoding("ISO-8859-1").encode("UTF-8").ord }}} It's probably wrong, but it seams to work for me. -- Ticket URL: <http://www.macruby.org/trac/ticket/769#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby