ruby-changes:31623
From: nobu <ko1@a...>
Date: Mon, 18 Nov 2013 11:30:07 +0900 (JST)
Subject: [ruby-changes:31623] nobu:r43702 (trunk): vm_core.h: extract VM_STACK_OVERFLOWED_P
nobu 2013-11-18 11:29:58 +0900 (Mon, 18 Nov 2013) New Revision: 43702 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43702 Log: vm_core.h: extract VM_STACK_OVERFLOWED_P * vm_core.h (VM_STACK_OVERFLOWED_P, WHEN_VM_STACK_OVERFLOWED): extract condition from CHECK_VM_STACK_OVERFLOW. * vm_exec.c (vm_stack_overflow_for_insn): move rb_bug call. * vm_exec.h (CHECK_VM_STACK_OVERFLOW_FOR_INSN): share the condition with CHECK_VM_STACK_OVERFLOW. Modified files: trunk/vm_core.h trunk/vm_exec.c trunk/vm_exec.h Index: vm_core.h =================================================================== --- vm_core.h (revision 43701) +++ vm_core.h (revision 43702) @@ -889,13 +889,17 @@ int rb_autoloading_value(VALUE mod, ID i https://github.com/ruby/ruby/blob/trunk/vm_core.h#L889 #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack] -#define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) do { \ - if ((VALUE *)((char *)((VALUE *)(sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \ - vm_stackoverflow(); \ - } \ -} while (0) - -#define CHECK_VM_STACK_OVERFLOW(cfp, margin) CHECK_VM_STACK_OVERFLOW0((cfp), (cfp)->sp, margin) +#define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */ +#define VM_STACK_OVERFLOWED_P(cfp, sp, margin) \ + (!RUBY_CONST_ASSERT(sizeof(*(sp)) == sizeof(VALUE)) || \ + !RUBY_CONST_ASSERT(sizeof(*(cfp)) == sizeof(rb_control_frame_t)) || \ + ((rb_control_frame_t *)((sp) + (margin)) + 1) >= (cfp)) +#define WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) \ + if (LIKELY(!VM_STACK_OVERFLOWED_P(cfp, sp, margin))) {(void)0;} else /* overflowed */ +#define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) \ + WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) vm_stackoverflow() +#define CHECK_VM_STACK_OVERFLOW(cfp, margin) \ + WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow() /* for thread */ Index: vm_exec.c =================================================================== --- vm_exec.c (revision 43701) +++ vm_exec.c (revision 43702) @@ -29,6 +29,15 @@ static void vm_analysis_insn(int insn); https://github.com/ruby/ruby/blob/trunk/vm_exec.c#L29 #endif /* #define DECL_SC_REG(r, reg) VALUE reg_##r */ +NORETURN(static void vm_stack_overflow_for_insn(void)); +static void +vm_stack_overflow_for_insn(void) +{ + rb_bug("CHECK_VM_STACK_OVERFLOW_FOR_INSN: should not overflow here. " + "Please contact ruby-core/dev with your (a part of) script. " + "This check will be removed soon."); +} + #if !OPT_CALL_THREADED_CODE static VALUE vm_exec_core(rb_thread_t *th, VALUE initial) Index: vm_exec.h =================================================================== --- vm_exec.h (revision 43701) +++ vm_exec.h (revision 43702) @@ -169,12 +169,7 @@ default: \ https://github.com/ruby/ruby/blob/trunk/vm_exec.h#L169 #endif #define SCREG(r) (reg_##r) -#define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin) do { \ - if (((rb_control_frame_t *)(((cfp)->sp) + (margin)) + 1) >= (cfp)) { \ - rb_bug("CHECK_VM_STACK_OVERFLOW_FOR_INSN: should not overflow here. " \ - "Please contact ruby-core/dev with your (a part of) script. " \ - "This check will be removed soon."); \ - } \ -} while (0) +#define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin) \ + WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stack_overflow_for_insn() #endif /* RUBY_VM_EXEC_H */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/