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

ruby-changes:39276

From: ko1 <ko1@a...>
Date: Thu, 23 Jul 2015 18:53:24 +0900 (JST)
Subject: [ruby-changes:39276] ko1:r51357 (trunk): * vm_core.h: constify rb_iseq_constant_body::local_table and

ko1	2015-07-23 18:53:16 +0900 (Thu, 23 Jul 2015)

  New Revision: 51357

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

  Log:
    * vm_core.h: constify rb_iseq_constant_body::local_table and
      rb_iseq_param_keyword::table and
      rb_iseq_param_keyword::default_values.
    * compile.c: catch up this fix.
    * iseq.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51356)
+++ ChangeLog	(revision 51357)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jul 23 18:50:43 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_core.h: constify rb_iseq_constant_body::local_table and 
+	  rb_iseq_param_keyword::table and
+	  rb_iseq_param_keyword::default_values.
+
+	* compile.c: catch up this fix.
+
+	* iseq.c: ditto.
+
 Thu Jul 23 17:30:43 2015  Koichi Sasada  <ko1@a...>
 
 	* vm_core.h: constify rb_iseq_constant_body::iseq_encoded and
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 51356)
+++ vm_core.h	(revision 51357)
@@ -322,8 +322,8 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L322
 	    int required_num;
 	    int bits_start;
 	    int rest_start;
-	    ID *table;
-	    VALUE *default_values;
+	    const ID *table;
+	    const VALUE *default_values;
 	} *keyword;
     } param;
 
@@ -332,7 +332,7 @@ struct rb_iseq_constant_body { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L332
     /* insn info, must be freed */
     struct iseq_line_info_entry *line_info_table;
 
-    ID *local_table;		/* must free */
+    const ID *local_table;		/* must free */
 
     /* catch table */
     struct iseq_catch_table *catch_table;
Index: iseq.c
===================================================================
--- iseq.c	(revision 51356)
+++ iseq.c	(revision 51357)
@@ -1365,7 +1365,7 @@ rb_iseq_disasm(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1365
     unsigned int size;
     int i;
     long l;
-    ID *tbl;
+    const ID *tbl;
     size_t n;
     enum {header_minlen = 72};
 
Index: compile.c
===================================================================
--- compile.c	(revision 51356)
+++ compile.c	(revision 51357)
@@ -1056,12 +1056,13 @@ static int https://github.com/ruby/ruby/blob/trunk/compile.c#L1056
 iseq_set_exception_local_table(rb_iseq_t *iseq)
 {
     ID id_dollar_bang;
+    ID *ids = (ID *)ALLOC_N(ID, 1);
 
     CONST_ID(id_dollar_bang, "#$!");
-    iseq->body->local_table = (ID *)ALLOC_N(ID, 1);
     iseq->body->local_table_size = 1;
     iseq->body->local_size = iseq->body->local_table_size + 1;
-    iseq->body->local_table[0] = id_dollar_bang;
+    ids[0] = id_dollar_bang;
+    iseq->body->local_table = ids;
     return COMPILE_OK;
 }
 
@@ -1279,12 +1280,17 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L1280
 	    }
 	    iseq->body->param.keyword->required_num = rkw;
 	    iseq->body->param.keyword->table = &iseq->body->local_table[iseq->body->param.keyword->bits_start - iseq->body->param.keyword->num];
-	    iseq->body->param.keyword->default_values = ALLOC_N(VALUE, RARRAY_LEN(default_values));
 
-	    for (i = 0; i < RARRAY_LEN(default_values); i++) {
-		VALUE dv = RARRAY_AREF(default_values, i);
-		if (dv == complex_mark) dv = Qundef;
-		iseq->body->param.keyword->default_values[i] = dv;
+	    {
+		VALUE *dvs = ALLOC_N(VALUE, RARRAY_LEN(default_values));
+
+		for (i = 0; i < RARRAY_LEN(default_values); i++) {
+		    VALUE dv = RARRAY_AREF(default_values, i);
+		    if (dv == complex_mark) dv = Qundef;
+		    dvs[i] = dv;
+		}
+
+		iseq->body->param.keyword->default_values = dvs;
 	    }
 	}
 	else if (args->kw_rest_arg) {
@@ -1349,8 +1355,9 @@ iseq_set_local_table(rb_iseq_t *iseq, co https://github.com/ruby/ruby/blob/trunk/compile.c#L1355
     }
 
     if (size > 0) {
-	iseq->body->local_table = (ID *)ALLOC_N(ID, size);
-	MEMCPY(iseq->body->local_table, tbl, ID, size);
+	ID *ids = (ID *)ALLOC_N(ID, size);
+	MEMCPY(ids, tbl, ID, size);
+	iseq->body->local_table = ids;
     }
 
     iseq->body->local_size = iseq->body->local_table_size = size;
@@ -6078,6 +6085,8 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE par https://github.com/ruby/ruby/blob/trunk/compile.c#L6085
     int len = RARRAY_LENINT(keywords);
     int default_len;
     VALUE key, sym, default_val;
+    VALUE *dvs;
+    ID *ids;
 
     iseq->body->param.flags.has_kw = TRUE;
 
@@ -6086,7 +6095,7 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE par https://github.com/ruby/ruby/blob/trunk/compile.c#L6095
 #define SYM(s) ID2SYM(rb_intern(#s))
     (void)int_param(&iseq->body->param.keyword->bits_start, params, SYM(kwbits));
     i = iseq->body->param.keyword->bits_start - iseq->body->param.keyword->num;
-    iseq->body->param.keyword->table = &iseq->body->local_table[i];
+    ids = (VALUE *)&iseq->body->local_table[i];
 #undef SYM
 
     /* required args */
@@ -6096,17 +6105,17 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE par https://github.com/ruby/ruby/blob/trunk/compile.c#L6105
 	if (!SYMBOL_P(val)) {
 	    goto default_values;
 	}
-	iseq->body->param.keyword->table[i] = SYM2ID(val);
+	ids[i] = SYM2ID(val);
 	iseq->body->param.keyword->required_num++;
     }
 
-default_values: /* note: we intentionally preserve `i' from previous loop */
+  default_values: /* note: we intentionally preserve `i' from previous loop */
     default_len = len - i;
     if (default_len == 0) {
 	return;
     }
 
-    iseq->body->param.keyword->default_values = ALLOC_N(VALUE, default_len);
+    dvs = ALLOC_N(VALUE, default_len);
 
     for (j = 0; i < len; i++, j++) {
 	key = RARRAY_AREF(keywords, i);
@@ -6126,9 +6135,12 @@ default_values: /* note: we intentionall https://github.com/ruby/ruby/blob/trunk/compile.c#L6135
 		     "keyword default has unsupported len %+"PRIsVALUE,
 		     key);
 	}
-	iseq->body->param.keyword->table[i] = SYM2ID(sym);
-	iseq->body->param.keyword->default_values[j] = default_val;
+	ids[i] = SYM2ID(sym);
+	dvs[j] = default_val;
     }
+
+    iseq->body->param.keyword->table = ids;
+    iseq->body->param.keyword->default_values = dvs;
 }
 
 void

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

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