Hi,

At Mon, 27 Feb 2006 01:49:33 +0900,
Tanaka Akira wrote in [ruby-core:07428]:
> 32-bit VALUE space:
> 
>                    VALUE
>         MSB ------------------------ LSB
> false   00000000000000000000000000000000
> true    00000000000000000000000000000010
> nil     00000000000000000000000000000100
> undef   00000000000000000000000000000110
> symbol  ssssssssssssssssssssssss00001110
> object  oooooooooooooooooooooooooooooo00
> 
> rb_obj_id generates an integer in different way between
> symbols and objects.
> 
>                    integer
>                                      LSB|FIXNUM_FLAG
> symbol  ssssssssssssssssssssssss00001110|1      LONG2NUM((long)obj)
> object   oooooooooooooooooooooooooooooo0|1      (VALUE)((long)obj|FIXNUM_FLAG)
> 
> # I ignore bignum case.
> 
> If ssssssssssssssssssssssss is 
> 0xxxxxxxxxxxxxxxxxxxxxxx and
> oooooooooooooooooooooooooooooo is 
> xxxxxxxxxxxxxxxxxxxxxxx0000111,
> they will be equal.

Two thoughts;

a) assume any objects never be placed at lowest 32MB area,
   while same problem presumably occurs on systems which
   doesn't have virtual memory feature, such as X68k.

b) use id name pointer instead of ID value, which would causes
   perfomance penalty.

Index: object.c
===================================================================
RCS file: /pub/cvs/ruby/src/ruby/object.c,v
retrieving revision 1.183
diff -U 2 -p -u -r1.183 object.c
--- object.c	17 Jan 2006 14:05:49 -0000	1.183
+++ object.c	27 Feb 2006 10:33:07 -0000
@@ -130,4 +130,13 @@ rb_obj_id(VALUE obj)
 {
     if (SPECIAL_CONST_P(obj)) {
+#if SIZEOF_VOIDP == 32		/* sizeof(VALUE) */
+	if (SYMBOL_P(obj)) {
+# if USE_TINY_OBJECT_ID
+	    return INT2FIX(SYM2ID(obj) << 1);
+# else
+	    return (VALUE)rb_id2name(obj) | FIXNUM_FLAG;
+# endif
+	}
+#endif
 	return LONG2NUM((long)obj);
     }

-- 
Nobu Nakada