1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

exclude flexible array size with old compilers

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-01-14 11:19:18 +00:00
parent bbea027027
commit 6b5e0bd98c
6 changed files with 10 additions and 9 deletions

View file

@ -868,7 +868,7 @@ compile_data_alloc(rb_iseq_t *iseq, size_t size)
alloc_size *= 2; alloc_size *= 2;
} }
storage->next = (void *)ALLOC_N(char, alloc_size + storage->next = (void *)ALLOC_N(char, alloc_size +
sizeof(struct iseq_compile_data_storage)); offsetof(struct iseq_compile_data_storage, buff));
storage = ISEQ_COMPILE_DATA(iseq)->storage_current = storage->next; storage = ISEQ_COMPILE_DATA(iseq)->storage_current = storage->next;
storage->next = 0; storage->next = 0;
storage->pos = 0; storage->pos = 0;

2
file.c
View file

@ -388,7 +388,7 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
{ {
VALUE v; VALUE v;
const size_t size = sizeof(struct apply_filename); const size_t size = sizeof(struct apply_filename);
const long len = (long)(sizeof(struct apply_arg) + (size * argc)); const long len = (long)(offsetof(struct apply_arg, fn) + (size * argc));
struct apply_arg *aa = ALLOCV(v, len); struct apply_arg *aa = ALLOCV(v, len);
aa->errnum = 0; aa->errnum = 0;

4
iseq.c
View file

@ -208,7 +208,7 @@ iseq_memsize(const rb_iseq_t *iseq)
cur = compile_data->storage_head; cur = compile_data->storage_head;
while (cur) { while (cur) {
size += cur->size + sizeof(struct iseq_compile_data_storage); size += cur->size + offsetof(struct iseq_compile_data_storage, buff);
cur = cur->next; cur = cur->next;
} }
} }
@ -333,7 +333,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current = ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current =
(struct iseq_compile_data_storage *) (struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE + ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
sizeof(struct iseq_compile_data_storage)); offsetof(struct iseq_compile_data_storage, buff));
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->catch_table_ary, rb_ary_tmp_new(3)); RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->catch_table_ary, rb_ary_tmp_new(3));
ISEQ_COMPILE_DATA(iseq)->storage_head->pos = 0; ISEQ_COMPILE_DATA(iseq)->storage_head->pos = 0;

7
iseq.h
View file

@ -256,11 +256,12 @@ static inline int
iseq_catch_table_bytes(int n) iseq_catch_table_bytes(int n)
{ {
enum { enum {
catch_table_entries_max = (INT_MAX - sizeof(struct iseq_catch_table)) / sizeof(struct iseq_catch_table_entry) catch_table_entry_size = sizeof(struct iseq_catch_table_entry),
catch_table_entries_max = (INT_MAX - offsetof(struct iseq_catch_table, entries)) / catch_table_entry_size
}; };
if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n); if (n > catch_table_entries_max) rb_fatal("too large iseq_catch_table - %d", n);
return (int)(sizeof(struct iseq_catch_table) + return (int)(offsetof(struct iseq_catch_table, entries) +
n * sizeof(struct iseq_catch_table_entry)); n * catch_table_entry_size);
} }
#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512) #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)

View file

@ -6410,7 +6410,7 @@ rb_str_casemap(VALUE source, OnigCaseFoldType *flags, rb_encoding *enc)
if (CASEMAP_DEBUG) { if (CASEMAP_DEBUG) {
fprintf(stderr, "Buffer allocation, capa is %"PRIuSIZE"\n", capa); /* for tuning */ fprintf(stderr, "Buffer allocation, capa is %"PRIuSIZE"\n", capa); /* for tuning */
} }
current_buffer->next = xmalloc(sizeof(mapping_buffer) + capa); current_buffer->next = xmalloc(offsetof(mapping_buffer, space) + capa);
current_buffer = current_buffer->next; current_buffer = current_buffer->next;
current_buffer->next = NULL; current_buffer->next = NULL;
current_buffer->capa = capa; current_buffer->capa = capa;

View file

@ -1001,7 +1001,7 @@ generic_ivar_get(VALUE obj, ID id, VALUE undef)
static size_t static size_t
gen_ivtbl_bytes(size_t n) gen_ivtbl_bytes(size_t n)
{ {
return sizeof(struct gen_ivtbl) + n * sizeof(VALUE); return offsetof(struct gen_ivtbl, ivptr) + n * sizeof(VALUE);
} }
static struct gen_ivtbl * static struct gen_ivtbl *