ruby-changes:11067
From: nobu <ko1@a...>
Date: Fri, 27 Feb 2009 18:31:03 +0900 (JST)
Subject: [ruby-changes:11067] Ruby:r22662 (trunk): * compile.c (cdhash_type, iseq_set_sequence): should not call
nobu 2009-02-27 18:30:53 +0900 (Fri, 27 Feb 2009) New Revision: 22662 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22662 Log: * compile.c (cdhash_type, iseq_set_sequence): should not call methods of the argument of case, to keep the semantics of case/when. [ruby-dev:38079] Modified files: trunk/ChangeLog trunk/compile.c Index: ChangeLog =================================================================== --- ChangeLog (revision 22661) +++ ChangeLog (revision 22662) @@ -1,3 +1,9 @@ +Fri Feb 27 18:30:51 2009 Nobuyoshi Nakada <nobu@r...> + + * compile.c (cdhash_type, iseq_set_sequence): should not call + methods of the argument of case, to keep the semantics of + case/when. [ruby-dev:38079] + Fri Feb 27 18:01:20 2009 Nobuyoshi Nakada <nobu@r...> * gc.c (ruby_get_stack_grow_direction): no needs to use thread Index: compile.c =================================================================== --- compile.c (revision 22661) +++ compile.c (revision 22662) @@ -1216,6 +1216,38 @@ return COMPILE_OK; } +static int +cdhash_cmp(VALUE val, VALUE lit) +{ + if (val == lit) return 0; + if (SPECIAL_CONST_P(lit)) { + return val != lit; + } + if (SPECIAL_CONST_P(val) || BUILTIN_TYPE(val) != BUILTIN_TYPE(lit)) { + return -1; + } + if (BUILTIN_TYPE(lit) == T_STRING) { + return rb_str_hash_cmp(lit, val); + } + return !rb_eql(lit, val); +} + +static int +cdhash_hash(VALUE a) +{ + if (SPECIAL_CONST_P(a)) return (int)a; + if (TYPE(a) == T_STRING) return rb_str_hash(a); + { + VALUE hval = rb_hash(a); + return (int)FIX2LONG(hval); + } +} + +static const struct st_hash_type cdhash_type = { + cdhash_cmp, + cdhash_hash, +}; + /** ruby insn object array -> raw instruction sequence */ @@ -1343,6 +1375,7 @@ int i; VALUE lits = operands[j]; VALUE map = rb_hash_new(); + RHASH_TBL(map)->type = &cdhash_type; for (i=0; i < RARRAY_LEN(lits); i+=2) { VALUE obj = rb_ary_entry(lits, i); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/