Skip to content

Commit

Permalink
* string.c (rb_str_equal): object with to_str must be treated as a
Browse files Browse the repository at this point in the history
  string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Nov 29, 2001
1 parent 080aa35 commit 23303b8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Fri Nov 30 00:25:28 2001 Usaku Nakamura <usa@ruby-lang.org>

* README.EXT.ja: ditto.

Thu Nov 29 00:28:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>

* string.c (rb_str_equal): object with to_str must be treated as a
string.

Wed Nov 28 18:46:28 2001 Ville Mattila <mulperi@iki.fi>

* eval.c (rb_thread_select): should subtract timeofday() from
Expand Down
2 changes: 1 addition & 1 deletion eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7680,7 +7680,7 @@ rb_thread_schedule()
if (select_timeout && n == 0) {
if (now < 0.0) now = timeofday();
FOREACH_THREAD_FROM(curr, th) {
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay < now) {
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay <= now) {
th->status = THREAD_RUNNABLE;
th->wait_for = 0;
th->select_value = 0;
Expand Down
1 change: 1 addition & 0 deletions intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ VALUE rb_obj_id _((VALUE));
VALUE rb_obj_class _((VALUE));
VALUE rb_class_real _((VALUE));
VALUE rb_convert_type _((VALUE,int,const char*,const char*));
VALUE rb_check_convert_type _((VALUE,int,const char*,const char*));
VALUE rb_to_int _((VALUE));
VALUE rb_Integer _((VALUE));
VALUE rb_Float _((VALUE));
Expand Down
20 changes: 20 additions & 0 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,26 @@ rb_convert_type(val, type, tname, method)
return val;
}

VALUE
rb_check_convert_type(val, type, tname, method)
VALUE val;
int type;
const char *tname, *method;
{
struct arg_to arg1, arg2;

if (TYPE(val) == type) return val;
arg1.val = arg2.val = val;
arg1.s = method;
arg2.s = tname;
val = rb_rescue(to_type, (VALUE)&arg1, 0, 0);
if (!NIL_P(val) && TYPE(val) != type) {
rb_raise(rb_eTypeError, "%s#%s should return %s",
rb_class2name(CLASS_OF(arg1.val)), method, tname);
}
return val;
}

static VALUE
rb_to_integer(val, method)
VALUE val;
Expand Down
6 changes: 4 additions & 2 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,10 @@ rb_str_equal(str1, str2)
VALUE str1, str2;
{
if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING)
return Qfalse;
if (TYPE(str2) != T_STRING) {
str2 = rb_check_convert_type(str2, T_STRING, "String", "to_str");
if (NIL_P(str2)) return Qfalse;
}

if (RSTRING(str1)->len == RSTRING(str2)->len
&& rb_str_cmp(str1, str2) == 0) {
Expand Down

0 comments on commit 23303b8

Please sign in to comment.