Project

General

Profile

Bug #7348

marshaling an object by a float does not work

Added by tenderlovemaking (Aaron Patterson) about 5 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 2.0.0dev (2012-11-14 trunk 37650) [x86_64-darwin12.2.1]
Backport:
[ruby-core:49323]

Description

The below calls object doesn't round trip through marshal on edge ruby:

def test_marshal_object_and_float
e = Object.new
calls = []
calls << [2.0, e]
calls << [e]
assert_equal calls, Marshal.load(Marshal.dump(calls))
end

When I run this test case, for some reason, the float takes the place of the object in the second array:

[36/82] TestMarshal#test_marshal_object_and_float = 0.00 s

1) Failure:
test_marshal_object_and_float(TestMarshal) [/Users/aaron/git/ruby/test/ruby/test_marshal.rb:40]:
<[[2.0, #Object:0x007fa5c20b08a0], [#Object:0x007fa5c20b08a0]]> expected but was
<[[2.0, #Object:0x007fa5c20b05a8], [2.0]]>.

I've attached a failing test case.

marshal_fail.patch (556 Bytes) marshal_fail.patch tenderlovemaking (Aaron Patterson), 11/14/2012 09:20 AM
flonum_marshal_dump.patch (954 Bytes) flonum_marshal_dump.patch nagachika (Tomoyuki Chikanaga), 11/16/2012 02:38 PM

Associated revisions

Revision 37687
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • marshal.c (w_object): add flonum to arg->data to keep reference index
    consistency. [Bug #7348]

  • test/ruby/test_marshal.rb: add a test for above.

Revision 37687
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • marshal.c (w_object): add flonum to arg->data to keep reference index
    consistency. [Bug #7348]

  • test/ruby/test_marshal.rb: add a test for above.

Revision 37687
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • marshal.c (w_object): add flonum to arg->data to keep reference index
    consistency. [Bug #7348]

  • test/ruby/test_marshal.rb: add a test for above.

Revision 37687
Added by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • marshal.c (w_object): add flonum to arg->data to keep reference index
    consistency. [Bug #7348]

  • test/ruby/test_marshal.rb: add a test for above.

Revision 42995
Added by zzak (Zachary Scott) about 4 years ago

  • ext/openssl/lib/openssl/ssl.rb: [DOC] Document OpenSSL::SSLServer Based on a patch by Rafal Lisowski [Bug #7348]

Revision 42995
Added by zzak (Zachary Scott) about 4 years ago

  • ext/openssl/lib/openssl/ssl.rb: [DOC] Document OpenSSL::SSLServer Based on a patch by Rafal Lisowski [Bug #7348]

Revision 42995
Added by zzak (Zachary Scott) about 4 years ago

  • ext/openssl/lib/openssl/ssl.rb: [DOC] Document OpenSSL::SSLServer Based on a patch by Rafal Lisowski [Bug #7348]

Revision 42995
Added by zzak (Zachary Scott) about 4 years ago

  • ext/openssl/lib/openssl/ssl.rb: [DOC] Document OpenSSL::SSLServer Based on a patch by Rafal Lisowski [Bug #7348]

History

#1 [ruby-core:49327] Updated by mrkn (Kenta Murata) about 5 years ago

irb(main):006:0> e = Object.new
irb(main):007:0> Marshal.load(Marshal.dump([[2.0e-100, e], [e]]))
=> [[2.0e-100, #Object:0x007fa45a10bc28], [#Object:0x007fa45a10bc28]]

Therefore it is related to flonum.

#2 [ruby-core:49329] Updated by shyouhei (Shyouhei Urabe) about 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)

#3 [ruby-core:49407] Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

hello,

I've investigated about this issue.
When flonum is introduced at r36798, flonum is treated as immediate value in w_object(), but is should treated as reference value.
I will attach a patch. This patch introduce a trivial incompatibility. All flonum of same value are dumped as reference of same Float object. I don't think this is not a practical problem.

(on flonum supported environment)
a = [2.0, 2.0, 2.0]
File.write("dump.txt", Marshal.dump(a))

(on flonum not supported environment)
a = Marshal.load(File.read("dump.txt"))
a.map{|f| f.object_id} # => [70180445290980, 70180445290980, 70180445290980]

If there's no objection, I'll check-in it tonight (in JST).

#4 Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37687.
Aaron, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • marshal.c (w_object): add flonum to arg->data to keep reference index
    consistency. [Bug #7348]

  • test/ruby/test_marshal.rb: add a test for above.

#5 [ruby-core:57295] Updated by zzak (Zachary Scott) about 4 years ago

commit miss orz

Also available in: Atom PDF