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

* numeric.c (num_step): use DBL_EPSILON.

* array.c (rb_check_array_type): new function: return an array
  (convert if possible), or nil.

* string.c (rb_check_string_type): new function: return a string
  (convert if possible), or nil.

* numeric.c (rb_dbl_cmp): returns nil if values are not
  comparable.

* numeric.c (fix_cmp,flo_cmp): use rb_num_coerce_cmp()

* bignum.c (rb_big_cmp): ditto.

* numeric.c (rb_num_coerce_cmp): new coercing function for "<=>",
  which does not raise TypeError.

* numeric.c (do_coerce): can be supress exception now.

* object.c (rb_mod_cmp): should return nil for non class/module
  objects.

* re.c (rb_reg_eqq): return false if the argument is not a
  string.  now returns boolean value.

* class.c (rb_include_module): argument should be T_MODULE, not
  T_class, nor T_ICLASS.

* eval.c (is_defined): "defined?" should return "assignment" for
  attribute assignment (e.g. a.foo=b) and indexed assignment
  (e.g. a[2] = 44).

* parse.y (aryset): use NODE_ATTRASGN.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-12-19 09:20:20 +00:00
parent a0a14ed14a
commit baa00aa250
18 changed files with 158 additions and 47 deletions

View file

@ -1,7 +1,40 @@
Thu Dec 19 01:00:09 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (num_step): use DBL_EPSILON.
* array.c (rb_check_array_type): new function: return an array
(convert if possible), or nil.
* string.c (rb_check_string_type): new function: return a string
(convert if possible), or nil.
* numeric.c (rb_dbl_cmp): returns nil if values are not
comparable.
* numeric.c (fix_cmp,flo_cmp): use rb_num_coerce_cmp()
* bignum.c (rb_big_cmp): ditto.
* numeric.c (rb_num_coerce_cmp): new coercing function for "<=>",
which does not raise TypeError.
* numeric.c (do_coerce): can be supress exception now.
* object.c (rb_mod_cmp): should return nil for non class/module
objects.
Thu Dec 19 04:21:10 2002 Akinori MUSHA <knu@iDaemons.org> Thu Dec 19 04:21:10 2002 Akinori MUSHA <knu@iDaemons.org>
* lib/open-uri.rb: add a missing ||. (found by: ruby -wc) * lib/open-uri.rb: add a missing ||. (found by: ruby -wc)
Wed Dec 18 17:53:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (rb_reg_eqq): return false if the argument is not a
string. now returns boolean value.
* class.c (rb_include_module): argument should be T_MODULE, not
T_class, nor T_ICLASS.
Wed Dec 18 03:52:55 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Wed Dec 18 03:52:55 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* string.c (rb_str_new4): handle tail shared string. * string.c (rb_str_new4): handle tail shared string.
@ -22,6 +55,14 @@ Tue Dec 17 21:08:29 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* re.c (rb_reg_nth_match): ditto. * re.c (rb_reg_nth_match): ditto.
Tue Dec 17 16:52:38 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (is_defined): "defined?" should return "assignment" for
attribute assignment (e.g. a.foo=b) and indexed assignment
(e.g. a[2] = 44).
* parse.y (aryset): use NODE_ATTRASGN.
Tue Dec 17 04:03:45 2002 Tanaka Akira <akr@m17n.org> Tue Dec 17 04:03:45 2002 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb: new file. * lib/open-uri.rb: new file.
@ -78,6 +119,11 @@ Fri Dec 13 23:42:16 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/dbm/extconf.rb (db_check): check existence of the function * ext/dbm/extconf.rb (db_check): check existence of the function
in the specified library before checking it in libc. in the specified library before checking it in libc.
Fri Dec 13 17:15:49 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (generic_ivar_get): should always warn uninitialized
instance variables.
Fri Dec 13 12:33:22 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Fri Dec 13 12:33:22 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* parse.y (expr): rescue clause was ignored. * parse.y (expr): rescue clause was ignored.

View file

@ -204,6 +204,13 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary"); return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
} }
VALUE
rb_check_array_type(ary)
VALUE ary;
{
return rb_check_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
static VALUE rb_ary_replace _((VALUE, VALUE)); static VALUE rb_ary_replace _((VALUE, VALUE));
static VALUE static VALUE
@ -225,7 +232,7 @@ rb_ary_initialize(argc, argv, ary)
} }
if (argc == 1 && !FIXNUM_P(size)) { if (argc == 1 && !FIXNUM_P(size)) {
val = rb_check_convert_type(size, T_ARRAY, "Array", "to_ary"); val = rb_check_array_type(size);
if (!NIL_P(val)) { if (!NIL_P(val)) {
rb_ary_replace(ary, val); rb_ary_replace(ary, val);
return ary; return ary;

View file

@ -853,7 +853,7 @@ rb_big_cmp(x, y)
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value); return rb_dbl_cmp(rb_big2dbl(x), RFLOAT(y)->value);
default: default:
return rb_num_coerce_bin(x, y); return rb_num_coerce_cmp(x, y);
} }
if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1); if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1);
@ -1749,7 +1749,6 @@ Init_Bignum()
rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1); rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1);
rb_define_method(rb_cBignum, "==", rb_big_eq, 1); rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
rb_define_method(rb_cBignum, "eql?", rb_big_eql, 1); rb_define_method(rb_cBignum, "eql?", rb_big_eql, 1);
rb_define_method(rb_cBignum, "hash", rb_big_hash, 0); rb_define_method(rb_cBignum, "hash", rb_big_hash, 0);
rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0); rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);

View file

@ -365,12 +365,7 @@ rb_include_module(klass, module)
if (NIL_P(module)) return; if (NIL_P(module)) return;
if (klass == module) return; if (klass == module) return;
switch (TYPE(module)) { if (TYPE(module) != T_MODULE) {
case T_MODULE:
case T_CLASS:
case T_ICLASS:
break;
default:
Check_Type(module, T_MODULE); Check_Type(module, T_MODULE);
} }

View file

@ -354,7 +354,7 @@ AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\ AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\ fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h \ syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h \
sys/mkdev.h sys/utime.h) sys/mkdev.h sys/utime.h float.h)
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T AC_TYPE_UID_T

8
eval.c
View file

@ -1881,6 +1881,7 @@ is_defined(self, node, buf)
goto check_bound; goto check_bound;
case NODE_CALL: case NODE_CALL:
case NODE_ATTRASGN:
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
val = rb_eval(self, node->nd_recv); val = rb_eval(self, node->nd_recv);
@ -1909,7 +1910,9 @@ is_defined(self, node, buf)
} }
else if (!rb_method_boundp(val, node->nd_mid, call)) else if (!rb_method_boundp(val, node->nd_mid, call))
break; break;
return arg_defined(self, node->nd_args, buf, "method"); return arg_defined(self, node->nd_args, buf,
nd_type(node) == NODE_ATTRASGN ?
"assignment" : "method");
} }
break; break;
@ -1936,7 +1939,6 @@ is_defined(self, node, buf)
return "false"; return "false";
case NODE_ATTRSET: case NODE_ATTRSET:
case NODE_ATTRASGN:
case NODE_OP_ASGN1: case NODE_OP_ASGN1:
case NODE_OP_ASGN2: case NODE_OP_ASGN2:
case NODE_MASGN: case NODE_MASGN:
@ -5039,7 +5041,7 @@ compile(src, file, line)
NODE *node; NODE *node;
ruby_nerrs = 0; ruby_nerrs = 0;
Check_Type(src, T_STRING); StringValue(src);
node = rb_compile_string(file, src, line); node = rb_compile_string(file, src, line);
if (ruby_nerrs == 0) return node; if (ruby_nerrs == 0) return node;

4
file.c
View file

@ -1826,13 +1826,11 @@ test_check(n, argc, argv)
for (i=1; i<n; i++) { for (i=1; i<n; i++) {
switch (TYPE(argv[i])) { switch (TYPE(argv[i])) {
case T_STRING: case T_STRING:
default:
SafeStringValue(argv[i]); SafeStringValue(argv[i]);
break; break;
case T_FILE: case T_FILE:
break; break;
default:
Check_Type(argv[i], T_STRING);
break;
} }
} }
} }

View file

@ -52,6 +52,7 @@ VALUE rb_ary_includes _((VALUE, VALUE));
VALUE rb_ary_cmp _((VALUE, VALUE)); VALUE rb_ary_cmp _((VALUE, VALUE));
VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE)); VALUE rb_protect_inspect _((VALUE(*)(ANYARGS),VALUE,VALUE));
VALUE rb_inspecting_p _((VALUE)); VALUE rb_inspecting_p _((VALUE));
VALUE rb_check_array_value _((VALUE));
/* bignum.c */ /* bignum.c */
VALUE rb_big_clone _((VALUE)); VALUE rb_big_clone _((VALUE));
void rb_big_2comp _((VALUE)); void rb_big_2comp _((VALUE));
@ -262,6 +263,7 @@ VALUE rb_marshal_load _((VALUE));
/* numeric.c */ /* numeric.c */
void rb_num_zerodiv _((void)); void rb_num_zerodiv _((void));
VALUE rb_num_coerce_bin _((VALUE, VALUE)); VALUE rb_num_coerce_bin _((VALUE, VALUE));
VALUE rb_num_coerce_cmp _((VALUE, VALUE));
VALUE rb_float_new _((double)); VALUE rb_float_new _((double));
VALUE rb_num2fix _((VALUE)); VALUE rb_num2fix _((VALUE));
VALUE rb_fix2str _((VALUE, int)); VALUE rb_fix2str _((VALUE, int));
@ -371,6 +373,7 @@ VALUE rb_str_buf_append _((VALUE, VALUE));
VALUE rb_str_buf_cat _((VALUE, const char*, long)); VALUE rb_str_buf_cat _((VALUE, const char*, long));
VALUE rb_str_buf_cat2 _((VALUE, const char*)); VALUE rb_str_buf_cat2 _((VALUE, const char*));
VALUE rb_obj_as_string _((VALUE)); VALUE rb_obj_as_string _((VALUE));
VALUE rb_check_string_type _((VALUE));
VALUE rb_str_dup _((VALUE)); VALUE rb_str_dup _((VALUE));
VALUE rb_str_dup_frozen _((VALUE)); VALUE rb_str_dup_frozen _((VALUE));
VALUE rb_str_plus _((VALUE, VALUE)); VALUE rb_str_plus _((VALUE, VALUE));

2
io.c
View file

@ -2581,7 +2581,7 @@ rb_io_puts(argc, argv, out)
line = rb_str_new2("nil"); line = rb_str_new2("nil");
} }
else { else {
line = rb_check_convert_type(argv[i], T_ARRAY, "Array", "to_ary"); line = rb_check_array_type(argv[i]);
if (!NIL_P(line)) { if (!NIL_P(line)) {
rb_protect_inspect(io_puts_ary, line, out); rb_protect_inspect(io_puts_ary, line, out);
continue; continue;

View file

@ -752,7 +752,7 @@ r_bytes0(len, arg)
VALUE n = LONG2NUM(len); VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n); str = rb_funcall2(src, s_read, 1, &n);
if (NIL_P(str)) goto too_short; if (NIL_P(str)) goto too_short;
Check_Type(str, T_STRING); StringValue(str);
if (RSTRING(str)->len != len) goto too_short; if (RSTRING(str)->len != len) goto too_short;
if (OBJ_TAINTED(str)) arg->taint = Qtrue; if (OBJ_TAINTED(str)) arg->taint = Qtrue;
} }

View file

@ -13,10 +13,19 @@
#include "ruby.h" #include "ruby.h"
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#if defined(__FreeBSD__) && __FreeBSD__ < 4 #if defined(__FreeBSD__) && __FreeBSD__ < 4
#include <floatingpoint.h> #include <floatingpoint.h>
#endif #endif
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifndef DBL_EPSILON
#define 2.2204460492503131E-16
#endif
static ID id_coerce, id_to_i, id_div; static ID id_coerce, id_to_i, id_div;
VALUE rb_cNumeric; VALUE rb_cNumeric;
@ -61,32 +70,46 @@ coerce_rescue(x)
return Qnil; /* dummy */ return Qnil; /* dummy */
} }
static void static int
do_coerce(x, y) do_coerce(x, y, err)
VALUE *x, *y; VALUE *x, *y;
int err;
{ {
VALUE ary; VALUE ary;
VALUE a[2]; VALUE a[2];
a[0] = *x; a[1] = *y; a[0] = *x; a[1] = *y;
ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a); ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) { if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) {
if (err) {
rb_raise(rb_eTypeError, "coerce must return [x, y]"); rb_raise(rb_eTypeError, "coerce must return [x, y]");
} }
return Qfalse;
}
*x = RARRAY(ary)->ptr[0]; *x = RARRAY(ary)->ptr[0];
*y = RARRAY(ary)->ptr[1]; *y = RARRAY(ary)->ptr[1];
return Qtrue;
} }
VALUE VALUE
rb_num_coerce_bin(x, y) rb_num_coerce_bin(x, y)
VALUE x, y; VALUE x, y;
{ {
do_coerce(&x, &y); do_coerce(&x, &y, Qtrue);
return rb_funcall(x, rb_frame_last_func(), 1, y); return rb_funcall(x, rb_frame_last_func(), 1, y);
} }
VALUE
rb_num_coerce_cmp(x, y)
VALUE x, y;
{
if (do_coerce(&x, &y, Qfalse))
return rb_funcall(x, rb_frame_last_func(), 1, y);
return Qnil;
}
static VALUE static VALUE
num_copy_object(x, y) num_copy_object(x, y)
VALUE x, y; VALUE x, y;
@ -110,7 +133,7 @@ num_uminus(num)
VALUE zero; VALUE zero;
zero = INT2FIX(0); zero = INT2FIX(0);
do_coerce(&zero, &num); do_coerce(&zero, &num, Qtrue);
return rb_funcall(zero, '-', 1, num); return rb_funcall(zero, '-', 1, num);
} }
@ -494,7 +517,7 @@ rb_dbl_cmp(a, b)
if (a == b) return INT2FIX(0); if (a == b) return INT2FIX(0);
if (a > b) return INT2FIX(1); if (a > b) return INT2FIX(1);
if (a < b) return INT2FIX(-1); if (a < b) return INT2FIX(-1);
rb_raise(rb_eFloatDomainError, "comparing NaN"); return Qnil;
} }
static VALUE static VALUE
@ -518,7 +541,7 @@ flo_cmp(x, y)
break; break;
default: default:
return rb_num_coerce_bin(x, y); return rb_num_coerce_cmp(x, y);
} }
return rb_dbl_cmp(a, b); return rb_dbl_cmp(a, b);
} }
@ -824,7 +847,7 @@ num_step(argc, argv, from)
} }
} }
else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) { else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
const double epsilon = 2.2204460492503131E-16; const double epsilon = DBL_EPSILON;
double beg = NUM2DBL(from); double beg = NUM2DBL(from);
double end = NUM2DBL(to); double end = NUM2DBL(to);
double unit = NUM2DBL(step); double unit = NUM2DBL(step);
@ -1322,7 +1345,7 @@ fix_cmp(x, y)
return INT2FIX(-1); return INT2FIX(-1);
} }
else { else {
return rb_num_coerce_bin(x, y); return rb_num_coerce_cmp(x, y);
} }
} }

View file

@ -651,9 +651,7 @@ rb_mod_cmp(mod, arg)
case T_CLASS: case T_CLASS:
break; break;
default: default:
rb_raise(rb_eTypeError, "<=> requires Class or Module (%s given)", return Qnil;
rb_class2name(CLASS_OF(arg)));
break;
} }
if (rb_mod_le(mod, arg)) { if (rb_mod_le(mod, arg)) {

View file

@ -4687,7 +4687,7 @@ aryset(recv, idx)
NODE *recv, *idx; NODE *recv, *idx;
{ {
value_expr(recv); value_expr(recv);
return NEW_CALL(recv, tASET, idx); return NEW_ATTRASGN(recv, tASET, idx);
} }
ID ID

View file

@ -123,6 +123,7 @@ r_lt(a, b)
{ {
VALUE r = rb_funcall(a, id_cmp, 1, b); VALUE r = rb_funcall(a, id_cmp, 1, b);
if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) < 0) return Qtrue; if (rb_cmpint(r) < 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -133,16 +134,19 @@ r_le(a, b)
{ {
VALUE r = rb_funcall(a, id_cmp, 1, b); VALUE r = rb_funcall(a, id_cmp, 1, b);
if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) <= 0) return Qtrue; if (rb_cmpint(r) <= 0) return Qtrue;
return Qfalse; return Qfalse;
} }
static int static int
r_gt(a,b) r_gt(a,b)
VALUE a, b; VALUE a, b;
{ {
VALUE r = rb_funcall(a, id_cmp, 1, b); VALUE r = rb_funcall(a, id_cmp, 1, b);
if (NIL_P(r)) return Qfalse;
if (rb_cmpint(r) > 0) return Qtrue; if (rb_cmpint(r) > 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -474,13 +478,14 @@ range_include(range, val)
beg = rb_ivar_get(range, id_beg); beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end); end = rb_ivar_get(range, id_end);
if (r_gt(beg, val)) return Qfalse; if (r_le(beg, val)) {
if (EXCL(range)) { if (EXCL(range)) {
if (r_lt(val, end)) return Qtrue; if (r_lt(val, end)) return Qtrue;
} }
else { else {
if (r_le(val, end)) return Qtrue; if (r_le(val, end)) return Qtrue;
} }
}
return Qfalse; return Qfalse;
} }

23
re.c
View file

@ -1109,6 +1109,27 @@ rb_reg_match(re, str)
return LONG2FIX(start); return LONG2FIX(start);
} }
VALUE
rb_reg_eqq(re, str)
VALUE re, str;
{
long start;
if (TYPE(str) != T_STRING) {
str = rb_check_string_type(str);
if (NIL_P(str)) {
rb_backref_set(Qnil);
return Qfalse;
}
}
StringValue(str);
start = rb_reg_search(re, str, 0, 0);
if (start < 0) {
return Qfalse;
}
return Qtrue;
}
VALUE VALUE
rb_reg_match2(re) rb_reg_match2(re)
VALUE re; VALUE re;
@ -1583,7 +1604,7 @@ Init_Regexp()
rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1); rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1); rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1); rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
rb_define_method(rb_cRegexp, "===", rb_reg_match, 1); rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0); rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
rb_define_method(rb_cRegexp, "match", rb_reg_match_m, 1); rb_define_method(rb_cRegexp, "match", rb_reg_match_m, 1);
rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0); rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);

View file

@ -234,7 +234,7 @@ rb_f_kill(argc, argv)
{ {
VALUE str; VALUE str;
str = rb_check_convert_type(argv[0], T_STRING, "String", "to_str"); str = rb_check_string_type(argv[0]);
if (!NIL_P(str)) { if (!NIL_P(str)) {
s = RSTRING(str)->ptr; s = RSTRING(str)->ptr;
goto str_signal; goto str_signal;

View file

@ -468,6 +468,13 @@ rb_string_value_ptr(ptr)
return RSTRING(s)->ptr; return RSTRING(s)->ptr;
} }
VALUE
rb_check_string_type(str)
VALUE str;
{
return rb_check_convert_type(str, T_STRING, "String", "to_str");
}
VALUE VALUE
rb_str_substr(str, beg, len) rb_str_substr(str, beg, len)
VALUE str; VALUE str;
@ -763,7 +770,7 @@ rb_str_equal(str1, str2)
{ {
if (str1 == str2) return Qtrue; if (str1 == str2) return Qtrue;
if (TYPE(str2) != T_STRING) { if (TYPE(str2) != T_STRING) {
str2 = rb_check_convert_type(str2, T_STRING, "String", "to_str"); str2 = rb_check_string_type(str2);
if (NIL_P(str2)) return Qfalse; if (NIL_P(str2)) return Qfalse;
} }
@ -794,7 +801,10 @@ rb_str_cmp_m(str1, str2)
{ {
int result; int result;
StringValue(str2); if (TYPE(str2) != T_STRING) {
str2 = rb_check_string_type(str2);
if (NIL_P(str2)) return Qnil;
}
result = rb_str_cmp(str1, str2); result = rb_str_cmp(str1, str2);
return INT2FIX(result); return INT2FIX(result);
} }
@ -1428,7 +1438,7 @@ get_pat(pat, quote)
break; break;
default: default:
val = rb_check_convert_type(pat, T_STRING, "String", "to_str"); val = rb_check_string_type(pat);
if (NIL_P(val)) { if (NIL_P(val)) {
Check_Type(pat, T_REGEXP); Check_Type(pat, T_REGEXP);
} }

View file

@ -816,11 +816,15 @@ generic_ivar_get(obj, id)
st_table *tbl; st_table *tbl;
VALUE val; VALUE val;
if (!generic_iv_tbl) return Qnil; if (generic_iv_tbl) {
if (!st_lookup(generic_iv_tbl, obj, &tbl)) return Qnil; if (st_lookup(generic_iv_tbl, obj, &tbl)) {
if (st_lookup(tbl, id, &val)) { if (st_lookup(tbl, id, &val)) {
return val; return val;
} }
}
}
rb_warning("instance variable %s not initialized", rb_id2name(id));
return Qnil; return Qnil;
} }