summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c5
-rw-r--r--eval_intern.h17
-rw-r--r--internal.h17
-rw-r--r--iseq.c13
-rw-r--r--thread_sync.c2
-rw-r--r--vm.c10
-rw-r--r--vm_eval.c2
-rw-r--r--vm_insnhelper.c5
8 files changed, 38 insertions, 33 deletions
diff --git a/compile.c b/compile.c
index 6135eb09ad..64bde0c962 100644
--- a/compile.c
+++ b/compile.c
@@ -1263,7 +1263,8 @@ update_catch_except_flags(struct rb_iseq_constant_body *body)
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)
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 ad74408ff7..db28aa1598 100644
--- a/eval_intern.h
+++ b/eval_intern.h
@@ -157,23 +157,6 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
# 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 fcaffa26be..4312f8d442 100644
--- a/internal.h
+++ b/internal.h
@@ -2511,6 +2511,23 @@ rb_obj_builtin_type(VALUE obj)
#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 916715e23f..fa4e72d2cd 100644
--- a/iseq.c
+++ b/iseq.c
@@ -256,7 +256,7 @@ rb_iseq_update_references(rb_iseq_t *iseq)
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)
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)
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 *
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)
/* 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 4c253f0e2a..2123458127 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)
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 9dd97e77c7..3f5a619e3c 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,
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,
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,
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,
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,
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 285eb77773..be645ec818 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
{
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 b69eaf168b..7946f9aa4f 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1201,7 +1201,8 @@ vm_throw_start(const rb_execution_context_t *ec, rb_control_frame_t *const reg_c
if (!ct) break;
for (i=0; i < ct->size; i++) {
- const struct iseq_catch_table_entry * const entry = &ct->entries[i];
+ const struct iseq_catch_table_entry *const entry =
+ UNALIGNED_MEMBER_PTR(ct, entries[i]);
if (entry->type == CATCH_TYPE_BREAK &&
entry->iseq == base_iseq &&
@@ -2183,7 +2184,7 @@ vm_method_cfunc_entry(const rb_callable_method_entry_t *me)
rb_bug("wrong method type: %d", me->def->type);
}
#endif
- return &me->def->body.cfunc;
+ return UNALIGNED_MEMBER_PTR(me->def, body.cfunc);
}
static VALUE