1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

RUBY_CONST_ASSERT: use STATIC_ASSERT instead

Static assertions shall be done using STATIC_ASSERT these days.
This commit is contained in:
卜部昌平 2020-07-06 15:39:26 +09:00
parent 4b8170ce80
commit 215c6fa3d0
Notes: git 2020-07-10 12:24:06 +09:00
3 changed files with 11 additions and 23 deletions

View file

@ -1688,17 +1688,17 @@ MJIT_STATIC const rb_callable_method_entry_t *rb_vm_frame_method_entry(const rb_
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
#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_OVERFLOW0(cfp, sp, margin) do { \
STATIC_ASSERT(sizeof_sp, sizeof(*(sp)) == sizeof(VALUE)); \
STATIC_ASSERT(sizeof_cfp, sizeof(*(cfp)) == sizeof(rb_control_frame_t)); \
const struct rb_control_frame_struct *bound = (void *)&(sp)[(margin)]; \
if (UNLIKELY((cfp) <= &bound[1])) { \
vm_stackoverflow(); \
} \
} while (0)
#define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow()
CHECK_VM_STACK_OVERFLOW0((cfp), (cfp)->sp, (margin))
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr);

View file

@ -62,17 +62,6 @@ static void vm_insns_counter_count_insn(int insn) {}
#endif
/* #define DECL_SC_REG(r, reg) VALUE reg_##r */
#if VM_DEBUG_STACKOVERFLOW
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.");
}
#endif
#if !OPT_CALL_THREADED_CODE
static VALUE
vm_exec_core(rb_execution_context_t *ec, VALUE initial)

View file

@ -185,8 +185,7 @@ default: \
#define VM_DEBUG_STACKOVERFLOW 0
#if VM_DEBUG_STACKOVERFLOW
#define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin) \
WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stack_overflow_for_insn()
#define CHECK_VM_STACK_OVERFLOW_FOR_INSN CHECK_VM_STACK_OVERFLOW
#else
#define CHECK_VM_STACK_OVERFLOW_FOR_INSN(cfp, margin)
#endif