1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* gc.c (id2ref): fix symbol test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2006-03-04 06:28:51 +00:00
parent 192fcacebf
commit 989fb4fec7
3 changed files with 42 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Sat Mar 4 15:26:40 2006 Tanaka Akira <akr@m17n.org>
* gc.c (id2ref): fix symbol test.
Fri Mar 3 21:22:42 2006 Tanaka Akira <akr@m17n.org>
* lib/fileutils.rb (FileUtils.cp_r): implement :remove_destination

6
gc.c
View file

@ -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);
}

View file

@ -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