ruby-changes:55936
From: Nobuyoshi <ko1@a...>
Date: Fri, 31 May 2019 16:32:50 +0900 (JST)
Subject: [ruby-changes:55936] Nobuyoshi Nakada: b1aecef873 (trunk): Use UNALIGNED_MEMBER_PTR
https://git.ruby-lang.org/ruby.git/commit/?id=b1aecef873 From b1aecef87364631b0001dd2aafc432931e19a98f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 31 May 2019 15:58:50 +0900 Subject: Use UNALIGNED_MEMBER_PTR * internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR): moved from eval_intern.h. * compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries` in `struct iseq_catch_table`. * vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body` in `rb_method_definition_t`. diff --git a/compile.c b/compile.c index 6135eb0..64bde0c 100644 --- a/compile.c +++ b/compile.c @@ -1263,7 +1263,8 @@ update_catch_except_flags(struct rb_iseq_constant_body *body) https://github.com/ruby/ruby/blob/trunk/compile.c#L1263 return; for (i = 0; i < ct->size; i++) { - const struct iseq_catch_table_entry *entry = &ct->entries[i]; + const struct iseq_catch_table_entry *entry = + UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->type != CATCH_TYPE_BREAK && entry->type != CATCH_TYPE_NEXT && entry->type != CATCH_TYPE_REDO) { @@ -2322,7 +2323,7 @@ iseq_set_exception_table(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L2323 for (i = 0; i < table->size; i++) { ptr = RARRAY_CONST_PTR_TRANSIENT(tptr[i]); - entry = &table->entries[i]; + entry = UNALIGNED_MEMBER_PTR(table, entries[i]); entry->type = (enum catch_type)(ptr[0] & 0xffff); entry->start = label_get_position((LABEL *)(ptr[1] & ~1)); entry->end = label_get_position((LABEL *)(ptr[2] & ~1)); diff --git a/eval_intern.h b/eval_intern.h index ad74408..db28aa1 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -157,23 +157,6 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *); https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L157 # define VAR_NOCLOBBERED(var) var #endif -#if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \ - (defined(__clang__) || GCC_VERSION_SINCE(9, 0, 0)) -# define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \ - COMPILER_WARNING_PUSH; \ - COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \ - typeof(expr) unaligned_member_access_result = (expr); \ - COMPILER_WARNING_POP; \ - unaligned_member_access_result; \ -}) -#else -# define UNALIGNED_MEMBER_ACCESS(expr) expr -#endif -#define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem) - -#undef RB_OBJ_WRITE -#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)) - /* clear ec->tag->state, and return the value */ static inline int rb_ec_tag_state(const rb_execution_context_t *ec) diff --git a/internal.h b/internal.h index fcaffa2..4312f8d 100644 --- a/internal.h +++ b/internal.h @@ -2511,6 +2511,23 @@ rb_obj_builtin_type(VALUE obj) https://github.com/ruby/ruby/blob/trunk/internal.h#L2511 #define COMPILER_WARNING_PRAGMA(str) COMPILER_WARNING_PRAGMA_(str) #define COMPILER_WARNING_PRAGMA_(str) _Pragma(#str) +#if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \ + (defined(__clang__) || GCC_VERSION_SINCE(9, 0, 0)) +# define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \ + COMPILER_WARNING_PUSH; \ + COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \ + typeof(expr) unaligned_member_access_result = (expr); \ + COMPILER_WARNING_POP; \ + unaligned_member_access_result; \ +}) +#else +# define UNALIGNED_MEMBER_ACCESS(expr) expr +#endif +#define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem) + +#undef RB_OBJ_WRITE +#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ diff --git a/iseq.c b/iseq.c index 916715e..fa4e72d 100644 --- a/iseq.c +++ b/iseq.c @@ -256,7 +256,7 @@ rb_iseq_update_references(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L256 unsigned int i; for(i = 0; i < table->size; i++) { struct iseq_catch_table_entry *entry; - entry = &table->entries[i]; + entry = UNALIGNED_MEMBER_PTR(table, entries[i]); if (entry->iseq) { entry->iseq = (rb_iseq_t *)rb_gc_location((VALUE)entry->iseq); } @@ -315,7 +315,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L315 unsigned int i; for(i = 0; i < table->size; i++) { const struct iseq_catch_table_entry *entry; - entry = &table->entries[i]; + entry = UNALIGNED_MEMBER_PTR(table, entries[i]); if (entry->iseq) { rb_gc_mark_no_pin((VALUE)entry->iseq); } @@ -2138,7 +2138,8 @@ rb_iseq_disasm_recursive(const rb_iseq_t *iseq, VALUE indent) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2138 rb_str_cat_cstr(indent, "| "); indent_str = RSTRING_PTR(indent); for (i = 0; i < body->catch_table->size; i++) { - const struct iseq_catch_table_entry *entry = &body->catch_table->entries[i]; + const struct iseq_catch_table_entry *entry = + UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]); rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n", @@ -2272,7 +2273,8 @@ iseq_iterate_children(const rb_iseq_t *iseq, void (*iter_func)(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L2273 if (body->catch_table) { for (i = 0; i < body->catch_table->size; i++) { - const struct iseq_catch_table_entry *entry = &body->catch_table->entries[i]; + const struct iseq_catch_table_entry *entry = + UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]); child = entry->iseq; if (child) { if (rb_hash_aref(all_children, (VALUE)child) == Qnil) { @@ -2782,7 +2784,8 @@ iseq_data_to_ary(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2784 /* exception */ if (iseq_body->catch_table) for (i=0; i<iseq_body->catch_table->size; i++) { VALUE ary = rb_ary_new(); - const struct iseq_catch_table_entry *entry = &iseq_body->catch_table->entries[i]; + const struct iseq_catch_table_entry *entry = + UNALIGNED_MEMBER_PTR(iseq_body->catch_table, entries[i]); rb_ary_push(ary, exception_type2symbol(entry->type)); if (entry->iseq) { rb_ary_push(ary, iseq_data_to_ary(rb_iseq_check(entry->iseq))); diff --git a/thread_sync.c b/thread_sync.c index 4c253f0..2123458 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -903,7 +903,7 @@ queue_do_pop(VALUE self, struct rb_queue *q, int should_block) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L903 qw.w.th = GET_THREAD(); qw.as.q = q; - list_add_tail(&qw.as.q->waitq, &qw.w.node); + list_add_tail(queue_waitq(qw.as.q), &qw.w.node); qw.as.q->num_waiting++; rb_ensure(queue_sleep, self, queue_sleep_done, (VALUE)&qw); diff --git a/vm.c b/vm.c index 9dd97e7..3f5a619 100644 --- a/vm.c +++ b/vm.c @@ -1956,7 +1956,7 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L1956 else { ct = cfp->iseq->body->catch_table; if (ct) for (i = 0; i < ct->size; i++) { - entry = &ct->entries[i]; + entry = UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->start < epc && entry->end >= epc) { if (entry->type == CATCH_TYPE_ENSURE) { catch_iseq = entry->iseq; @@ -1992,7 +1992,7 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L1992 if (state == TAG_RAISE) { ct = cfp->iseq->body->catch_table; if (ct) for (i = 0; i < ct->size; i++) { - entry = &ct->entries[i]; + entry = UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->start < epc && entry->end >= epc) { if (entry->type == CATCH_TYPE_RESCUE || @@ -2008,7 +2008,7 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L2008 else if (state == TAG_RETRY) { ct = cfp->iseq->body->catch_table; if (ct) for (i = 0; i < ct->size; i++) { - entry = &ct->entries[i]; + entry = UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->start < epc && entry->end >= epc) { if (entry->type == CATCH_TYPE_ENSURE) { @@ -2035,7 +2035,7 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L2035 search_restart_point: ct = cfp->iseq->body->catch_table; if (ct) for (i = 0; i < ct->size; i++) { - entry = &ct->entries[i]; + entry = UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->start < epc && entry->end >= epc) { if (entry->type == CATCH_TYPE_ENSURE) { @@ -2073,7 +2073,7 @@ vm_exec_handle_exception(rb_execution_context_t *ec, enum ruby_tag_type state, https://github.com/ruby/ruby/blob/trunk/vm.c#L2073 else { ct = cfp->iseq->body->catch_table; if (ct) for (i = 0; i < ct->size; i++) { - entry = &ct->entries[i]; + entry = UNALIGNED_MEMBER_PTR(ct, entries[i]); if (entry->start < epc && entry->end >= epc) { if (entry->type == CATCH_TYPE_ENSURE) { diff --git a/vm_eval.c b/vm_eval.c index 285eb77..be645ec 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -65,7 +65,7 @@ vm_call0_cfunc_with_frame(rb_execution_context_t* ec, struct rb_calling_info *ca https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L65 { VALUE val; const rb_callable_method_entry_t *me = cc->me; - const rb_method_cfunc_t *cfunc = &me->def->body.cfunc; + const rb_method_cfunc_t *cfunc = UNALIGNED_MEMBER_PTR(me->def, body.cfunc); int len = cfunc->argc; VALUE recv = calling->recv; int argc = calling->argc; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index b69eaf1..7946f9a (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/