[前][次][番号順一覧][スレッド一覧]

ruby-changes:23712

From: nobu <ko1@a...>
Date: Wed, 23 May 2012 16:13:38 +0900 (JST)
Subject: [ruby-changes:23712] nobu:r35763 (trunk): use RB_TYPE_P() instead of comparison of TYPE()

nobu	2012-05-23 16:13:21 +0900 (Wed, 23 May 2012)

  New Revision: 35763

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35763

  Log:
    use RB_TYPE_P() instead of comparison of TYPE()

  Modified files:
    trunk/enumerator.c
    trunk/error.c
    trunk/eval.c
    trunk/ext/io/console/console.c
    trunk/ext/objspace/objspace.c
    trunk/ext/pathname/pathname.c
    trunk/ext/pty/pty.c
    trunk/ext/racc/cparse/cparse.c
    trunk/ext/socket/ancdata.c
    trunk/ext/socket/raddrinfo.c
    trunk/ext/stringio/stringio.c
    trunk/ext/zlib/zlib.c
    trunk/hash.c
    trunk/io.c
    trunk/marshal.c
    trunk/pack.c
    trunk/proc.c
    trunk/re.c
    trunk/string.c
    trunk/thread.c
    trunk/vm_insnhelper.c

Index: re.c
===================================================================
--- re.c	(revision 35762)
+++ re.c	(revision 35763)
@@ -2907,7 +2907,7 @@
     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) {
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 35762)
+++ enumerator.c	(revision 35763)
@@ -1369,7 +1369,7 @@
 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]);
Index: string.c
===================================================================
--- string.c	(revision 35762)
+++ string.c	(revision 35763)
@@ -3244,7 +3244,7 @@
 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 @@
 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 {
Index: io.c
===================================================================
--- io.c	(revision 35762)
+++ io.c	(revision 35763)
@@ -6495,7 +6495,7 @@
     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 @@
 	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 @@
 
 #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 @@
     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 @@
     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 @@
 
   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 @@
 
   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 {
Index: pack.c
===================================================================
--- pack.c	(revision 35762)
+++ pack.c	(revision 35763)
@@ -2057,7 +2057,7 @@
 		    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 @@
 			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;
 			    }
Index: proc.c
===================================================================
--- proc.c	(revision 35762)
+++ proc.c	(revision 35763)
@@ -1970,7 +1970,7 @@
     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");
 	}
Index: thread.c
===================================================================
--- thread.c	(revision 35762)
+++ thread.c	(revision 35763)
@@ -733,7 +733,7 @@
 	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)));
 	}
Index: eval.c
===================================================================
--- eval.c	(revision 35762)
+++ eval.c	(revision 35763)
@@ -1058,7 +1058,7 @@
 		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];
 	    }
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 35762)
+++ ext/objspace/objspace.c	(revision 35763)
@@ -300,7 +300,7 @@
     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 @@
     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 @@
     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");
     }
 
Index: ext/zlib/zlib.c
===================================================================
--- ext/zlib/zlib.c	(revision 35762)
+++ ext/zlib/zlib.c	(revision 35763)
@@ -3369,7 +3369,7 @@
 {
     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);
Index: ext/pty/pty.c
===================================================================
--- ext/pty/pty.c	(revision 35762)
+++ ext/pty/pty.c	(revision 35763)
@@ -461,7 +461,7 @@
 
     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;
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 35762)
+++ ext/socket/raddrinfo.c	(revision 35763)
@@ -673,25 +673,25 @@
                              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));
Index: ext/socket/ancdata.c
===================================================================
--- ext/socket/ancdata.c	(revision 35762)
+++ ext/socket/ancdata.c	(revision 35763)
@@ -196,7 +196,7 @@
 
     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 @@
     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);
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 35762)
+++ ext/pathname/pathname.c	(revision 35763)
@@ -9,7 +9,7 @@
 {
     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 @@
 path_initialize(VALUE self, VALUE arg)
 {
     VALUE str;
-    if (TYPE(arg) == T_STRING) {
+    if (RB_TYPE_P(arg, T_STRING)) {
         str = arg;
     }
     else {
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 35762)
+++ ext/stringio/stringio.c	(revision 35763)
@@ -506,7 +506,7 @@
 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 @@
 	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 @@
     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);
Index: ext/io/console/console.c
===================================================================
--- ext/io/console/console.c	(revision 35762)
+++ ext/io/console/console.c	(revision 35763)
@@ -659,7 +659,7 @@
     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;
 	}
Index: ext/racc/cparse/cparse.c
===================================================================
--- ext/racc/cparse/cparse.c	(revision 35762)
+++ ext/racc/cparse/cparse.c	(revision 35763)
@@ -416,7 +416,7 @@
         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",
Index: hash.c
===================================================================
--- hash.c	(revision 35762)
+++ hash.c	(revision 35763)
@@ -45,7 +45,7 @@
 	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;
Index: error.c
===================================================================
--- error.c	(revision 35762)
+++ error.c	(revision 35763)
@@ -451,7 +451,7 @@
 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 @@
     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);
     }
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 35762)
+++ vm_insnhelper.c	(revision 35763)
@@ -153,7 +153,7 @@
 	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);
Index: marshal.c
===================================================================
--- marshal.c	(revision 35762)
+++ marshal.c	(revision 35763)
@@ -1025,7 +1025,7 @@
 {
     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 @@
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]