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

ruby-changes:42626

From: naruse <ko1@a...>
Date: Fri, 22 Apr 2016 17:50:58 +0900 (JST)
Subject: [ruby-changes:42626] naruse:r54700 (trunk): * variable.c: use uint32_t instead of long to avoid confusion about

naruse	2016-04-22 18:47:34 +0900 (Fri, 22 Apr 2016)

  New Revision: 54700

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54700

  Log:
    * variable.c: use uint32_t instead of long to avoid confusion about
      the type of ivtbl->numiv.

  Modified files:
    trunk/ChangeLog
    trunk/ext/objspace/objspace_dump.c
    trunk/gc.c
    trunk/include/ruby/ruby.h
    trunk/object.c
    trunk/variable.c
    trunk/vm_insnhelper.c
Index: gc.c
===================================================================
--- gc.c	(revision 54699)
+++ gc.c	(revision 54700)
@@ -4494,7 +4494,7 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L4494
 
       case T_OBJECT:
         {
-            long i, len = ROBJECT_NUMIV(obj);
+            uint32_t i, len = ROBJECT_NUMIV(obj);
 	    VALUE *ptr = ROBJECT_IVPTR(obj);
             for (i  = 0; i < len; i++) {
 		gc_mark(objspace, *ptr++);
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 54699)
+++ include/ruby/ruby.h	(revision 54700)
@@ -909,7 +909,7 @@ struct RObject { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L909
     struct RBasic basic;
     union {
 	struct {
-	    long numiv; /* only uses 32-bits */
+	    uint32_t numiv;
 	    VALUE *ivptr;
             void *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
 	} heap;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54699)
+++ ChangeLog	(revision 54700)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Apr 22 18:44:32 2016  NARUSE, Yui  <naruse@r...>
+
+	* variable.c: use uint32_t instead of long to avoid confusion about
+	  the type of ivtbl->numiv.
+
 Fri Apr 22 15:09:27 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval_jump.c (exec_end_procs_chain): restore previous error info
Index: ext/objspace/objspace_dump.c
===================================================================
--- ext/objspace/objspace_dump.c	(revision 54699)
+++ ext/objspace/objspace_dump.c	(revision 54700)
@@ -272,7 +272,7 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L272
 	break;
 
       case T_OBJECT:
-	dump_append(dc, ", \"ivars\":%ld", ROBJECT_NUMIV(obj));
+	dump_append(dc, ", \"ivars\":%u", ROBJECT_NUMIV(obj));
 	break;
 
       case T_FILE:
Index: variable.c
===================================================================
--- variable.c	(revision 54699)
+++ variable.c	(revision 54700)
@@ -30,7 +30,7 @@ static st_table *generic_iv_tbl_compat; https://github.com/ruby/ruby/blob/trunk/variable.c#L30
 
 /* per-object */
 struct gen_ivtbl {
-    long numiv; /* only uses 32-bits */
+    uint32_t numiv;
     VALUE ivptr[1]; /* flexible array */
 };
 
@@ -949,7 +949,7 @@ gen_ivar_compat_tbl_i(st_data_t id, st_d https://github.com/ruby/ruby/blob/trunk/variable.c#L949
 {
     struct gen_ivar_compat_tbl *a = (struct gen_ivar_compat_tbl *)arg;
 
-    if ((long)index < a->ivtbl->numiv) {
+    if (index < a->ivtbl->numiv) {
 	VALUE val = a->ivtbl->ivptr[index];
 	if (val != Qundef) {
 	    st_add_direct(a->tbl, id, (st_data_t)val);
@@ -1012,7 +1012,7 @@ generic_ivar_delete(VALUE obj, ID id, VA https://github.com/ruby/ruby/blob/trunk/variable.c#L1012
 	st_data_t index;
 
 	if (st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
-	    if ((long)index < ivtbl->numiv) {
+	    if (index < ivtbl->numiv) {
 		VALUE ret = ivtbl->ivptr[index];
 
 		ivtbl->ivptr[index] = Qundef;
@@ -1033,7 +1033,7 @@ generic_ivar_get(VALUE obj, ID id, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1033
 	st_data_t index;
 
 	if (st_lookup(iv_index_tbl, (st_data_t)id, &index)) {
-	    if ((long)index < ivtbl->numiv) {
+	    if (index < ivtbl->numiv) {
 		VALUE ret = ivtbl->ivptr[index];
 
 		return ret == Qundef ? undef : ret;
@@ -1050,9 +1050,9 @@ gen_ivtbl_bytes(size_t n) https://github.com/ruby/ruby/blob/trunk/variable.c#L1050
 }
 
 static struct gen_ivtbl *
-gen_ivtbl_resize(struct gen_ivtbl *old, long n)
+gen_ivtbl_resize(struct gen_ivtbl *old, uint32_t n)
 {
-    long len = old ? old->numiv : 0;
+    uint32_t len = old ? old->numiv : 0;
     struct gen_ivtbl *ivtbl = xrealloc(old, gen_ivtbl_bytes(n));
 
     ivtbl->numiv = n;
@@ -1076,10 +1076,10 @@ gen_ivtbl_dup(const struct gen_ivtbl *or https://github.com/ruby/ruby/blob/trunk/variable.c#L1076
 }
 #endif
 
-static long
+static uint32_t
 iv_index_tbl_newsize(struct ivar_update *ivup)
 {
-    long newsize = (ivup->index+1) + (ivup->index+1)/4; /* (index+1)*1.25 */
+    uint32_t newsize = (ivup->index+1) + (ivup->index+1)/4; /* (index+1)*1.25 */
 
     if (!ivup->iv_extended &&
         ivup->u.iv_index_tbl->num_entries < (st_index_t)newsize) {
@@ -1093,13 +1093,13 @@ generic_ivar_update(st_data_t *k, st_dat https://github.com/ruby/ruby/blob/trunk/variable.c#L1093
 {
     VALUE obj = (VALUE)*k;
     struct ivar_update *ivup = (struct ivar_update *)u;
-    long newsize;
+    uint32_t newsize;
     int ret = ST_CONTINUE;
     struct gen_ivtbl *ivtbl;
 
     if (existing) {
 	ivtbl = (struct gen_ivtbl *)*v;
-	if ((long)ivup->index >= ivtbl->numiv) {
+	if (ivup->index >= ivtbl->numiv) {
 	    goto resize;
 	}
 	ret = ST_STOP;
@@ -1127,7 +1127,7 @@ generic_ivar_defined(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L1127
     if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) return Qfalse;
     if (!gen_ivtbl_get(obj, &ivtbl)) return Qfalse;
 
-    if (((long)index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef))
+    if ((index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef))
 	return Qtrue;
 
     return Qfalse;
@@ -1145,7 +1145,7 @@ generic_ivar_remove(VALUE obj, ID id, VA https://github.com/ruby/ruby/blob/trunk/variable.c#L1145
     if (!st_lookup(iv_index_tbl, key, &index)) return 0;
     if (!gen_ivtbl_get(obj, &ivtbl)) return 0;
 
-    if ((long)index < ivtbl->numiv) {
+    if (index < ivtbl->numiv) {
 	if (ivtbl->ivptr[index] != Qundef) {
 	    *valp = ivtbl->ivptr[index];
 	    ivtbl->ivptr[index] = Qundef;
@@ -1158,7 +1158,7 @@ generic_ivar_remove(VALUE obj, ID id, VA https://github.com/ruby/ruby/blob/trunk/variable.c#L1158
 static void
 gen_ivtbl_mark(const struct gen_ivtbl *ivtbl)
 {
-    long i;
+    uint32_t i;
 
     for (i = 0; i < ivtbl->numiv; i++) {
 	rb_gc_mark(ivtbl->ivptr[i]);
@@ -1205,7 +1205,7 @@ rb_generic_ivar_memsize(VALUE obj) https://github.com/ruby/ruby/blob/trunk/variable.c#L1205
 static size_t
 gen_ivtbl_count(const struct gen_ivtbl *ivtbl)
 {
-    long i;
+    uint32_t i;
     size_t n = 0;
 
     for (i = 0; i < ivtbl->numiv; i++) {
@@ -1222,7 +1222,7 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE u https://github.com/ruby/ruby/blob/trunk/variable.c#L1222
 {
     VALUE val, *ptr;
     struct st_table *iv_index_tbl;
-    long len;
+    uint32_t len;
     st_data_t index;
 
     if (SPECIAL_CONST_P(obj)) return undef;
@@ -1233,7 +1233,7 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE u https://github.com/ruby/ruby/blob/trunk/variable.c#L1233
         iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
         if (!iv_index_tbl) break;
         if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
-        if (len <= (long)index) break;
+        if (len <= index) break;
         val = ptr[index];
         if (val != Qundef)
             return val;
@@ -1276,7 +1276,7 @@ rb_ivar_delete(VALUE obj, ID id, VALUE u https://github.com/ruby/ruby/blob/trunk/variable.c#L1276
 {
     VALUE val, *ptr;
     struct st_table *iv_index_tbl;
-    long len;
+    uint32_t len;
     st_data_t index;
 
     rb_check_frozen(obj);
@@ -1287,7 +1287,7 @@ rb_ivar_delete(VALUE obj, ID id, VALUE u https://github.com/ruby/ruby/blob/trunk/variable.c#L1287
         iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
         if (!iv_index_tbl) break;
         if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
-        if (len <= (long)index) break;
+        if (len <= index) break;
         val = ptr[index];
         ptr[index] = Qundef;
         if (val != Qundef)
@@ -1360,7 +1360,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1360
 rb_ivar_set(VALUE obj, ID id, VALUE val)
 {
     struct ivar_update ivup;
-    long i, len;
+    uint32_t i, len;
 
     rb_check_frozen(obj);
 
@@ -1370,7 +1370,7 @@ rb_ivar_set(VALUE obj, ID id, VALUE val) https://github.com/ruby/ruby/blob/trunk/variable.c#L1370
         ivup.u.iv_index_tbl = iv_index_tbl_make(obj);
         iv_index_tbl_extend(&ivup, id);
         len = ROBJECT_NUMIV(obj);
-        if (len <= (long)ivup.index) {
+        if (len <= ivup.index) {
             VALUE *ptr = ROBJECT_IVPTR(obj);
             if (ivup.index < ROBJECT_EMBED_LEN_MAX) {
                 RBASIC(obj)->flags |= ROBJECT_EMBED;
@@ -1426,7 +1426,7 @@ rb_ivar_defined(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L1426
         iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
         if (!iv_index_tbl) break;
         if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
-        if (ROBJECT_NUMIV(obj) <= (long)index) break;
+        if (ROBJECT_NUMIV(obj) <= index) break;
         val = ROBJECT_IVPTR(obj)[index];
         if (val != Qundef)
             return Qtrue;
@@ -1454,8 +1454,8 @@ static int https://github.com/ruby/ruby/blob/trunk/variable.c#L1454
 obj_ivar_i(st_data_t key, st_data_t index, st_data_t arg)
 {
     struct obj_ivar_tag *data = (struct obj_ivar_tag *)arg;
-    if ((long)index < ROBJECT_NUMIV(data->obj)) {
-        VALUE val = ROBJECT_IVPTR(data->obj)[(long)index];
+    if (index < ROBJECT_NUMIV(data->obj)) {
+        VALUE val = ROBJECT_IVPTR(data->obj)[index];
         if (val != Qundef) {
             return (data->func)((ID)key, val, data->arg);
         }
@@ -1491,7 +1491,7 @@ gen_ivar_each_i(st_data_t key, st_data_t https://github.com/ruby/ruby/blob/trunk/variable.c#L1491
 {
     struct gen_ivar_tag *arg = (struct gen_ivar_tag *)data;
 
-    if ((long)index < arg->ivtbl->numiv) {
+    if (index < arg->ivtbl->numiv) {
         VALUE val = arg->ivtbl->ivptr[index];
         if (val != Qundef) {
             return (arg->func)((ID)key, val, arg->arg);
@@ -1530,9 +1530,8 @@ gen_ivar_copy(ID id, VALUE val, st_data_ https://github.com/ruby/ruby/blob/trunk/variable.c#L1530
     ivup.iv_extended = 0;
     ivup.u.iv_index_tbl = c->iv_index_tbl;
     iv_index_tbl_extend(&ivup, id);
-    if ((long)ivup.index >= c->ivtbl->numiv) {
-	size_t newsize = iv_index_tbl_newsize(&ivup);
-
+    if (ivup.index >= c->ivtbl->numiv) {
+	uint32_t newsize = iv_index_tbl_newsize(&ivup);
 	c->ivtbl = gen_ivtbl_resize(c->ivtbl, newsize);
     }
     c->ivtbl->ivptr[ivup.index] = val;
@@ -1559,7 +1558,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1558
     }
     if (gen_ivtbl_get(obj, &ivtbl)) {
 	struct givar_copy c;
-	long i;
+	uint32_t i;
 
 	if (gen_ivtbl_count(ivtbl) == 0)
 	    goto clear;
@@ -1746,7 +1745,7 @@ rb_obj_remove_instance_variable(VALUE ob https://github.com/ruby/ruby/blob/trunk/variable.c#L1745
         iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
         if (!iv_index_tbl) break;
         if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
-        if (ROBJECT_NUMIV(obj) <= (long)index) break;
+        if (ROBJECT_NUMIV(obj) <= index) break;
         val = ROBJECT_IVPTR(obj)[index];
         if (val != Qundef) {
             ROBJECT_IVPTR(obj)[index] = Qundef;
Index: object.c
===================================================================
--- object.c	(revision 54699)
+++ object.c	(revision 54700)
@@ -268,7 +268,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L268
 	RBASIC(dest)->flags |= ROBJECT_EMBED;
     }
     else {
-	long len = ROBJECT(obj)->as.heap.numiv;
+	uint32_t len = ROBJECT(obj)->as.heap.numiv;
 	VALUE *ptr = 0;
 	if (len > 0) {
 	    ptr = ALLOC_N(VALUE, len);
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 54699)
+++ vm_insnhelper.c	(revision 54700)
@@ -781,11 +781,11 @@ vm_getivar(VALUE obj, ID id, IC ic, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L781
     if (RB_TYPE_P(obj, T_OBJECT)) {
 	VALUE val = Qundef;
 	VALUE klass = RBASIC(obj)->klass;
-	const long len = ROBJECT_NUMIV(obj);
+	const uint32_t len = ROBJECT_NUMIV(obj);
 	const VALUE *const ptr = ROBJECT_IVPTR(obj);
 
 	if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(klass))) {
-	    long index = !is_attr ? (long)ic->ic_value.index : (long)(cc->aux.index - 1);
+	    st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1);
 
 	    if (index < len) {
 		val = ptr[index];
@@ -797,7 +797,7 @@ vm_getivar(VALUE obj, ID id, IC ic, stru https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L797
 
 	    if (iv_index_tbl) {
 		if (st_lookup(iv_index_tbl, id, &index)) {
-		    if ((long)index < len) {
+		    if (index < len) {
 			val = ptr[index];
 		    }
 		    if (!is_attr) {
@@ -837,11 +837,10 @@ vm_setivar(VALUE obj, ID id, VALUE val, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L837
 	if (LIKELY(
 	    (!is_attr && ic->ic_serial == RCLASS_SERIAL(klass)) ||
 	    (is_attr && cc->aux.index > 0))) {
-	    long index = !is_attr ? (long)ic->ic_value.index : (long)cc->aux.index-1;
-	    long len = ROBJECT_NUMIV(obj);
 	    VALUE *ptr = ROBJECT_IVPTR(obj);
+	    index = !is_attr ? ic->ic_value.index : cc->aux.index-1;
 
-	    if (index < len) {
+	    if (index < ROBJECT_NUMIV(obj)) {
 		RB_OBJ_WRITE(obj, &ptr[index], val);
 		return val; /* inline cache hit */
 	    }

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

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