summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-17 04:46:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-17 04:46:26 +0000
commit86a16b36ae7d6149080588cbd196371888fb48f4 (patch)
treec268dc49a5338530fca74632419e24af17bb1f6e /compile.c
parent1bf9dec04c59ebe7db098a9439ee943db37ace7b (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index 303054e6de..2291a61700 100644
--- a/compile.c
+++ b/compile.c
@@ -8140,9 +8140,6 @@ rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
/* 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 {
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, struct ibf_header *header)
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, struct ibf_header *header)
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 *dump, struct ibf_header *header)
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++) {