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

ruby-changes:50631

From: nobu <ko1@a...>
Date: Sat, 17 Mar 2018 13:46:30 +0900 (JST)
Subject: [ruby-changes:50631] nobu:r62791 (trunk): compile.c: align offsets

nobu	2018-03-17 13:46:26 +0900 (Sat, 17 Mar 2018)

  New Revision: 62791

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

  Log:
    compile.c: align offsets
    
    * compile.c (ibf_dump_align): expand the buffer for alignment.
    
    * compile.c (ibf_dump_iseq_list, ibf_dump_object_list): align as
      ibf_offset_t.  not all processors do not allow unaligned word,
      or larger, access.

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 62790)
+++ compile.c	(revision 62791)
@@ -8140,9 +8140,6 @@ rb_method_for_self_aset(VALUE name, VALU https://github.com/ruby/ruby/blob/trunk/compile.c#L8140
 
 /* ISeq binary format */
 
-#ifdef __sparc
-#define IBF_ISEQ_DEBUG 1
-#endif
 #ifndef IBF_ISEQ_DEBUG
 #define IBF_ISEQ_DEBUG 0
 #endif
@@ -8190,7 +8187,22 @@ struct ibf_load { https://github.com/ruby/ruby/blob/trunk/compile.c#L8187
 static ibf_offset_t
 ibf_dump_pos(struct ibf_dump *dump)
 {
-    return (unsigned int)rb_str_strlen(dump->str);
+    long pos = RSTRING_LEN(dump->str);
+#if SIZEOF_LONG > SIZEOF_INT
+    if (pos >= UINT_MAX) {
+        rb_raise(rb_eRuntimeError, "dump size exceeds");
+    }
+#endif
+    return (unsigned int)pos;
+}
+
+static void
+ibf_dump_align(struct ibf_dump *dump, size_t align)
+{
+    ibf_offset_t pos = ibf_dump_pos(dump);
+    if (pos % align) {
+        rb_str_modify_expand(dump->str, align - (pos % align));
+    }
 }
 
 static ibf_offset_t
@@ -8826,6 +8838,7 @@ ibf_dump_iseq_list(struct ibf_dump *dump https://github.com/ruby/ruby/blob/trunk/compile.c#L8838
 	list[i] = (ibf_offset_t)NUM2LONG(rb_ary_entry(dump->iseq_list, i));
     }
 
+    ibf_dump_align(dump, sizeof(ibf_offset_t));
     header->iseq_list_offset = ibf_dump_write(dump, list, sizeof(ibf_offset_t) * size);
     header->iseq_list_size = (unsigned int)size;
 }
@@ -8866,6 +8879,7 @@ ibf_dump_id_list(struct ibf_dump *dump, https://github.com/ruby/ruby/blob/trunk/compile.c#L8879
 
     st_foreach(dump->id_table, ibf_dump_id_list_i, (st_data_t)&arg);
 
+    ibf_dump_align(dump, sizeof(long));
     header->id_list_offset = ibf_dump_write(dump, arg.list, sizeof(long) * size);
     header->id_list_size = (unsigned int)size;
 }
@@ -9416,6 +9430,7 @@ ibf_dump_object_list(struct ibf_dump *du https://github.com/ruby/ruby/blob/trunk/compile.c#L9430
 	rb_ary_push(list, UINT2NUM(offset));
     }
     size = i;
+    ibf_dump_align(dump, sizeof(ibf_offset_t));
     header->object_list_offset = ibf_dump_pos(dump);
 
     for (i=0; i<size; i++) {

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

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