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

vm_insnhelper.c: rb_eql_opt should call eql?

* vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and
  String, not #==.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-25 05:29:35 +00:00
parent b827fdffe6
commit 7db534a20c
4 changed files with 52 additions and 8 deletions

View file

@ -1342,6 +1342,7 @@ VALUE rb_int_div(VALUE x, VALUE y);
VALUE rb_int_abs(VALUE num);
VALUE rb_float_abs(VALUE flt);
VALUE rb_float_equal(VALUE x, VALUE y);
VALUE rb_float_eql(VALUE x, VALUE y);
#if USE_FLONUM
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
@ -1619,6 +1620,7 @@ size_t rb_str_memsize(VALUE);
VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, VALUE passed_proc);
VALUE rb_sym_to_proc(VALUE sym);
char *rb_str_to_cstr(VALUE str);
VALUE rb_str_eql(VALUE str1, VALUE str2);
/* symbol.c */
#ifdef RUBY_ENCODING_H

View file

@ -1643,8 +1643,8 @@ flo_le(VALUE x, VALUE y)
* so an implementation-dependent value is returned.
*/
static VALUE
flo_eql(VALUE x, VALUE y)
VALUE
rb_float_eql(VALUE x, VALUE y)
{
if (RB_TYPE_P(y, T_FLOAT)) {
double a = RFLOAT_VALUE(x);
@ -1658,6 +1658,8 @@ flo_eql(VALUE x, VALUE y)
return Qfalse;
}
#define flo_eql rb_float_eql
/*
* call-seq:
* float.to_f -> self

View file

@ -3183,7 +3183,7 @@ rb_str_equal(VALUE str1, VALUE str2)
* Two strings are equal if they have the same length and content.
*/
static VALUE
VALUE
rb_str_eql(VALUE str1, VALUE str2)
{
if (str1 == str2) return Qtrue;

View file

@ -1295,6 +1295,9 @@ check_cfunc(const rb_callable_method_entry_t *me, VALUE (*func)())
}
}
#define BUILTIN_CLASS_P(x, k) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == k)
#define EQ_UNREDEFINED_P(t) BASIC_OP_UNREDEFINED_P(BOP_EQ, t##_REDEFINED_OP_FLAG)
static
#ifndef NO_BIG_INLINE
inline
@ -1302,8 +1305,6 @@ inline
VALUE
opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc)
{
#define BUILTIN_CLASS_P(x, k) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == k)
#define EQ_UNREDEFINED_P(t) BASIC_OP_UNREDEFINED_P(BOP_EQ, t##_REDEFINED_OP_FLAG)
if (FIXNUM_2_P(recv, obj)) {
if (EQ_UNREDEFINED_P(INTEGER)) {
return (recv == obj) ? Qtrue : Qfalse;
@ -1324,8 +1325,47 @@ opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc)
return rb_str_equal(recv, obj);
}
}
#undef EQ_UNREDEFINED_P
#undef BUILTIN_CLASS_P
{
vm_search_method(ci, cc, recv);
if (check_cfunc(cc->me, rb_obj_equal)) {
return recv == obj ? Qtrue : Qfalse;
}
}
return Qundef;
}
static
#ifndef NO_BIG_INLINE
inline
#endif
VALUE
opt_eql_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc)
{
#define BUILTIN_CLASS_P(x, k) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == k)
#define EQ_UNREDEFINED_P(t) BASIC_OP_UNREDEFINED_P(BOP_EQ, t##_REDEFINED_OP_FLAG)
if (FIXNUM_2_P(recv, obj)) {
if (EQ_UNREDEFINED_P(INTEGER)) {
return (recv == obj) ? Qtrue : Qfalse;
}
}
else if (FLONUM_2_P(recv, obj)) {
if (EQ_UNREDEFINED_P(FLOAT)) {
return (recv == obj) ? Qtrue : Qfalse;
}
}
else if (BUILTIN_CLASS_P(recv, rb_cFloat)) {
if (EQ_UNREDEFINED_P(FLOAT)) {
return rb_float_eql(recv, obj);
}
}
else if (BUILTIN_CLASS_P(recv, rb_cString)) {
if (EQ_UNREDEFINED_P(STRING)) {
return rb_str_eql(recv, obj);
}
}
{
vm_search_method(ci, cc, recv);
@ -1361,7 +1401,7 @@ rb_eql_opt(VALUE obj1, VALUE obj2)
cc.method_state = 0;
cc.class_serial = 0;
cc.me = NULL;
return opt_eq_func(obj1, obj2, &ci, &cc);
return opt_eql_func(obj1, obj2, &ci, &cc);
}
static VALUE vm_call0(rb_thread_t*, VALUE, ID, int, const VALUE*, const rb_callable_method_entry_t *);