summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 05:29:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-25 05:29:35 +0000
commit7db534a20c78cf4b9d8eb5f3c6a0198c2dd65aad (patch)
tree6b52b2e04eb5961d29f362359e9b774fe1245afb
parentb827fdffe60d612762dd8628e3dea9b6548a4f1c (diff)
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
-rw-r--r--internal.h2
-rw-r--r--numeric.c6
-rw-r--r--string.c2
-rw-r--r--vm_insnhelper.c50
4 files changed, 52 insertions, 8 deletions
diff --git a/internal.h b/internal.h
index 4c26bd2c13..9c11f4a308 100644
--- a/internal.h
+++ b/internal.h
@@ -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
diff --git a/numeric.c b/numeric.c
index 69bb573cc7..8205829f8d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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
diff --git a/string.c b/string.c
index 8de556718e..54a89f3565 100644
--- a/string.c
+++ b/string.c
@@ -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;
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index a23983a5e0..b9bfccac95 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -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 *);