From 8e6e8e628888aa251f771ce8b3fe30a6b41a7a0e Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 29 Sep 2011 11:07:45 +0000 Subject: [PATCH] * use RB_TYPE_P which is optimized for constant types, instead of comparison with TYPE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 8 ++++---- bignum.c | 16 ++++++++-------- class.c | 20 ++++++++++---------- compile.c | 8 ++++---- complex.c | 10 +++++----- enum.c | 2 +- enumerator.c | 2 +- error.c | 2 +- eval.c | 2 +- eval_error.c | 4 ++-- gc.c | 4 ++-- hash.c | 4 ++-- io.c | 24 ++++++++++++------------ marshal.c | 18 +++++++++--------- math.c | 2 +- numeric.c | 10 +++++----- object.c | 12 ++++++------ pack.c | 6 +++--- parse.y | 2 +- proc.c | 6 +++--- process.c | 6 +++--- random.c | 4 ++-- range.c | 6 +++--- rational.c | 10 +++++----- re.c | 6 +++--- ruby.c | 2 +- safe.c | 2 +- string.c | 26 +++++++++++++------------- struct.c | 12 ++++++------ thread.c | 14 +++++++------- time.c | 32 ++++++++++++++++---------------- transcode.c | 8 ++++---- variable.c | 6 +++--- vm_eval.c | 8 ++++---- vm_insnhelper.c | 6 +++--- vm_method.c | 8 ++++---- 37 files changed, 164 insertions(+), 159 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1de50783829a48..63f60a1e324933 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Sep 29 20:07:36 2011 Nobuyoshi Nakada + + * use RB_TYPE_P which is optimized for constant types, instead of + comparison with TYPE. + Wed Sep 28 09:20:37 2011 Nobuyoshi Nakada * configure.in (pthread_np.h): needs pthread.h to be included diff --git a/array.c b/array.c index 8caad66a3e10cb..82013df69d067e 100644 --- a/array.c +++ b/array.c @@ -2016,7 +2016,7 @@ enum { sort_optimizable_count }; -#define STRING_P(s) (TYPE(s) == T_STRING && CLASS_OF(s) == rb_cString) +#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString) #define SORT_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(sort_opt_,type)) #define SORT_OPTIMIZABLE(data, type) \ @@ -3137,7 +3137,7 @@ rb_ary_rassoc(VALUE ary, VALUE value) for (i = 0; i < RARRAY_LEN(ary); ++i) { v = RARRAY_PTR(ary)[i]; - if (TYPE(v) == T_ARRAY && + if (RB_TYPE_P(v, T_ARRAY) && RARRAY_LEN(v) > 1 && rb_equal(RARRAY_PTR(v)[1], value)) return v; @@ -3176,7 +3176,7 @@ static VALUE rb_ary_equal(VALUE ary1, VALUE ary2) { if (ary1 == ary2) return Qtrue; - if (TYPE(ary2) != T_ARRAY) { + if (!RB_TYPE_P(ary2, T_ARRAY)) { if (!rb_respond_to(ary2, rb_intern("to_ary"))) { return Qfalse; } @@ -3211,7 +3211,7 @@ static VALUE rb_ary_eql(VALUE ary1, VALUE ary2) { if (ary1 == ary2) return Qtrue; - if (TYPE(ary2) != T_ARRAY) return Qfalse; + if (!RB_TYPE_P(ary2, T_ARRAY)) return Qfalse; if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse; return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2); } diff --git a/bignum.c b/bignum.c index 65e82d4e0f39e9..a618caeb37d11c 100644 --- a/bignum.c +++ b/bignum.c @@ -101,7 +101,7 @@ rb_cmpint(VALUE val, VALUE a, VALUE b) if (l < 0) return -1; return 0; } - if (TYPE(val) == T_BIGNUM) { + if (RB_TYPE_P(val, T_BIGNUM)) { if (BIGZEROP(val)) return 0; if (RBIGNUM_SIGN(val)) return 1; return -1; @@ -269,7 +269,7 @@ bigfixize(VALUE x) static VALUE bignorm(VALUE x) { - if (!FIXNUM_P(x) && TYPE(x) == T_BIGNUM) { + if (RB_TYPE_P(x, T_BIGNUM)) { x = bigfixize(bigtrunc(x)); } return x; @@ -1628,7 +1628,7 @@ rb_big_eq(VALUE x, VALUE y) static VALUE rb_big_eql(VALUE x, VALUE y) { - if (TYPE(y) != T_BIGNUM) return Qfalse; + if (!RB_TYPE_P(y, T_BIGNUM)) return Qfalse; if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y)) return Qfalse; if (RBIGNUM_LEN(x) != RBIGNUM_LEN(y)) return Qfalse; if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM_LEN(y)) != 0) return Qfalse; @@ -3107,7 +3107,7 @@ rb_big_pow(VALUE x, VALUE y) static inline VALUE bit_coerce(VALUE x) { - while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) { + while (!FIXNUM_P(x) && !RB_TYPE_P(x, T_BIGNUM)) { rb_raise(rb_eTypeError, "can't convert %s into Integer for bitwise arithmetic", rb_obj_classname(x)); @@ -3434,7 +3434,7 @@ rb_big_lshift(VALUE x, VALUE y) } break; } - else if (TYPE(y) == T_BIGNUM) { + else if (RB_TYPE_P(y, T_BIGNUM)) { if (!RBIGNUM_SIGN(y)) { VALUE t = check_shiftdown(y, x); if (!NIL_P(t)) return t; @@ -3498,7 +3498,7 @@ rb_big_rshift(VALUE x, VALUE y) } break; } - else if (TYPE(y) == T_BIGNUM) { + else if (RB_TYPE_P(y, T_BIGNUM)) { if (RBIGNUM_SIGN(y)) { VALUE t = check_shiftdown(y, x); if (!NIL_P(t)) return t; @@ -3586,7 +3586,7 @@ rb_big_aref(VALUE x, VALUE y) VALUE shift; long i, s1, s2; - if (TYPE(y) == T_BIGNUM) { + if (RB_TYPE_P(y, T_BIGNUM)) { if (!RBIGNUM_SIGN(y)) return INT2FIX(0); bigtrunc(y); @@ -3646,7 +3646,7 @@ rb_big_coerce(VALUE x, VALUE y) if (FIXNUM_P(y)) { return rb_assoc_new(rb_int2big(FIX2LONG(y)), x); } - else if (TYPE(y) == T_BIGNUM) { + else if (RB_TYPE_P(y, T_BIGNUM)) { return rb_assoc_new(y, x); } else { diff --git a/class.c b/class.c index d4273930812f37..e6c1f8fd110000 100644 --- a/class.c +++ b/class.c @@ -93,7 +93,7 @@ rb_class_boot(VALUE super) void rb_check_inheritable(VALUE super) { - if (TYPE(super) != T_CLASS) { + if (!RB_TYPE_P(super, T_CLASS)) { rb_raise(rb_eTypeError, "superclass must be a Class (%s given)", rb_obj_classname(super)); } @@ -463,7 +463,7 @@ rb_define_class(const char *name, VALUE super) id = rb_intern(name); if (rb_const_defined(rb_cObject, id)) { klass = rb_const_get(rb_cObject, id); - if (TYPE(klass) != T_CLASS) { + if (!RB_TYPE_P(klass, T_CLASS)) { rb_raise(rb_eTypeError, "%s is not a class", name); } if (rb_class_real(RCLASS_SUPER(klass)) != super) { @@ -530,7 +530,7 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super) if (rb_const_defined_at(outer, id)) { klass = rb_const_get_at(outer, id); - if (TYPE(klass) != T_CLASS) { + if (!RB_TYPE_P(klass, T_CLASS)) { rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id)); } if (rb_class_real(RCLASS_SUPER(klass)) != super) { @@ -581,7 +581,7 @@ rb_define_module(const char *name) id = rb_intern(name); if (rb_const_defined(rb_cObject, id)) { module = rb_const_get(rb_cObject, id); - if (TYPE(module) == T_MODULE) + if (RB_TYPE_P(module, T_MODULE)) return module; rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module)); } @@ -605,7 +605,7 @@ rb_define_module_id_under(VALUE outer, ID id) if (rb_const_defined_at(outer, id)) { module = rb_const_get_at(outer, id); - if (TYPE(module) == T_MODULE) + if (RB_TYPE_P(module, T_MODULE)) return module; rb_raise(rb_eTypeError, "%s::%s is not a module", rb_class2name(outer), rb_obj_classname(module)); @@ -636,7 +636,7 @@ include_class_new(VALUE module, VALUE super) RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module); RCLASS_M_TBL(klass) = RCLASS_M_TBL(module); RCLASS_SUPER(klass) = super; - if (TYPE(module) == T_ICLASS) { + if (RB_TYPE_P(module, T_ICLASS)) { RBASIC(klass)->klass = RBASIC(module)->klass; } else { @@ -659,7 +659,7 @@ rb_include_module(VALUE klass, VALUE module) rb_secure(4); } - if (TYPE(module) != T_MODULE) { + if (!RB_TYPE_P(module, T_MODULE)) { Check_Type(module, T_MODULE); } @@ -791,7 +791,7 @@ rb_mix_module(VALUE klass, VALUE module, st_table *constants, st_table *methods) rb_secure(4); } - if (TYPE(module) != T_MODULE) { + if (!RB_TYPE_P(module, T_MODULE)) { Check_Type(module, T_MODULE); } @@ -1248,7 +1248,7 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj) klass = RCLASS_SUPER(klass); } if (RTEST(recur)) { - while (klass && (FL_TEST(klass, FL_SINGLETON) || TYPE(klass) == T_ICLASS)) { + while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) { st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list); klass = RCLASS_SUPER(klass); } @@ -1435,7 +1435,7 @@ rb_singleton_class(VALUE obj) VALUE klass = singleton_class_of(obj); /* ensures an exposed class belongs to its own eigenclass */ - if (TYPE(obj) == T_CLASS) (void)ENSURE_EIGENCLASS(klass); + if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass); return klass; } diff --git a/compile.c b/compile.c index fd800a88408ccb..81d87be47e6ead 100644 --- a/compile.c +++ b/compile.c @@ -1263,7 +1263,7 @@ static st_index_t cdhash_hash(VALUE a) { if (SPECIAL_CONST_P(a)) return (st_index_t)a; - if (TYPE(a) == T_STRING) return rb_str_hash(a); + if (RB_TYPE_P(a, T_STRING)) return rb_str_hash(a); { VALUE hval = rb_hash(a); return (st_index_t)FIX2LONG(hval); @@ -2335,7 +2335,7 @@ case_when_optimizable_literal(NODE * node) case NODE_LIT: { VALUE v = node->nd_lit; double ival; - if (TYPE(v) == T_FLOAT && + if (RB_TYPE_P(v, T_FLOAT) && modf(RFLOAT_VALUE(v), &ival) == 0.0) { return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival); } @@ -5314,7 +5314,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor, else if (FIXNUM_P(obj)) { line_no = NUM2INT(obj); } - else if (TYPE(obj) == T_ARRAY) { + else if (RB_TYPE_P(obj, T_ARRAY)) { VALUE *argv = 0; int argc = RARRAY_LENINT(obj) - 1; st_data_t insn_id; @@ -5356,7 +5356,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor, case TS_ISEQ: { if (op != Qnil) { - if (TYPE(op) == T_ARRAY) { + if (RB_TYPE_P(op, T_ARRAY)) { argv[j] = rb_iseq_load(op, iseq->self, Qnil); } else if (CLASS_OF(op) == rb_cISeq) { diff --git a/complex.c b/complex.c index a701129b730562..fd0088c57465cb 100644 --- a/complex.c +++ b/complex.c @@ -121,7 +121,7 @@ f_mul(VALUE x, VALUE y) if (FIXNUM_P(y)) { long iy = FIX2LONG(y); if (iy == 0) { - if (FIXNUM_P(x) || TYPE(x) == T_BIGNUM) + if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) return ZERO; } else if (iy == 1) @@ -130,7 +130,7 @@ f_mul(VALUE x, VALUE y) else if (FIXNUM_P(x)) { long ix = FIX2LONG(x); if (ix == 0) { - if (FIXNUM_P(y) || TYPE(y) == T_BIGNUM) + if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM)) return ZERO; } else if (ix == 1) @@ -166,14 +166,14 @@ fun1(real_p) inline static VALUE f_to_i(VALUE x) { - if (TYPE(x) == T_STRING) + if (RB_TYPE_P(x, T_STRING)) return rb_str_to_inum(x, 10, 0); return rb_funcall(x, id_to_i, 0); } inline static VALUE f_to_f(VALUE x) { - if (TYPE(x) == T_STRING) + if (RB_TYPE_P(x, T_STRING)) return DBL2NUM(rb_str_to_dbl(x, 0)); return rb_funcall(x, id_to_f, 0); } @@ -944,7 +944,7 @@ nucomp_coerce(VALUE self, VALUE other) { if (k_numeric_p(other) && f_real_p(other)) return rb_assoc_new(f_complex_new_bang1(CLASS_OF(self), other), self); - if (TYPE(other) == T_COMPLEX) + if (RB_TYPE_P(other, T_COMPLEX)) return rb_assoc_new(other, self); rb_raise(rb_eTypeError, "%s can't be coerced into %s", diff --git a/enum.c b/enum.c index b9d34d8c03d22c..77ecd2fa563c9d 100644 --- a/enum.c +++ b/enum.c @@ -901,7 +901,7 @@ enum_sort_by(VALUE obj) RETURN_ENUMERATOR(obj, 0, 0); - if (TYPE(obj) == T_ARRAY && RARRAY_LEN(obj) <= LONG_MAX/2) { + if (RB_TYPE_P(obj, T_ARRAY) && RARRAY_LEN(obj) <= LONG_MAX/2) { ary = rb_ary_new2(RARRAY_LEN(obj)*2); } else { diff --git a/enumerator.c b/enumerator.c index 8b1add254a5cd0..b7561482e5aa17 100644 --- a/enumerator.c +++ b/enumerator.c @@ -590,7 +590,7 @@ enumerator_next_values(VALUE obj) static VALUE ary2sv(VALUE args, int dup) { - if (TYPE(args) != T_ARRAY) + if (!RB_TYPE_P(args, T_ARRAY)) return args; switch (RARRAY_LEN(args)) { diff --git a/error.c b/error.c index 646fb1623268be..8bf33e65ad031c 100644 --- a/error.c +++ b/error.c @@ -1134,7 +1134,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self) if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) { klass = (VALUE)data; /* change class */ - if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */ + if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */ rb_raise(rb_eTypeError, "invalid instance type"); } RBASIC(self)->klass = klass; diff --git a/eval.c b/eval.c index 87f1f61ec35219..ddbe31a47751ae 100644 --- a/eval.c +++ b/eval.c @@ -169,7 +169,7 @@ ruby_cleanup(volatile int ex) if (!RTEST(err)) continue; /* th->errinfo contains a NODE while break'ing */ - if (TYPE(err) == T_NODE) continue; + if (RB_TYPE_P(err, T_NODE)) continue; if (rb_obj_is_kind_of(err, rb_eSystemExit)) { ex = sysexit_status(err); diff --git a/eval_error.c b/eval_error.c index e2763ad1d6e756..cf3961cb33d578 100644 --- a/eval_error.c +++ b/eval_error.c @@ -202,7 +202,7 @@ rb_print_undef(VALUE klass, ID id, int scope) } rb_name_error(id, "undefined%s method `%s' for %s `%s'", v, rb_id2name(id), - (TYPE(klass) == T_MODULE) ? "module" : "class", + (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", rb_class2name(klass)); } @@ -211,7 +211,7 @@ rb_print_undef_str(VALUE klass, VALUE name) { rb_name_error_str(name, "undefined method `%s' for %s `%s'", RSTRING_PTR(name), - (TYPE(klass) == T_MODULE) ? "module" : "class", + (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", rb_class2name(klass)); } diff --git a/gc.c b/gc.c index b79dcac4819276..22d56ac49ece7a 100644 --- a/gc.c +++ b/gc.c @@ -3265,7 +3265,7 @@ count_objects(int argc, VALUE *argv, VALUE os) VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { - if (TYPE(hash) != T_HASH) + if (!RB_TYPE_P(hash, T_HASH)) rb_raise(rb_eTypeError, "non-hash given"); } @@ -3384,7 +3384,7 @@ gc_stat(int argc, VALUE *argv, VALUE self) VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { - if (TYPE(hash) != T_HASH) + if (!RB_TYPE_P(hash, T_HASH)) rb_raise(rb_eTypeError, "non-hash given"); } diff --git a/hash.c b/hash.c index fbd82374eb3db8..a6096f08d43d60 100644 --- a/hash.c +++ b/hash.c @@ -44,7 +44,7 @@ rb_any_cmp(VALUE a, VALUE b) if (FIXNUM_P(a) && FIXNUM_P(b)) { return a != b; } - if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString && + if (RB_TYPE_P(a, T_STRING) && RBASIC(a)->klass == rb_cString && TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) { return rb_str_hash_cmp(a, b); } @@ -1599,7 +1599,7 @@ hash_equal(VALUE hash1, VALUE hash2, int eql) struct equal_data data; if (hash1 == hash2) return Qtrue; - if (TYPE(hash2) != T_HASH) { + if (!RB_TYPE_P(hash2, T_HASH)) { if (!rb_respond_to(hash2, rb_intern("to_hash"))) { return Qfalse; } diff --git a/io.c b/io.c index b3bd0ce52b874e..6bade4547f69e8 100644 --- a/io.c +++ b/io.c @@ -1053,7 +1053,7 @@ rb_io_flush(VALUE io) { rb_io_t *fptr; - if (TYPE(io) != T_FILE) { + if (!RB_TYPE_P(io, T_FILE)) { return rb_funcall(io, id_flush, 0); } @@ -2117,7 +2117,7 @@ rb_io_write_nonblock(VALUE io, VALUE str) long n; rb_secure(4); - if (TYPE(str) != T_STRING) + if (!RB_TYPE_P(str, T_STRING)) str = rb_obj_as_string(str); io = GetWriteIO(io); @@ -3144,7 +3144,7 @@ rb_io_getbyte(VALUE io) GetOpenFile(io, fptr); rb_io_check_byte_readable(fptr); READ_CHECK(fptr); - if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) { + if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && RB_TYPE_P(rb_stdout, T_FILE)) { rb_io_t *ofp; GetOpenFile(rb_stdout, ofp); if (ofp->mode & FMODE_TTY) { @@ -3243,7 +3243,7 @@ rb_io_ungetc(VALUE io, VALUE c) if (FIXNUM_P(c)) { c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr)); } - else if (TYPE(c) == T_BIGNUM) { + else if (RB_TYPE_P(c, T_BIGNUM)) { c = rb_enc_uint_chr(NUM2UINT(c), io_read_encoding(fptr)); } else { @@ -3886,7 +3886,7 @@ rb_io_syswrite(VALUE io, VALUE str) long n; rb_secure(4); - if (TYPE(str) != T_STRING) + if (!RB_TYPE_P(str, T_STRING)) str = rb_obj_as_string(str); io = GetWriteIO(io); @@ -6113,7 +6113,7 @@ static VALUE rb_io_putc(VALUE io, VALUE ch) { VALUE str; - if (TYPE(ch) == T_STRING) { + if (RB_TYPE_P(ch, T_STRING)) { str = rb_str_substr(ch, 0, 1); } else { @@ -6254,7 +6254,7 @@ void rb_p(VALUE obj) /* for debug print within C code */ { VALUE str = rb_obj_as_string(rb_inspect(obj)); - if (TYPE(rb_stdout) == T_FILE && + if (RB_TYPE_P(rb_stdout, T_FILE) && rb_method_basic_definition_p(CLASS_OF(rb_stdout), id_write)) { io_write(rb_stdout, str, 1); io_write(rb_stdout, rb_default_rs, 0); @@ -6298,7 +6298,7 @@ rb_f_p(int argc, VALUE *argv, VALUE self) else if (argc > 1) { ret = rb_ary_new4(argc, argv); } - if (TYPE(rb_stdout) == T_FILE) { + if (RB_TYPE_P(rb_stdout, T_FILE)) { rb_io_flush(rb_stdout); } return ret; @@ -6845,7 +6845,7 @@ argf_next_argv(VALUE argf) int stdout_binmode = 0; int fmode; - if (TYPE(rb_stdout) == T_FILE) { + if (RB_TYPE_P(rb_stdout, T_FILE)) { GetOpenFile(rb_stdout, fptr); if (fptr->mode & FMODE_BINMODE) stdout_binmode = 1; @@ -6885,7 +6885,7 @@ argf_next_argv(VALUE argf) VALUE str; int fw; - if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) { + if (RB_TYPE_P(rb_stdout, T_FILE) && rb_stdout != orig_stdout) { rb_io_close(rb_stdout); } fstat(fr, &st); @@ -7770,7 +7770,7 @@ rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p) GetOpenFile(io, fptr); retval = io_cntl(fptr->fd, cmd, narg, io_p); if (retval < 0) rb_sys_fail_path(fptr->pathv); - if (TYPE(arg) == T_STRING && RSTRING_PTR(arg)[len] != 17) { + if (RB_TYPE_P(arg, T_STRING) && RSTRING_PTR(arg)[len] != 17) { rb_raise(rb_eArgError, "return value overflowed string"); } @@ -9269,7 +9269,7 @@ rb_io_set_encoding(int argc, VALUE *argv, VALUE io) rb_io_t *fptr; VALUE v1, v2, opt; - if (TYPE(io) != T_FILE) { + if (!RB_TYPE_P(io, T_FILE)) { return rb_funcall2(io, id_set_encoding, argc, argv); } diff --git a/marshal.c b/marshal.c index 9a43cdb4d10eae..d286aaa7c829f6 100644 --- a/marshal.c +++ b/marshal.c @@ -210,7 +210,7 @@ class2path(VALUE klass) VALUE path = rb_class_path(klass); const char *n; - n = must_not_be_anonymous((TYPE(klass) == T_CLASS ? "class" : "module"), path); + n = must_not_be_anonymous((RB_TYPE_P(klass, T_CLASS) ? "class" : "module"), path); if (rb_path_to_class(path) != rb_class_real(klass)) { rb_raise(rb_eTypeError, "%s can't be referred to", n); } @@ -656,7 +656,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit) v = rb_funcall(obj, s_dump, 1, INT2NUM(limit)); check_dump_arg(arg, s_dump); - if (TYPE(v) != T_STRING) { + if (!RB_TYPE_P(v, T_STRING)) { rb_raise(rb_eTypeError, "_dump() must return string"); } hasiv = has_ivars(obj, ivtbl); @@ -1271,7 +1271,7 @@ path2class(VALUE path) { VALUE v = rb_path_to_class(path); - if (TYPE(v) != T_CLASS) { + if (!RB_TYPE_P(v, T_CLASS)) { rb_raise(rb_eArgError, "%.*s does not refer to class", (int)RSTRING_LEN(path), RSTRING_PTR(path)); } @@ -1283,7 +1283,7 @@ path2module(VALUE path) { VALUE v = rb_path_to_class(path); - if (TYPE(v) != T_MODULE) { + if (!RB_TYPE_P(v, T_MODULE)) { rb_raise(rb_eArgError, "%.*s does not refer to module", (int)RSTRING_LEN(path), RSTRING_PTR(path)); } @@ -1364,11 +1364,11 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) rb_raise(rb_eTypeError, "singleton can't be loaded"); } v = r_object0(arg, 0, extmod); - if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) { + if (rb_special_const_p(v) || RB_TYPE_P(v, T_OBJECT) || RB_TYPE_P(v, T_CLASS)) { format_error: rb_raise(rb_eArgError, "dump format error (user class)"); } - if (TYPE(v) == T_MODULE || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) { + if (RB_TYPE_P(v, T_MODULE) || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) { VALUE tmp = rb_obj_alloc(c); if (TYPE(v) != TYPE(tmp)) goto format_error; @@ -1554,7 +1554,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) long len = r_long(arg); v = rb_obj_alloc(klass); - if (TYPE(v) != T_STRUCT) { + if (!RB_TYPE_P(v, T_STRUCT)) { rb_raise(rb_eTypeError, "class %s not a struct", rb_class2name(klass)); } mem = rb_struct_s_members(klass); @@ -1630,7 +1630,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) { st_index_t idx = r_prepare(arg); v = obj_alloc_by_path(r_unique(arg), arg); - if (TYPE(v) != T_OBJECT) { + if (!RB_TYPE_P(v, T_OBJECT)) { rb_raise(rb_eArgError, "dump format error"); } v = r_entry0(v, idx, arg); @@ -1654,7 +1654,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod) else { v = rb_obj_alloc(klass); } - if (TYPE(v) != T_DATA) { + if (!RB_TYPE_P(v, T_DATA)) { rb_raise(rb_eArgError, "dump format error"); } v = r_entry(v, arg); diff --git a/math.c b/math.c index 276b2cbc4988d1..e9e1678dc6ffb6 100644 --- a/math.c +++ b/math.c @@ -24,7 +24,7 @@ VALUE rb_mMath; VALUE rb_eMathDomainError; -#define Need_Float(x) do {if (TYPE(x) != T_FLOAT) {(x) = rb_to_float(x);}} while(0) +#define Need_Float(x) do {if (!RB_TYPE_P(x, T_FLOAT)) {(x) = rb_to_float(x);}} while(0) #define Need_Float2(x,y) do {\ Need_Float(x);\ Need_Float(y);\ diff --git a/numeric.c b/numeric.c index 18f5e1cd1a64fe..6d3c1432e842e8 100644 --- a/numeric.c +++ b/numeric.c @@ -204,7 +204,7 @@ do_coerce(VALUE *x, VALUE *y, int err) a[0] = *x; a[1] = *y; ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a); - if (TYPE(ary) != T_ARRAY || RARRAY_LEN(ary) != 2) { + if (!RB_TYPE_P(ary, T_ARRAY) || RARRAY_LEN(ary) != 2) { if (err) { rb_raise(rb_eTypeError, "coerce must return [x, y]"); } @@ -1272,7 +1272,7 @@ flo_le(VALUE x, VALUE y) static VALUE flo_eql(VALUE x, VALUE y) { - if (TYPE(y) == T_FLOAT) { + if (RB_TYPE_P(y, T_FLOAT)) { double a = RFLOAT_VALUE(x); double b = RFLOAT_VALUE(y); #if defined(_MSC_VER) && _MSC_VER < 1300 @@ -1480,7 +1480,7 @@ int_round_0(VALUE num, int ndigits) if (neg) x = -x; return LONG2NUM(x); } - if (TYPE(f) == T_FLOAT) { + if (RB_TYPE_P(f, T_FLOAT)) { /* then int_pow overflow */ return INT2FIX(0); } @@ -1676,7 +1676,7 @@ num_truncate(VALUE num) int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl) { - if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) { + if (RB_TYPE_P(from, T_FLOAT) || RB_TYPE_P(to, T_FLOAT) || RB_TYPE_P(step, T_FLOAT)) { const double epsilon = DBL_EPSILON; double beg = NUM2DBL(from); double end = NUM2DBL(to); @@ -2960,7 +2960,7 @@ fix_rev(VALUE num) static VALUE bit_coerce(VALUE x) { - while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) { + while (!FIXNUM_P(x) && !RB_TYPE_P(x, T_BIGNUM)) { rb_raise(rb_eTypeError, "can't convert %s into Integer for bitwise arithmetic", rb_obj_classname(x)); diff --git a/object.c b/object.c index 3a7265b31d5934..23c18edb33f71a 100644 --- a/object.c +++ b/object.c @@ -432,7 +432,7 @@ inspect_obj(VALUE obj, VALUE str, int recur) static VALUE rb_obj_inspect(VALUE obj) { - if (TYPE(obj) == T_OBJECT && rb_obj_basic_to_s_p(obj)) { + if (RB_TYPE_P(obj, T_OBJECT) && rb_obj_basic_to_s_p(obj)) { int has_ivar = 0; VALUE *ptr = ROBJECT_IVPTR(obj); long len = ROBJECT_NUMIV(obj); @@ -1661,7 +1661,7 @@ rb_class_superclass(VALUE klass) if (klass == rb_cBasicObject) return Qnil; rb_raise(rb_eTypeError, "uninitialized class"); } - while (TYPE(super) == T_ICLASS) { + while (RB_TYPE_P(super, T_ICLASS)) { super = RCLASS_SUPER(super); } if (!super) { @@ -2157,7 +2157,7 @@ rb_to_integer(VALUE val, const char *method) VALUE v; if (FIXNUM_P(val)) return val; - if (TYPE(val) == T_BIGNUM) return val; + if (RB_TYPE_P(val, T_BIGNUM)) return val; v = convert_type(val, "Integer", method, TRUE); if (!rb_obj_is_kind_of(v, rb_cInteger)) { const char *cname = rb_obj_classname(val); @@ -2173,7 +2173,7 @@ rb_check_to_integer(VALUE val, const char *method) VALUE v; if (FIXNUM_P(val)) return val; - if (TYPE(val) == T_BIGNUM) return val; + if (RB_TYPE_P(val, T_BIGNUM)) return val; v = convert_type(val, "Integer", method, FALSE); if (!rb_obj_is_kind_of(v, rb_cInteger)) { return Qnil; @@ -2437,7 +2437,7 @@ rb_f_float(VALUE obj, VALUE arg) VALUE rb_to_float(VALUE val) { - if (TYPE(val) == T_FLOAT) return val; + if (RB_TYPE_P(val, T_FLOAT)) return val; if (!rb_obj_is_kind_of(val, rb_cNumeric)) { rb_raise(rb_eTypeError, "can't convert %s into Float", NIL_P(val) ? "nil" : @@ -2451,7 +2451,7 @@ rb_to_float(VALUE val) VALUE rb_check_to_float(VALUE val) { - if (TYPE(val) == T_FLOAT) return val; + if (RB_TYPE_P(val, T_FLOAT)) return val; if (!rb_obj_is_kind_of(val, rb_cNumeric)) { return Qnil; } diff --git a/pack.c b/pack.c index 1616a8a6385f58..d22a80a9be2104 100644 --- a/pack.c +++ b/pack.c @@ -243,7 +243,7 @@ num2i32(VALUE x) x = rb_to_int(x); /* is nil OK? (should not) */ if (FIXNUM_P(x)) return FIX2LONG(x); - if (TYPE(x) == T_BIGNUM) { + if (RB_TYPE_P(x, T_BIGNUM)) { return rb_big2ulong_pack(x); } rb_raise(rb_eTypeError, "can't convert %s to `integer'", rb_obj_classname(x)); @@ -995,9 +995,9 @@ pack_pack(VALUE ary, VALUE fmt) char c, *bufs, *bufe; from = NEXTFROM; - if (TYPE(from) == T_BIGNUM) { + if (RB_TYPE_P(from, T_BIGNUM)) { VALUE big128 = rb_uint2big(128); - while (TYPE(from) == T_BIGNUM) { + while (RB_TYPE_P(from, T_BIGNUM)) { from = rb_big_divmod(from, big128); c = NUM2INT(RARRAY_PTR(from)[1]) | 0x80; /* mod */ rb_str_buf_cat(buf, &c, sizeof(char)); diff --git a/parse.y b/parse.y index ab17534b36c670..437f534f1df2c2 100644 --- a/parse.y +++ b/parse.y @@ -5152,7 +5152,7 @@ debug_lines(const char *f) CONST_ID(script_lines, "SCRIPT_LINES__"); if (rb_const_defined_at(rb_cObject, script_lines)) { VALUE hash = rb_const_get_at(rb_cObject, script_lines); - if (TYPE(hash) == T_HASH) { + if (RB_TYPE_P(hash, T_HASH)) { VALUE fname = rb_str_new2(f); VALUE lines = rb_ary_new(); rb_hash_aset(hash, fname, lines); diff --git a/proc.c b/proc.c index 68ea1d4b6d16c0..8a19a88a2c1f8b 100644 --- a/proc.c +++ b/proc.c @@ -951,7 +951,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) } rb_name_error(id, "method `%s' for %s `%s' is %s", rb_id2name(id), - (TYPE(klass) == T_MODULE) ? "module" : "class", + (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", rb_class2name(klass), v); } @@ -965,11 +965,11 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) klass = me->klass; while (rclass != klass && - (FL_TEST(rclass, FL_SINGLETON) || TYPE(rclass) == T_ICLASS)) { + (FL_TEST(rclass, FL_SINGLETON) || RB_TYPE_P(rclass, T_ICLASS))) { rclass = RCLASS_SUPER(rclass); } - if (TYPE(klass) == T_ICLASS) { + if (RB_TYPE_P(klass, T_ICLASS)) { klass = RBASIC(klass)->klass; } diff --git a/process.c b/process.c index c3d42ffd4ebe5f..a2cd4c6867e12c 100644 --- a/process.c +++ b/process.c @@ -1418,7 +1418,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) flags = rb_ary_entry(val, 1); if (NIL_P(flags)) flags = INT2NUM(O_RDONLY); - else if (TYPE(flags) == T_STRING) + else if (RB_TYPE_P(flags, T_STRING)) flags = INT2NUM(rb_io_modestr_oflags(StringValueCStr(flags))); else flags = rb_to_int(flags); @@ -1433,7 +1433,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) index = EXEC_OPTION_OPEN; path = val; FilePathValue(path); - if (TYPE(key) == T_FILE) + if (RB_TYPE_P(key, T_FILE)) key = check_exec_redirect_fd(key, 1); if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2)) flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC); @@ -1453,7 +1453,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options) ary = hide_obj(rb_ary_new()); rb_ary_store(options, index, ary); } - if (TYPE(key) != T_ARRAY) { + if (!RB_TYPE_P(key, T_ARRAY)) { VALUE fd = check_exec_redirect_fd(key, !NIL_P(param)); rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param))); } diff --git a/random.c b/random.c index 192110a85031d7..ebb4a60de0305b 100644 --- a/random.c +++ b/random.c @@ -1035,7 +1035,7 @@ rand_range(struct MT* mt, VALUE range) if ((v = vmax = range_values(range, &beg, &end, &excl)) == Qfalse) return Qfalse; - if (TYPE(vmax) != T_FLOAT && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) { + if (!RB_TYPE_P(vmax, T_FLOAT) && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) { long max; vmax = v; v = Qnil; @@ -1149,7 +1149,7 @@ random_rand(int argc, VALUE *argv, VALUE obj) if (NIL_P(vmax)) { v = Qnil; } - else if (TYPE(vmax) != T_FLOAT && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) { + else if (!RB_TYPE_P(vmax, T_FLOAT) && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) { v = rand_int(&rnd->mt, v, 1); } else if (v = rb_check_to_float(vmax), !NIL_P(v)) { diff --git a/range.c b/range.c index b7ae19118e09a3..fb9ecd05b221a8 100644 --- a/range.c +++ b/range.c @@ -865,10 +865,10 @@ range_include(VALUE range, VALUE val) } return Qfalse; } - else if (TYPE(beg) == T_STRING && TYPE(end) == T_STRING && + else if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING) && RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) { if (NIL_P(val)) return Qfalse; - if (TYPE(val) == T_STRING) { + if (RB_TYPE_P(val, T_STRING)) { if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1) return Qfalse; else { @@ -939,7 +939,7 @@ range_dumper(VALUE range) static VALUE range_loader(VALUE range, VALUE obj) { - if (TYPE(obj) != T_OBJECT || RBASIC(obj)->klass != rb_cObject) { + if (!RB_TYPE_P(obj, T_OBJECT) || RBASIC(obj)->klass != rb_cObject) { rb_raise(rb_eTypeError, "not a dumped range object"); } diff --git a/rational.c b/rational.c index 40b480df6ea47b..3af98c76c55701 100644 --- a/rational.c +++ b/rational.c @@ -106,7 +106,7 @@ f_mul(VALUE x, VALUE y) if (FIXNUM_P(y)) { long iy = FIX2LONG(y); if (iy == 0) { - if (FIXNUM_P(x) || TYPE(x) == T_BIGNUM) + if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) return ZERO; } else if (iy == 1) @@ -115,7 +115,7 @@ f_mul(VALUE x, VALUE y) else if (FIXNUM_P(x)) { long ix = FIX2LONG(x); if (ix == 0) { - if (FIXNUM_P(y) || TYPE(y) == T_BIGNUM) + if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM)) return ZERO; } else if (ix == 1) @@ -141,14 +141,14 @@ fun1(negate) inline static VALUE f_to_i(VALUE x) { - if (TYPE(x) == T_STRING) + if (RB_TYPE_P(x, T_STRING)) return rb_str_to_inum(x, 10, 0); return rb_funcall(x, id_to_i, 0); } inline static VALUE f_to_f(VALUE x) { - if (TYPE(x) == T_STRING) + if (RB_TYPE_P(x, T_STRING)) return DBL2NUM(rb_str_to_dbl(x, 0)); return rb_funcall(x, id_to_f, 0); } @@ -2161,7 +2161,7 @@ string_to_r(VALUE self) a1 = RARRAY_PTR(a)[0]; if (!NIL_P(a1)) { - if (TYPE(a1) == T_FLOAT) + if (RB_TYPE_P(a1, T_FLOAT)) rb_raise(rb_eFloatDomainError, "Infinity"); return a1; } diff --git a/re.c b/re.c index 9fdbf547aaf33f..6484baa664b49d 100644 --- a/re.c +++ b/re.c @@ -2587,7 +2587,7 @@ static VALUE rb_reg_equal(VALUE re1, VALUE re2) { if (re1 == re2) return Qtrue; - if (TYPE(re2) != T_REGEXP) return Qfalse; + if (!RB_TYPE_P(re2, T_REGEXP)) return Qfalse; rb_reg_check(re1); rb_reg_check(re2); if (FL_TEST(re1, KCODE_FIXED) != FL_TEST(re2, KCODE_FIXED)) return Qfalse; if (RREGEXP(re1)->ptr->options != RREGEXP(re2)->ptr->options) return Qfalse; @@ -2635,7 +2635,7 @@ match_equal(VALUE match1, VALUE match2) { const struct re_registers *regs1, *regs2; if (match1 == match2) return Qtrue; - if (TYPE(match2) != T_MATCH) return Qfalse; + if (!RB_TYPE_P(match2, T_MATCH)) return Qfalse; if (!rb_str_equal(RMATCH(match1)->str, RMATCH(match2)->str)) return Qfalse; if (!rb_reg_equal(RMATCH(match1)->regexp, RMATCH(match2)->regexp)) return Qfalse; regs1 = RMATCH_REGS(match1); @@ -2795,7 +2795,7 @@ rb_reg_match2(VALUE re) long start; VALUE line = rb_lastline_get(); - if (TYPE(line) != T_STRING) { + if (!RB_TYPE_P(line, T_STRING)) { rb_backref_set(Qnil); return Qnil; } diff --git a/ruby.c b/ruby.c index b53784feb1369a..2e6751f0f28944 100644 --- a/ruby.c +++ b/ruby.c @@ -1137,7 +1137,7 @@ uscore_get(void) VALUE line; line = rb_lastline_get(); - if (TYPE(line) != T_STRING) { + if (!RB_TYPE_P(line, T_STRING)) { rb_raise(rb_eTypeError, "$_ value need to be String (%s given)", NIL_P(line) ? "nil" : rb_obj_classname(line)); } diff --git a/safe.c b/safe.c index e2ed5979d25e2d..05c1aa395bcffb 100644 --- a/safe.c +++ b/safe.c @@ -122,7 +122,7 @@ void rb_check_safe_str(VALUE x) { rb_check_safe_obj(x); - if (TYPE(x) != T_STRING) { + if (!RB_TYPE_P(x, T_STRING)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected String)", rb_obj_classname(x)); } diff --git a/string.c b/string.c index 711918b4e68015..1cc41fea2789e4 100644 --- a/string.c +++ b/string.c @@ -854,11 +854,11 @@ rb_obj_as_string(VALUE obj) { VALUE str; - if (TYPE(obj) == T_STRING) { + if (RB_TYPE_P(obj, T_STRING)) { return obj; } str = rb_funcall(obj, id_to_s, 0); - if (TYPE(str) != T_STRING) + if (!RB_TYPE_P(str, T_STRING)) return rb_any_to_s(obj); if (OBJ_TAINTED(obj)) OBJ_TAINT(str); return str; @@ -1404,7 +1404,7 @@ VALUE rb_string_value(volatile VALUE *ptr) { VALUE s = *ptr; - if (TYPE(s) != T_STRING) { + if (!RB_TYPE_P(s, T_STRING)) { s = rb_str_to_str(s); *ptr = s; } @@ -2075,7 +2075,7 @@ rb_str_concat(VALUE str1, VALUE str2) { unsigned int lc; - if (FIXNUM_P(str2) || TYPE(str2) == T_BIGNUM) { + if (FIXNUM_P(str2) || RB_TYPE_P(str2, T_BIGNUM)) { if (rb_num_to_uint(str2, &lc) == 0) { } else if (FIXNUM_P(str2)) { @@ -2250,7 +2250,7 @@ VALUE rb_str_equal(VALUE str1, VALUE str2) { if (str1 == str2) return Qtrue; - if (TYPE(str2) != T_STRING) { + if (!RB_TYPE_P(str2, T_STRING)) { if (!rb_respond_to(str2, rb_intern("to_str"))) { return Qfalse; } @@ -2270,7 +2270,7 @@ static VALUE rb_str_eql(VALUE str1, VALUE str2) { if (str1 == str2) return Qtrue; - if (TYPE(str2) != T_STRING) return Qfalse; + if (!RB_TYPE_P(str2, T_STRING)) return Qfalse; return str_eql(str1, str2); } @@ -2302,7 +2302,7 @@ rb_str_cmp_m(VALUE str1, VALUE str2) { long result; - if (TYPE(str2) != T_STRING) { + if (!RB_TYPE_P(str2, T_STRING)) { if (!rb_respond_to(str2, rb_intern("to_str"))) { return Qnil; } @@ -2472,7 +2472,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str) if (pos < 0) { pos += str_strlen(str, STR_ENC_GET(str)); if (pos < 0) { - if (TYPE(sub) == T_REGEXP) { + if (RB_TYPE_P(sub, T_REGEXP)) { rb_backref_set(Qnil); } return Qnil; @@ -2581,7 +2581,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str) if (pos < 0) { pos += len; if (pos < 0) { - if (TYPE(sub) == T_REGEXP) { + if (RB_TYPE_P(sub, T_REGEXP)) { rb_backref_set(Qnil); } return Qnil; @@ -5751,7 +5751,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) } else { fs_set: - if (TYPE(spat) == T_STRING) { + if (RB_TYPE_P(spat, T_STRING)) { rb_encoding *enc2 = STR_ENC_GET(spat); split_type = string; @@ -7064,7 +7064,7 @@ rb_str_partition(VALUE str, VALUE sep) long pos; int regex = FALSE; - if (TYPE(sep) == T_REGEXP) { + if (RB_TYPE_P(sep, T_REGEXP)) { pos = rb_reg_search(sep, str, 0, 0); regex = TRUE; } @@ -7114,7 +7114,7 @@ rb_str_rpartition(VALUE str, VALUE sep) long pos = RSTRING_LEN(str); int regex = FALSE; - if (TYPE(sep) == T_REGEXP) { + if (RB_TYPE_P(sep, T_REGEXP)) { pos = rb_reg_search(sep, str, pos, 1); regex = TRUE; } @@ -7206,7 +7206,7 @@ rb_str_end_with(int argc, VALUE *argv, VALUE str) void rb_str_setter(VALUE val, ID id, VALUE *var) { - if (!NIL_P(val) && TYPE(val) != T_STRING) { + if (!NIL_P(val) && !RB_TYPE_P(val, T_STRING)) { rb_raise(rb_eTypeError, "value of %s must be String", rb_id2name(id)); } *var = val; diff --git a/struct.c b/struct.c index ab82fadd1c6330..21f8c1ab7bed21 100644 --- a/struct.c +++ b/struct.c @@ -43,7 +43,7 @@ rb_struct_s_members(VALUE klass) if (NIL_P(members)) { rb_raise(rb_eTypeError, "uninitialized struct"); } - if (TYPE(members) != T_ARRAY) { + if (!RB_TYPE_P(members, T_ARRAY)) { rb_raise(rb_eTypeError, "corrupted struct"); } return members; @@ -354,7 +354,7 @@ num_members(VALUE klass) { VALUE members; members = struct_ivar_get(klass, id_members); - if (TYPE(members) != T_ARRAY) { + if (!RB_TYPE_P(members, T_ARRAY)) { rb_raise(rb_eTypeError, "broken members"); } return RARRAY_LEN(members); @@ -644,7 +644,7 @@ rb_struct_aref(VALUE s, VALUE idx) { long i; - if (TYPE(idx) == T_STRING || TYPE(idx) == T_SYMBOL) { + if (RB_TYPE_P(idx, T_STRING) || RB_TYPE_P(idx, T_SYMBOL)) { return rb_struct_aref_id(s, rb_to_id(idx)); } @@ -709,7 +709,7 @@ rb_struct_aset(VALUE s, VALUE idx, VALUE val) { long i; - if (TYPE(idx) == T_STRING || TYPE(idx) == T_SYMBOL) { + if (RB_TYPE_P(idx, T_STRING) || RB_TYPE_P(idx, T_SYMBOL)) { return rb_struct_aset_id(s, rb_to_id(idx), val); } @@ -827,7 +827,7 @@ static VALUE rb_struct_equal(VALUE s, VALUE s2) { if (s == s2) return Qtrue; - if (TYPE(s2) != T_STRUCT) return Qfalse; + if (!RB_TYPE_P(s2, T_STRUCT)) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { rb_bug("inconsistent struct"); /* should never happen */ @@ -897,7 +897,7 @@ static VALUE rb_struct_eql(VALUE s, VALUE s2) { if (s == s2) return Qtrue; - if (TYPE(s2) != T_STRUCT) return Qfalse; + if (!RB_TYPE_P(s2, T_STRUCT)) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) { rb_bug("inconsistent struct"); /* should never happen */ diff --git a/thread.c b/thread.c index 4f9d09534d36a8..d9d497ad6c4cc7 100644 --- a/thread.c +++ b/thread.c @@ -493,7 +493,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s main_th = th->vm->main_thread; if (th != main_th) { - if (TYPE(errinfo) == T_OBJECT) { + if (RB_TYPE_P(errinfo, T_OBJECT)) { /* treat with normal error object */ rb_threadptr_raise(main_th, 1, &errinfo); } @@ -3738,7 +3738,7 @@ recursive_list_access(void) volatile VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key); VALUE sym = ID2SYM(rb_frame_this_func()); VALUE list; - if (NIL_P(hash) || TYPE(hash) != T_HASH) { + if (NIL_P(hash) || !RB_TYPE_P(hash, T_HASH)) { hash = rb_hash_new(); OBJ_UNTRUST(hash); rb_thread_local_aset(rb_thread_current(), recursive_key, hash); @@ -3747,7 +3747,7 @@ recursive_list_access(void) else { list = rb_hash_aref(hash, sym); } - if (NIL_P(list) || TYPE(list) != T_HASH) { + if (NIL_P(list) || !RB_TYPE_P(list, T_HASH)) { list = rb_hash_new(); OBJ_UNTRUST(list); rb_hash_aset(hash, sym, list); @@ -3768,7 +3768,7 @@ recursive_check(VALUE list, VALUE obj_id, VALUE paired_obj_id) if (pair_list == Qundef) return Qfalse; if (paired_obj_id) { - if (TYPE(pair_list) != T_HASH) { + if (!RB_TYPE_P(pair_list, T_HASH)) { if (pair_list != paired_obj_id) return Qfalse; } @@ -3801,7 +3801,7 @@ recursive_push(VALUE list, VALUE obj, VALUE paired_obj) rb_hash_aset(list, obj, paired_obj); } else { - if (TYPE(pair_list) != T_HASH){ + if (!RB_TYPE_P(pair_list, T_HASH)){ VALUE other_paired_obj = pair_list; pair_list = rb_hash_new(); OBJ_UNTRUST(pair_list); @@ -3831,7 +3831,7 @@ recursive_pop(VALUE list, VALUE obj, VALUE paired_obj) rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list for %s in %s", StringValuePtr(symname), StringValuePtr(thrname)); } - if (TYPE(pair_list) == T_HASH) { + if (RB_TYPE_P(pair_list, T_HASH)) { rb_hash_delete(pair_list, paired_obj); if (!RHASH_EMPTY_P(pair_list)) { return; /* keep hash until is empty */ @@ -4424,7 +4424,7 @@ call_trace_proc(VALUE args, int tracing) if (id == ID_ALLOCATOR) return Qnil; if (klass) { - if (TYPE(klass) == T_ICLASS) { + if (RB_TYPE_P(klass, T_ICLASS)) { klass = RBASIC(klass)->klass; } else if (FL_TEST(klass, FL_SINGLETON)) { diff --git a/time.c b/time.c index 0a571ac0d98729..a18548ea36fa16 100644 --- a/time.c +++ b/time.c @@ -73,7 +73,7 @@ add(VALUE x, VALUE y) if (FIXABLE(l)) return LONG2FIX(l); return LONG2NUM(l); } - if (TYPE(x) == T_BIGNUM) return rb_big_plus(x, y); + if (RB_TYPE_P(x, T_BIGNUM)) return rb_big_plus(x, y); return rb_funcall(x, '+', 1, y); } @@ -85,7 +85,7 @@ sub(VALUE x, VALUE y) if (FIXABLE(l)) return LONG2FIX(l); return LONG2NUM(l); } - if (TYPE(x) == T_BIGNUM) return rb_big_minus(x, y); + if (RB_TYPE_P(x, T_BIGNUM)) return rb_big_minus(x, y); return rb_funcall(x, '-', 1, y); } @@ -148,7 +148,7 @@ mul(VALUE x, VALUE y) return LONG2NUM(z); #endif } - if (TYPE(x) == T_BIGNUM) + if (RB_TYPE_P(x, T_BIGNUM)) return rb_big_mul(x, y); return rb_funcall(x, '*', 1, y); } @@ -182,7 +182,7 @@ quo(VALUE x, VALUE y) } } ret = rb_funcall(x, id_quo, 1, y); - if (TYPE(ret) == T_RATIONAL && + if (RB_TYPE_P(ret, T_RATIONAL) && RRATIONAL(ret)->den == INT2FIX(1)) { ret = RRATIONAL(ret)->num; } @@ -391,7 +391,7 @@ v2w(VALUE v) if (FIXNUM_P(v)) { return WIDEVAL_WRAP((WIDEVALUE)(SIGNED_WIDEVALUE)(long)v); } - else if (TYPE(v) == T_BIGNUM && + else if (RB_TYPE_P(v, T_BIGNUM) && RBIGNUM_LEN(v) * sizeof(BDIGIT) <= sizeof(WIDEVALUE)) { return v2w_bignum(v); } @@ -451,7 +451,7 @@ wadd(wideval_t wx, wideval_t wy) else #endif x = w2v(wx); - if (TYPE(x) == T_BIGNUM) return v2w(rb_big_plus(x, w2v(wy))); + if (RB_TYPE_P(x, T_BIGNUM)) return v2w(rb_big_plus(x, w2v(wy))); return v2w(rb_funcall(x, '+', 1, w2v(wy))); } @@ -467,7 +467,7 @@ wsub(wideval_t wx, wideval_t wy) else #endif x = w2v(wx); - if (TYPE(x) == T_BIGNUM) return v2w(rb_big_minus(x, w2v(wy))); + if (RB_TYPE_P(x, T_BIGNUM)) return v2w(rb_big_minus(x, w2v(wy))); return v2w(rb_funcall(x, '-', 1, w2v(wy))); } @@ -525,9 +525,9 @@ wmul(wideval_t wx, wideval_t wy) } #endif x = w2v(wx); - if (TYPE(x) == T_BIGNUM) return v2w(rb_big_mul(x, w2v(wy))); + if (RB_TYPE_P(x, T_BIGNUM)) return v2w(rb_big_mul(x, w2v(wy))); z = rb_funcall(x, '*', 1, w2v(wy)); - if (TYPE(z) == T_RATIONAL && RRATIONAL(z)->den == INT2FIX(1)) { + if (RB_TYPE_P(z, T_RATIONAL) && RRATIONAL(z)->den == INT2FIX(1)) { z = RRATIONAL(z)->num; } return v2w(z); @@ -552,7 +552,7 @@ wquo(wideval_t wx, wideval_t wy) x = w2v(wx); y = w2v(wy); ret = rb_funcall(x, id_quo, 1, y); - if (TYPE(ret) == T_RATIONAL && + if (RB_TYPE_P(ret, T_RATIONAL) && RRATIONAL(ret)->den == INT2FIX(1)) { ret = RRATIONAL(ret)->num; } @@ -2536,7 +2536,7 @@ static const char months[][4] = { static int obj2int(VALUE obj) { - if (TYPE(obj) == T_STRING) { + if (RB_TYPE_P(obj, T_STRING)) { obj = rb_str_to_inum(obj, 10, FALSE); } @@ -2546,7 +2546,7 @@ obj2int(VALUE obj) static VALUE obj2vint(VALUE obj) { - if (TYPE(obj) == T_STRING) { + if (RB_TYPE_P(obj, T_STRING)) { obj = rb_str_to_inum(obj, 10, FALSE); } else { @@ -2561,7 +2561,7 @@ obj2subsecx(VALUE obj, VALUE *subsecx) { VALUE subsec; - if (TYPE(obj) == T_STRING) { + if (RB_TYPE_P(obj, T_STRING)) { obj = rb_str_to_inum(obj, 10, FALSE); *subsecx = INT2FIX(0); return NUM2INT(obj); @@ -2575,7 +2575,7 @@ obj2subsecx(VALUE obj, VALUE *subsecx) static long usec2subsecx(VALUE obj) { - if (TYPE(obj) == T_STRING) { + if (RB_TYPE_P(obj, T_STRING)) { obj = rb_str_to_inum(obj, 10, FALSE); } @@ -3216,7 +3216,7 @@ time_to_r(VALUE time) GetTimeval(time, tobj); v = w2v(rb_time_unmagnify(tobj->timew)); - if (TYPE(v) != T_RATIONAL) { + if (!RB_TYPE_P(v, T_RATIONAL)) { v = rb_Rational1(v); } return v; @@ -4642,7 +4642,7 @@ time_mdump(VALUE time) str = rb_str_new(buf, 8); rb_copy_generic_ivar(str, time); if (!rb_equal(nano, INT2FIX(0))) { - if (TYPE(nano) == T_RATIONAL) { + if (RB_TYPE_P(nano, T_RATIONAL)) { rb_ivar_set(str, id_nano_num, RRATIONAL(nano)->num); rb_ivar_set(str, id_nano_den, RRATIONAL(nano)->den); } diff --git a/transcode.c b/transcode.c index e813516563aeed..9c283951821c27 100644 --- a/transcode.c +++ b/transcode.c @@ -2294,7 +2294,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos, if (!ec) rb_exc_raise(rb_econv_open_exc(src_encoding, dst_encoding, ecflags)); - if (!NIL_P(ecopts) && TYPE(ecopts) == T_HASH) { + if (!NIL_P(ecopts) && RB_TYPE_P(ecopts, T_HASH)) { fallback = rb_hash_aref(ecopts, sym_fallback); if (RB_TYPE_P(fallback, T_HASH)) { fallback_func = hash_fallback; @@ -2471,7 +2471,7 @@ econv_opts(VALUE opt, int ecflags) else if (v==sym_attr) { ecflags |= ECONV_XML_ATTR_CONTENT_DECORATOR|ECONV_XML_ATTR_QUOTE_DECORATOR|ECONV_UNDEF_HEX_CHARREF; } - else if (TYPE(v) == T_SYMBOL) { + else if (RB_TYPE_P(v, T_SYMBOL)) { rb_raise(rb_eArgError, "unexpected value for xml option: %s", rb_id2name(SYM2ID(v))); } else { @@ -2593,7 +2593,7 @@ rb_econv_open_opts(const char *source_encoding, const char *destination_encoding replacement = Qnil; } else { - if (TYPE(opthash) != T_HASH || !OBJ_FROZEN(opthash)) + if (!RB_TYPE_P(opthash, T_HASH) || !OBJ_FROZEN(opthash)) rb_bug("rb_econv_open_opts called with invalid opthash"); replacement = rb_hash_aref(opthash, sym_replace); } @@ -3057,7 +3057,7 @@ decorate_convpath(VALUE convpath, int ecflags) len = n = RARRAY_LENINT(convpath); if (n != 0) { VALUE pair = RARRAY_PTR(convpath)[n-1]; - if (TYPE(pair) == T_ARRAY) { + if (RB_TYPE_P(pair, T_ARRAY)) { const char *sname = rb_enc_name(rb_to_encoding(RARRAY_PTR(pair)[0])); const char *dname = rb_enc_name(rb_to_encoding(RARRAY_PTR(pair)[1])); transcoder_entry_t *entry = get_transcoder_entry(sname, dname); diff --git a/variable.c b/variable.c index 3909b799c42e7d..ae89e8eead7a89 100644 --- a/variable.c +++ b/variable.c @@ -161,7 +161,7 @@ classname(VALUE klass) else { path = (VALUE)n; } - if (TYPE(path) != T_STRING) { + if (!RB_TYPE_P(path, T_STRING)) { rb_bug("class path is not set properly"); } return path; @@ -199,7 +199,7 @@ rb_class_path(VALUE klass) else { const char *s = "Class"; - if (TYPE(klass) == T_MODULE) { + if (RB_TYPE_P(klass, T_MODULE)) { if (rb_obj_class(klass) == rb_cModule) { s = "Module"; } @@ -2157,7 +2157,7 @@ rb_mod_public_constant(int argc, VALUE *argv, VALUE obj) static VALUE original_module(VALUE c) { - if (TYPE(c) == T_ICLASS) + if (RB_TYPE_P(c, T_ICLASS)) return RBASIC(c)->klass; return c; } diff --git a/vm_eval.c b/vm_eval.c index 393047a2c06eb6..8be6b437c3a916 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -410,7 +410,7 @@ rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type sc if (((noex & NOEX_MASK) & NOEX_PROTECTED) && scope == CALL_PUBLIC) { VALUE defined_class = klass; - if (TYPE(defined_class) == T_ICLASS) { + if (RB_TYPE_P(defined_class, T_ICLASS)) { defined_class = RBASIC(defined_class)->klass; } @@ -1063,9 +1063,9 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char CONST_ID(id_mesg, "mesg"); errat = rb_get_backtrace(errinfo); mesg = rb_attr_get(errinfo, id_mesg); - if (!NIL_P(errat) && TYPE(errat) == T_ARRAY && + if (!NIL_P(errat) && RB_TYPE_P(errat, T_ARRAY) && (bt2 = vm_backtrace(th, -2), RARRAY_LEN(bt2) > 0)) { - if (!NIL_P(mesg) && TYPE(mesg) == T_STRING && !RSTRING_LEN(mesg)) { + if (!NIL_P(mesg) && RB_TYPE_P(mesg, T_STRING) && !RSTRING_LEN(mesg)) { if (OBJ_FROZEN(mesg)) { VALUE m = rb_str_cat(rb_str_dup(RARRAY_PTR(errat)[0]), ": ", 2); rb_ivar_set(errinfo, id_mesg, rb_str_append(m, mesg)); @@ -1189,7 +1189,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) level = 4; } - if (TYPE(cmd) != T_STRING) { + if (!RB_TYPE_P(cmd, T_STRING)) { PUSH_TAG(); rb_set_safe_level_force(level); if ((state = EXEC_TAG()) == 0) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index d97ac87a2a2356..420e67de05b225 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1282,7 +1282,7 @@ static VALUE vm_getivar(VALUE obj, ID id, IC ic) { #if USE_IC_FOR_IVAR - if (TYPE(obj) == T_OBJECT) { + if (RB_TYPE_P(obj, T_OBJECT)) { VALUE val = Qundef; VALUE klass = RBASIC(obj)->klass; @@ -1337,7 +1337,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic) rb_check_frozen(obj); - if (TYPE(obj) == T_OBJECT) { + if (RB_TYPE_P(obj, T_OBJECT)) { VALUE klass = RBASIC(obj)->klass; st_data_t index; @@ -1645,7 +1645,7 @@ vm_expandarray(rb_control_frame_t *cfp, VALUE ary, rb_num_t num, int flag) volatile VALUE tmp_ary; rb_num_t len; - if (TYPE(ary) != T_ARRAY) { + if (!RB_TYPE_P(ary, T_ARRAY)) { ary = rb_ary_to_ary(ary); } diff --git a/vm_method.c b/vm_method.c index d6c4926e65da75..f1235dcd47e613 100644 --- a/vm_method.c +++ b/vm_method.c @@ -521,7 +521,7 @@ rb_export_method(VALUE klass, ID name, rb_method_flag_t noex) } me = search_method(klass, name); - if (!me && TYPE(klass) == T_MODULE) { + if (!me && RB_TYPE_P(klass, T_MODULE)) { me = search_method(rb_cObject, name); } @@ -639,7 +639,7 @@ rb_undef(VALUE klass, ID id) s0 = ""; } } - else if (TYPE(c) == T_MODULE) { + else if (RB_TYPE_P(c, T_MODULE)) { s0 = " module"; } rb_name_error(id, "undefined method `%s' for%s `%s'", @@ -922,7 +922,7 @@ rb_alias(VALUE klass, ID name, ID def) orig_me = search_method(klass, def); if (UNDEFINED_METHOD_ENTRY_P(orig_me)) { - if ((TYPE(klass) != T_MODULE) || + if ((!RB_TYPE_P(klass, T_MODULE)) || (orig_me = search_method(rb_cObject, def), UNDEFINED_METHOD_ENTRY_P(orig_me))) { rb_print_undef(klass, def, 0); } @@ -1176,7 +1176,7 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module) ID id; const rb_method_entry_t *me; - if (TYPE(module) != T_MODULE) { + if (!RB_TYPE_P(module, T_MODULE)) { rb_raise(rb_eTypeError, "module_function must be called for modules"); }