Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use RB_TYPE_P() instead of comparison of TYPE()

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit b0dd250dc95ea0fae89c3201967039d582fbf156 1 parent 87c8c5e
Nobuyoshi Nakada nobu authored
2  enumerator.c
View
@@ -1369,7 +1369,7 @@ static VALUE
lazy_flat_map_func(VALUE val, VALUE m, int argc, VALUE *argv)
{
VALUE result = rb_yield_values2(argc - 1, &argv[1]);
- if (TYPE(result) == T_ARRAY) {
+ if (RB_TYPE_P(result, T_ARRAY)) {
long i;
for (i = 0; i < RARRAY_LEN(result); i++) {
rb_funcall(argv[0], id_yield, 1, RARRAY_PTR(result)[i]);
4 error.c
View
@@ -451,7 +451,7 @@ rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *pare
int
rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
{
- if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA ||
+ if (!RB_TYPE_P(obj, T_DATA) ||
!RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
return 0;
}
@@ -464,7 +464,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
const char *etype;
static const char mesg[] = "wrong argument type %s (expected %s)";
- if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA) {
+ if (!RB_TYPE_P(obj, T_DATA)) {
etype = builtin_type_name(obj);
rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
}
2  eval.c
View
@@ -1058,7 +1058,7 @@ errinfo_place(rb_thread_t *th)
return &cfp->dfp[-2];
}
else if (cfp->iseq->type == ISEQ_TYPE_ENSURE &&
- TYPE(cfp->dfp[-2]) != T_NODE &&
+ !RB_TYPE_P(cfp->dfp[-2], T_NODE) &&
!FIXNUM_P(cfp->dfp[-2])) {
return &cfp->dfp[-2];
}
2  ext/io/console/console.c
View
@@ -659,7 +659,7 @@ console_dev(VALUE klass)
if (klass == rb_cIO) klass = rb_cFile;
if (rb_const_defined(klass, id_console)) {
con = rb_const_get(klass, id_console);
- if (TYPE(con) == T_FILE) {
+ if (RB_TYPE_P(con, T_FILE)) {
if ((fptr = RFILE(con)->fptr) && GetReadFD(fptr) != -1)
return con;
}
6 ext/objspace/objspace.c
View
@@ -300,7 +300,7 @@ count_objects_size(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");
}
@@ -404,7 +404,7 @@ count_nodes(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");
}
@@ -609,7 +609,7 @@ count_tdata_objects(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");
}
4 ext/pathname/pathname.c
View
@@ -9,7 +9,7 @@ get_strpath(VALUE obj)
{
VALUE strpath;
strpath = rb_ivar_get(obj, id_at_path);
- if (TYPE(strpath) != T_STRING)
+ if (!RB_TYPE_P(strpath, T_STRING))
rb_raise(rb_eTypeError, "unexpected @path");
return strpath;
}
@@ -28,7 +28,7 @@ static VALUE
path_initialize(VALUE self, VALUE arg)
{
VALUE str;
- if (TYPE(arg) == T_STRING) {
+ if (RB_TYPE_P(arg, T_STRING)) {
str = arg;
}
else {
2  ext/pty/pty.c
View
@@ -461,7 +461,7 @@ pty_close_pty(VALUE assoc)
for (i = 0; i < 2; i++) {
io = rb_ary_entry(assoc, i);
- if (TYPE(io) == T_FILE && 0 <= RFILE(io)->fptr->fd)
+ if (RB_TYPE_P(io, T_FILE) && 0 <= RFILE(io)->fptr->fd)
rb_io_close(io);
}
return Qnil;
2  ext/racc/cparse/cparse.c
View
@@ -416,7 +416,7 @@ extract_user_token(struct cparse_params *v, VALUE block_args,
return;
}
- if (TYPE(block_args) != T_ARRAY) {
+ if (!RB_TYPE_P(block_args, T_ARRAY)) {
rb_raise(rb_eTypeError,
"%s() %s %s (must be Array[2])",
v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
4 ext/socket/ancdata.c
View
@@ -196,7 +196,7 @@ ancillary_s_unix_rights(int argc, VALUE *argv, VALUE klass)
for (i = 0 ; i < argc; i++) {
VALUE obj = argv[i];
- if (TYPE(obj) != T_FILE) {
+ if (!RB_TYPE_P(obj, T_FILE)) {
rb_raise(rb_eTypeError, "IO expected");
}
rb_ary_push(ary, obj);
@@ -1496,7 +1496,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
rb_secure(4);
vopts = Qnil;
- if (0 < argc && TYPE(argv[argc-1]) == T_HASH)
+ if (0 < argc && RB_TYPE_P(argv[argc-1], T_HASH))
vopts = argv[--argc];
rb_scan_args(argc, argv, "03", &vmaxdatlen, &vflags, &vmaxctllen);
12 ext/socket/raddrinfo.c
View
@@ -673,25 +673,25 @@ make_inspectname(VALUE node, VALUE service, struct addrinfo *res)
sizeof(hbuf), pbuf, sizeof(pbuf),
NI_NUMERICHOST|NI_NUMERICSERV);
if (ret == 0) {
- if (TYPE(node) == T_STRING && strcmp(hbuf, RSTRING_PTR(node)) == 0)
+ if (RB_TYPE_P(node, T_STRING) && strcmp(hbuf, RSTRING_PTR(node)) == 0)
node = Qnil;
- if (TYPE(service) == T_STRING && strcmp(pbuf, RSTRING_PTR(service)) == 0)
+ if (RB_TYPE_P(service, T_STRING) && strcmp(pbuf, RSTRING_PTR(service)) == 0)
service = Qnil;
- else if (TYPE(service) == T_FIXNUM && atoi(pbuf) == FIX2INT(service))
+ else if (RB_TYPE_P(service, T_FIXNUM) && atoi(pbuf) == FIX2INT(service))
service = Qnil;
}
}
- if (TYPE(node) == T_STRING) {
+ if (RB_TYPE_P(node, T_STRING)) {
inspectname = rb_str_dup(node);
}
- if (TYPE(service) == T_STRING) {
+ if (RB_TYPE_P(service, T_STRING)) {
if (NIL_P(inspectname))
inspectname = rb_sprintf(":%s", StringValueCStr(service));
else
rb_str_catf(inspectname, ":%s", StringValueCStr(service));
}
- else if (TYPE(service) == T_FIXNUM && FIX2INT(service) != 0)
+ else if (RB_TYPE_P(service, T_FIXNUM) && FIX2INT(service) != 0)
{
if (NIL_P(inspectname))
inspectname = rb_sprintf(":%d", FIX2INT(service));
6 ext/stringio/stringio.c
View
@@ -506,7 +506,7 @@ static VALUE
strio_reopen(int argc, VALUE *argv, VALUE self)
{
rb_io_taint_check(self);
- if (argc == 1 && TYPE(*argv) != T_STRING) {
+ if (argc == 1 && !RB_TYPE_P(*argv, T_STRING)) {
return strio_copy(self, *argv);
}
strio_init(argc, argv, StringIO(self));
@@ -931,7 +931,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
break;
case 1:
- if (!NIL_P(str) && TYPE(str) != T_STRING) {
+ if (!NIL_P(str) && !RB_TYPE_P(str, T_STRING)) {
VALUE tmp = rb_check_string_type(str);
if (NIL_P(tmp)) {
limit = NUM2LONG(str);
@@ -1124,7 +1124,7 @@ strio_write(VALUE self, VALUE str)
rb_encoding *enc, *enc2;
RB_GC_GUARD(str);
- if (TYPE(str) != T_STRING)
+ if (!RB_TYPE_P(str, T_STRING))
str = rb_obj_as_string(str);
enc = rb_enc_get(ptr->string);
enc2 = rb_enc_get(str);
2  ext/zlib/zlib.c
View
@@ -3369,7 +3369,7 @@ rb_gzwriter_write(VALUE obj, VALUE str)
{
struct gzfile *gz = get_gzfile(obj);
- if (TYPE(str) != T_STRING)
+ if (!RB_TYPE_P(str, T_STRING))
str = rb_obj_as_string(str);
if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) {
str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2);
2  hash.c
View
@@ -45,7 +45,7 @@ rb_any_cmp(VALUE a, VALUE b)
return a != b;
}
if (RB_TYPE_P(a, T_STRING) && RBASIC(a)->klass == rb_cString &&
- TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
+ RB_TYPE_P(b, T_STRING) && RBASIC(b)->klass == rb_cString) {
return rb_str_hash_cmp(a, b);
}
if (a == Qundef || b == Qundef) return -1;
22 io.c
View
@@ -6495,7 +6495,7 @@ rb_f_printf(int argc, VALUE *argv)
VALUE out;
if (argc == 0) return Qnil;
- if (TYPE(argv[0]) == T_STRING) {
+ if (RB_TYPE_P(argv[0], T_STRING)) {
out = rb_stdout;
}
else {
@@ -6705,7 +6705,7 @@ rb_io_puts(int argc, VALUE *argv, VALUE out)
return Qnil;
}
for (i=0; i<argc; i++) {
- if (TYPE(argv[i]) == T_STRING) {
+ if (RB_TYPE_P(argv[i], T_STRING)) {
line = argv[i];
goto string;
}
@@ -7336,7 +7336,7 @@ argf_forward(int argc, VALUE *argv, VALUE argf)
#define next_argv() argf_next_argv(argf)
#define ARGF_GENERIC_INPUT_P() \
- (ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
+ (ARGF.current_file == rb_stdin && !RB_TYPE_P(ARGF.current_file, T_FILE))
#define ARGF_FORWARD(argc, argv) do {\
if (ARGF_GENERIC_INPUT_P())\
return argf_forward((argc), (argv), argf);\
@@ -9831,13 +9831,13 @@ copy_stream_body(VALUE arg)
stp->total = 0;
if (stp->src == argf ||
- !(TYPE(stp->src) == T_FILE ||
- TYPE(stp->src) == T_STRING ||
+ !(RB_TYPE_P(stp->src, T_FILE) ||
+ RB_TYPE_P(stp->src, T_STRING) ||
rb_respond_to(stp->src, rb_intern("to_path")))) {
src_fd = -1;
}
else {
- src_io = TYPE(stp->src) == T_FILE ? stp->src : Qnil;
+ src_io = RB_TYPE_P(stp->src, T_FILE) ? stp->src : Qnil;
if (NIL_P(src_io)) {
VALUE args[2];
int oflags = O_RDONLY;
@@ -9858,13 +9858,13 @@ copy_stream_body(VALUE arg)
stp->src_fd = src_fd;
if (stp->dst == argf ||
- !(TYPE(stp->dst) == T_FILE ||
- TYPE(stp->dst) == T_STRING ||
+ !(RB_TYPE_P(stp->dst, T_FILE) ||
+ RB_TYPE_P(stp->dst, T_STRING) ||
rb_respond_to(stp->dst, rb_intern("to_path")))) {
dst_fd = -1;
}
else {
- dst_io = TYPE(stp->dst) == T_FILE ? stp->dst : Qnil;
+ dst_io = RB_TYPE_P(stp->dst, T_FILE) ? stp->dst : Qnil;
if (NIL_P(dst_io)) {
VALUE args[3];
int oflags = O_WRONLY|O_CREAT|O_TRUNC;
@@ -10609,7 +10609,7 @@ argf_getbyte(VALUE argf)
retry:
if (!next_argv()) return Qnil;
- if (TYPE(ARGF.current_file) != T_FILE) {
+ if (!RB_TYPE_P(ARGF.current_file, T_FILE)) {
ch = rb_funcall3(ARGF.current_file, rb_intern("getbyte"), 0, 0);
}
else {
@@ -10649,7 +10649,7 @@ argf_readchar(VALUE argf)
retry:
if (!next_argv()) rb_eof_error();
- if (TYPE(ARGF.current_file) != T_FILE) {
+ if (!RB_TYPE_P(ARGF.current_file, T_FILE)) {
ch = rb_funcall3(ARGF.current_file, rb_intern("getc"), 0, 0);
}
else {
4 marshal.c
View
@@ -1025,7 +1025,7 @@ r_byte(struct load_arg *arg)
{
int c;
- if (TYPE(arg->src) == T_STRING) {
+ if (RB_TYPE_P(arg->src, T_STRING)) {
if (RSTRING_LEN(arg->src) > arg->offset) {
c = (unsigned char)RSTRING_PTR(arg->src)[arg->offset++];
}
@@ -1099,7 +1099,7 @@ r_bytes0(long len, struct load_arg *arg)
VALUE str;
if (len == 0) return rb_str_new(0, 0);
- if (TYPE(arg->src) == T_STRING) {
+ if (RB_TYPE_P(arg->src, T_STRING)) {
if (RSTRING_LEN(arg->src) - arg->offset >= len) {
str = rb_str_new(RSTRING_PTR(arg->src)+arg->offset, len);
arg->offset += len;
4 pack.c
View
@@ -2057,7 +2057,7 @@ pack_unpack(VALUE str, VALUE fmt)
p = RARRAY_PTR(a);
pend = p + RARRAY_LEN(a);
while (p < pend) {
- if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
+ if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
if (len < RSTRING_LEN(*p)) {
tmp = rb_tainted_str_new(t, len);
rb_str_associate(tmp, a);
@@ -2099,7 +2099,7 @@ pack_unpack(VALUE str, VALUE fmt)
p = RARRAY_PTR(a);
pend = p + RARRAY_LEN(a);
while (p < pend) {
- if (TYPE(*p) == T_STRING && RSTRING_PTR(*p) == t) {
+ if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
tmp = *p;
break;
}
2  proc.c
View
@@ -1970,7 +1970,7 @@ proc_binding(VALUE self)
rb_binding_t *bind;
GetProcPtr(self, proc);
- if (TYPE(proc->block.iseq) == T_NODE) {
+ if (RB_TYPE_P((VALUE)proc->block.iseq, T_NODE)) {
if (!IS_METHOD_PROC_NODE((NODE *)proc->block.iseq)) {
rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
}
2  re.c
View
@@ -2907,7 +2907,7 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
long len;
rb_check_arity(argc, 1, 3);
- if (TYPE(argv[0]) == T_REGEXP) {
+ if (RB_TYPE_P(argv[0], T_REGEXP)) {
VALUE re = argv[0];
if (argc > 1) {
4 string.c
View
@@ -3244,7 +3244,7 @@ static VALUE
rb_str_aref_m(int argc, VALUE *argv, VALUE str)
{
if (argc == 2) {
- if (TYPE(argv[0]) == T_REGEXP) {
+ if (RB_TYPE_P(argv[0], T_REGEXP)) {
return rb_str_subpat(str, argv[0], argv[1]);
}
return rb_str_substr(str, NUM2LONG(argv[0]), NUM2LONG(argv[1]));
@@ -3469,7 +3469,7 @@ static VALUE
rb_str_aset_m(int argc, VALUE *argv, VALUE str)
{
if (argc == 3) {
- if (TYPE(argv[0]) == T_REGEXP) {
+ if (RB_TYPE_P(argv[0], T_REGEXP)) {
rb_str_subpat_set(str, argv[0], argv[1], argv[2]);
}
else {
2  thread.c
View
@@ -733,7 +733,7 @@ thread_join(rb_thread_t *target_th, double delay)
if (FIXNUM_P(err)) {
/* */
}
- else if (TYPE(target_th->errinfo) == T_NODE) {
+ else if (RB_TYPE_P(target_th->errinfo, T_NODE)) {
rb_exc_raise(rb_vm_make_jump_tag_but_local_jump(
GET_THROWOBJ_STATE(err), GET_THROWOBJ_VAL(err)));
}
2  vm_insnhelper.c
View
@@ -153,7 +153,7 @@ unknown_keyword_error(const rb_iseq_t *iseq, VALUE hash)
rb_hash_delete(hash, ID2SYM(iseq->arg_keyword_table[i]));
}
keys = rb_funcall(hash, rb_intern("keys"), 0, 0);
- if (TYPE(keys) != T_ARRAY) rb_raise(rb_eArgError, "unknown keyword");
+ if (!RB_TYPE_P(keys, T_ARRAY)) rb_raise(rb_eArgError, "unknown keyword");
msg = RARRAY_LEN(keys) == 1 ? "unknown keyword: %s" : "unknown keywords: %s";
keys = rb_funcall(keys, rb_intern("join"), 1, sep);
RB_GC_GUARD(keys);
Please sign in to comment.
Something went wrong with that request. Please try again.