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

iseq.h (struct iseq_catch_table_entry, iseq_compile_data_storage): Use FLEX_ARY_LEN

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-01-13 12:44:17 +00:00
parent 879df66d96
commit 7ad9975fe7
3 changed files with 6 additions and 10 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_ISEQ_COMPILE_DATA_STORAGE); sizeof(struct iseq_compile_data_storage));
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;

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_ISEQ_COMPILE_DATA_STORAGE; size += cur->size + sizeof(struct iseq_compile_data_storage);
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_ISEQ_COMPILE_DATA_STORAGE); sizeof(struct iseq_compile_data_storage));
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;

10
iseq.h
View file

@ -249,7 +249,7 @@ struct iseq_catch_table_entry {
PACKED_STRUCT_UNALIGNED(struct iseq_catch_table { PACKED_STRUCT_UNALIGNED(struct iseq_catch_table {
unsigned int size; unsigned int size;
struct iseq_catch_table_entry entries[1]; /* flexible array */ struct iseq_catch_table_entry entries[FLEX_ARY_LEN];
}); });
static inline int static inline int
@ -260,7 +260,7 @@ iseq_catch_table_bytes(int n)
}; };
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)(sizeof(struct iseq_catch_table) +
(n - 1) * sizeof(struct iseq_catch_table_entry)); n * sizeof(struct iseq_catch_table_entry));
} }
#define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512) #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
@ -269,13 +269,9 @@ struct iseq_compile_data_storage {
struct iseq_compile_data_storage *next; struct iseq_compile_data_storage *next;
unsigned int pos; unsigned int pos;
unsigned int size; unsigned int size;
char buff[1]; /* flexible array */ char buff[FLEX_ARY_LEN];
}; };
/* account for flexible array */
#define SIZEOF_ISEQ_COMPILE_DATA_STORAGE \
(sizeof(struct iseq_compile_data_storage) - 1)
/* defined? */ /* defined? */
enum defined_type { enum defined_type {