aboutsummaryrefslogtreecommitdiffstats
path: root/vm_core.h
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-07-06 15:39:26 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-07-10 12:23:41 +0900
commit215c6fa3d012221d89420cbdf1416f65d7179a24 (patch)
treef7352818e6ab18fc0bab9725014cd9a09567eea8 /vm_core.h
parent4b8170ce8027863b2085c105f4c4aaad0489328b (diff)
downloadruby-215c6fa3d012221d89420cbdf1416f65d7179a24.tar.gz
RUBY_CONST_ASSERT: use STATIC_ASSERT instead
Static assertions shall be done using STATIC_ASSERT these days.
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/vm_core.h b/vm_core.h
index fd49c243e3..81455e18bc 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -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);