JRuby

Array#pack fails for Q/q directives

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: JRuby 1.0.2, JRuby 1.1b1
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    OS X 10.4.9, Java 1.5, JRuby 1.0.0RC2
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

It appears that the 'Q/q' directive (64bit numbers) always returns an empty string. Here are some sample tests:

require 'test/unit'

class TC_Array_Pack_Q < Test::Unit::TestCase
   def setup
      @char_array  = %w/alpha beta gamma/
      @int_array   = [-1, 0, 1, 128]
      @float_array = [-1.5, 0.0, 1.5, 128.5]
      @bignum1      = 2**63
   end

   def endian(data, n=4)
      [1].pack('I') == [1].pack('N') ? data.gsub(/.{#{n}}/){ |s| s.reverse } : data
   end

   def test_pack_q
      assert_equal(endian("\000\000\000\000\000\000\000\000", 8), [0].pack("q"))
      assert_equal(endian("\001\000\000\000\000\000\000\000", 8), [1].pack("q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), [-1].pack("q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @int_array.pack("q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @float_array.pack("q"))
      assert_equal(endian("\000\000\000\000\000\000\000\200", 8), [@bignum1].pack("q"))
   end

   def test_pack_q_expected_errors
      assert_raises(TypeError){ @char_array.pack("q") }
      assert_raises(RangeError){ [(2**128)].pack("q") }
   end

   def test_pack_Q
      assert_equal(endian("\000\000\000\000\000\000\000\000", 8), [0].pack("Q"))
      assert_equal(endian("\001\000\000\000\000\000\000\000", 8), [1].pack("Q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), [-1].pack("Q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @int_array.pack("Q"))
      assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @float_array.pack("Q"))
      assert_equal(endian("\000\000\000\000\000\000\000\200", 8), [@bignum1].pack("Q"))
   end

   def test_pack_Q_expected_errors
      assert_raises(TypeError){ @char_array.pack("Q") }
      assert_raises(RangeError){ [(2**128)].pack("Q") }
   end

   def teardown
      @char_array  = nil
      @int_array   = nil
      @float_array = nil
      @bignum1     = nil
   end
end

And here are the results:

Loaded suite test/test_endian
Started
FFFF
Finished in 0.168 seconds.

  1) Failure:
test_pack_Q(TC_Array_Pack_Q) [test/test_endian.rb:30]:
<"\000\000\000\000\000\000\000\000"> expected but was
<"">.

  2) Failure:
test_pack_Q_expected_errors(TC_Array_Pack_Q) [test/test_endian.rb:39]:
<TypeError> exception expected but none was thrown.

  3) Failure:
test_pack_q(TC_Array_Pack_Q) [test/test_endian.rb:16]:
<"\000\000\000\000\000\000\000\000"> expected but was
<"">.

  4) Failure:
test_pack_q_expected_errors(TC_Array_Pack_Q) [test/test_endian.rb:25]:
<TypeError> exception expected but none was thrown.

4 tests, 4 assertions, 4 failures, 0 errors

Activity

Hide
Charles Oliver Nutter added a comment -

Still failing on trunk and 1.0 branch; probably too late to fix for 1.0.2, but try. Fix for 1.1.

Show
Charles Oliver Nutter added a comment - Still failing on trunk and 1.0 branch; probably too late to fix for 1.0.2, but try. Fix for 1.1.
Hide
Thomas E Enebo added a comment -

This is a good newbie bug to fix. Pack.java does not contain any implementation for q/Q. You just need to add the impl for these directives. Someone interested in getting started should give this one a try.

Show
Thomas E Enebo added a comment - This is a good newbie bug to fix. Pack.java does not contain any implementation for q/Q. You just need to add the impl for these directives. Someone interested in getting started should give this one a try.
Hide
Riley Lynch added a comment -

Patch to add support for Array#pack Q/q, runs all tests

Show
Riley Lynch added a comment - Patch to add support for Array#pack Q/q, runs all tests
Hide
Riley Lynch added a comment -

Patch also works for branch jruby-1_0

Show
Riley Lynch added a comment - Patch also works for branch jruby-1_0
Hide
Charles Oliver Nutter added a comment -

Looks great, thanks a lot Riley!

Show
Charles Oliver Nutter added a comment - Looks great, thanks a lot Riley!

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: