diff --git a/ChangeLog b/ChangeLog index 1c9c39f7dd..3cddc29e8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Mar 4 15:26:40 2006 Tanaka Akira + + * gc.c (id2ref): fix symbol test. + Fri Mar 3 21:22:42 2006 Tanaka Akira * lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination diff --git a/gc.c b/gc.c index 8f4473759c..d3c87ddc8f 100644 --- a/gc.c +++ b/gc.c @@ -1938,15 +1938,15 @@ id2ref(VALUE obj, VALUE objid) if (ptr == Qfalse) return Qfalse; if (ptr == Qnil) return Qnil; if (FIXNUM_P(ptr)) return (VALUE)ptr; + ptr = objid ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */ - if ((objid % sizeof(RVALUE)) == (4 << 2)) { - ID symid = objid / sizeof(RVALUE); + if ((ptr % sizeof(RVALUE)) == (4 << 2)) { + ID symid = ptr / sizeof(RVALUE); if (rb_id2name(symid) == 0) rb_raise(rb_eRangeError, "%p is not symbol id value", p0); return ID2SYM(symid); } - ptr = objid ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */ if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLOCK) { rb_raise(rb_eRangeError, "%p is not id value", p0); } diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb new file mode 100644 index 0000000000..dab94688ee --- /dev/null +++ b/test/ruby/test_objectspace.rb @@ -0,0 +1,35 @@ +require 'test/unit' + +class TestObjectSpace < Test::Unit::TestCase + def self.deftest_id2ref(obj) + /:(\d+)/ =~ caller[0] + file = $` + line = $1.to_i + eval <<"End", binding, file, line + define_method("test_id2ref_#{line}") {\ + o = ObjectSpace._id2ref(obj.object_id);\ + assert_equal(obj, o, "didn't round trip: #{obj.inspect}");\ + } +End + end + + deftest_id2ref(-0x4000000000000001) + deftest_id2ref(-0x4000000000000000) + deftest_id2ref(-0x40000001) + deftest_id2ref(-0x40000000) + deftest_id2ref(-1) + deftest_id2ref(0) + deftest_id2ref(1) + deftest_id2ref(0x3fffffff) + deftest_id2ref(0x40000000) + deftest_id2ref(0x3fffffffffffffff) + deftest_id2ref(0x4000000000000000) + deftest_id2ref(:a) + deftest_id2ref(:abcdefghijilkjl) + deftest_id2ref(:==) + deftest_id2ref(Object.new) + deftest_id2ref(self) + deftest_id2ref(true) + deftest_id2ref(false) + deftest_id2ref(nil) +end