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

ruby-changes:49697

From: nobu <ko1@a...>
Date: Sun, 14 Jan 2018 20:19:25 +0900 (JST)
Subject: [ruby-changes:49697] nobu:r61814 (trunk): exclude flexible array size with old compilers

nobu	2018-01-14 20:19:18 +0900 (Sun, 14 Jan 2018)

  New Revision: 61814

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

  Log:
    exclude flexible array size with old compilers

  Modified files:
    trunk/compile.c
    trunk/file.c
    trunk/iseq.c
    trunk/iseq.h
    trunk/string.c
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 61813)
+++ variable.c	(revision 61814)
@@ -1001,7 +1001,7 @@ generic_ivar_get(VALUE obj, ID id, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1001
 static size_t
 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 *
Index: iseq.c
===================================================================
--- iseq.c	(revision 61813)
+++ iseq.c	(revision 61814)
@@ -208,7 +208,7 @@ iseq_memsize(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L208
 
 	cur = compile_data->storage_head;
 	while (cur) {
-	    size += cur->size + sizeof(struct iseq_compile_data_storage);
+	    size += cur->size + offsetof(struct iseq_compile_data_storage, buff);
 	    cur = cur->next;
 	}
     }
@@ -333,7 +333,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L333
     ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current =
       (struct iseq_compile_data_storage *)
 	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));
     ISEQ_COMPILE_DATA(iseq)->storage_head->pos = 0;
Index: iseq.h
===================================================================
--- iseq.h	(revision 61813)
+++ iseq.h	(revision 61814)
@@ -256,11 +256,12 @@ static inline int https://github.com/ruby/ruby/blob/trunk/iseq.h#L256
 iseq_catch_table_bytes(int n)
 {
     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);
-    return (int)(sizeof(struct iseq_catch_table) +
-		 n * sizeof(struct iseq_catch_table_entry));
+    return (int)(offsetof(struct iseq_catch_table, entries) +
+		 n * catch_table_entry_size);
 }
 
 #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)
Index: string.c
===================================================================
--- string.c	(revision 61813)
+++ string.c	(revision 61814)
@@ -6410,7 +6410,7 @@ rb_str_casemap(VALUE source, OnigCaseFol https://github.com/ruby/ruby/blob/trunk/string.c#L6410
 	if (CASEMAP_DEBUG) {
 	    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->next = NULL;
 	current_buffer->capa = capa;
Index: compile.c
===================================================================
--- compile.c	(revision 61813)
+++ compile.c	(revision 61814)
@@ -868,7 +868,7 @@ compile_data_alloc(rb_iseq_t *iseq, size https://github.com/ruby/ruby/blob/trunk/compile.c#L868
 	    alloc_size *= 2;
 	}
 	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->next = 0;
 	storage->pos = 0;
Index: file.c
===================================================================
--- file.c	(revision 61813)
+++ file.c	(revision 61814)
@@ -388,7 +388,7 @@ apply2files(int (*func)(const char *, vo https://github.com/ruby/ruby/blob/trunk/file.c#L388
 {
     VALUE v;
     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);
 
     aa->errnum = 0;

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

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