[前][次][番号順一覧][スレッド一覧]

ruby-changes:62171

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 10 Jul 2020 12:24:01 +0900 (JST)
Subject: [ruby-changes:62171] 215c6fa3d0 (master): RUBY_CONST_ASSERT: use STATIC_ASSERT instead

https://git.ruby-lang.org/ruby.git/commit/?id=215c6fa3d0

From 215c6fa3d012221d89420cbdf1416f65d7179a24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 6 Jul 2020 15:39:26 +0900
Subject: RUBY_CONST_ASSERT: use STATIC_ASSERT instead

Static assertions shall be done using STATIC_ASSERT these days.

diff --git a/vm_core.h b/vm_core.h
index fd49c24..81455e1 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_ https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1688
 
 #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);
 
diff --git a/vm_exec.c b/vm_exec.c
index 2c7e222..ce2e053 100644
--- a/vm_exec.c
+++ b/vm_exec.c
@@ -62,17 +62,6 @@ static void vm_insns_counter_count_insn(int insn) {} https://github.com/ruby/ruby/blob/trunk/vm_exec.c#L62
 #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)
diff --git a/vm_exec.h b/vm_exec.h
index 1be3f64..1f2a052 100644
--- a/vm_exec.h
+++ b/vm_exec.h
@@ -185,8 +185,7 @@ default:                        \ https://github.com/ruby/ruby/blob/trunk/vm_exec.h#L185
 #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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]