mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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`.
This commit is contained in:
		
							parent
							
								
									ea42423908
								
							
						
					
					
						commit
						b1aecef873
					
				
					 8 changed files with 38 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -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));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								internal.h
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								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 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								iseq.c
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								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)));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								vm.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue