[#1147] Copying RVALUE — why the lucky stiff <ruby-core@...>

Hello, everyone. Hope you are all doing well.

18 messages 2003/06/17
[#1155] Re: Copying RVALUE — matz@... (Yukihiro Matsumoto) 2003/06/20

Hi,

[#1157] Re: Copying RVALUE — why the lucky stiff <ruby-core@...> 2003/06/20

Yukihiro Matsumoto (matz@ruby-lang.org) wrote:

[#1173] class.c code cleanup (rb_class_*_instance_methods) — Matthew Dempsky <jivera@...>

Hi, I'm new to this mailing list so I don't know the procedure for

15 messages 2003/06/22
[#1174] Re: [Patch] class.c code cleanup (rb_class_*_instance_methods) — nobu.nokada@... 2003/06/22

Hi,

[#1175] Re: [Patch] class.c code cleanup (rb_class_*_instance_methods) — Matthew Dempsky <jivera@...> 2003/06/22

On Sun, 2003-06-22 at 05:36, nobu.nokada@softhome.net wrote:

[#1176] Re: [Patch] class.c code cleanup (rb_class_*_instance_methods) — nobu.nokada@... 2003/06/22

Hi,

[#1193] Re: [Patch] class.c code cleanup (rb_class_*_instance_methods) — Matthew Dempsky <jivera@...> 2003/06/25

On Sun, 2003-06-22 at 07:41, nobu.nokada@softhome.net wrote:

[#1177] Re: In 1.8.0 nil.to_s is not the same as "" — ts <decoux@...>

14 messages 2003/06/22

Re: YAML problem

From: Tanaka Akira <akr@...17n.org>
Date: 2003-06-06 09:14:48 UTC
List: ruby-core #1134
In article <20030605060109.GA60067@rysa.inetz.com>,
  why the lucky stiff <ruby-core@whytheluckystiff.net> writes:

> Fixed.  Was a problem with anchors on a collection.

Thank you.

But I found YAML has more problem.

% ruby -ryaml -e 'o = "\0"; p YAML.load(o.to_yaml)'
"\\z"

The result "\\z" is not equal to the input "\0".

I found above problem by following simple test program which generates
random objects.  It seems that YAML has more problems.

% cat tst
#!/usr/bin/env ruby

class Hash
  def hash
    h = 0
    self.each {|k,v|
      h ^= k.hash ^ v.hash
    }
    h
  end

  alias eql? ==
end

def random_fixnum
  rand(0x80000000) - 0x40000000
end

def random_bool
  [false, true][rand(2)]
end

def random_string
  len = rand(4)
  chars = []
  (0...len).each {|i|
    ## don't check bytes with MSB.
    #chars << rand(256)
    chars << rand(128)
  }
  chars.pack("C*")
end

def random_array
  o = []
  rand(4).times {
    o << random_obj
  }
  o
end

def random_hash
  o = {}
  rand(4).times {
    o[random_obj] = random_obj
  }
  o
end

Simple = [
  :random_fixnum,
  :random_bool,
  :random_string,
]

Complex = [
  :random_array,
  :random_hash,
]

Both = Simple + Complex

NestLimit = 10
Thread.current[:nest] = 0

def random_obj
  if Thread.current[:nest] < NestLimit
    methods = Both
  else
    methods = Simple
  end
  begin
    Thread.current[:nest] += 1
    m = methods[rand(methods.length)]
    self.send m
  ensure
    Thread.current[:nest] -= 1
  end
end

require 'yaml'
require 'pp'

100.times {
  o0 = random_obj
  begin
    y = o0.to_yaml
    o1 = YAML.load(y)
    raise "not equal" unless o0 == o1
  rescue
    pp o0
    pp o1
    puts y
    raise
  end
}
% ./tst
[{false=>266179502, 334540002=>"\n\022\022"},
 {false=>true, 1055494844=>103879957},
 true]
[{334540002=>"\\n\\x12\\x12", false=>266179502},
 {false=>true, 1055494844=>103879957},
 true]
- false: 266179502
  334540002: >-
    \n\x12\x12

- false: true
  1055494844: 103879957
- true
./tst:89: not equal (RuntimeError)
        from ./tst:84:in `times'
        from ./tst:84
-- 
Tanaka Akira

In This Thread

Prev Next