Commit 82a1b00e authored by dearblue's avatar dearblue

Assert that `MRB_METHOD_CACHE_SIZE` is a power of 2

The `mrb_static_assert_powerof2()` macro has been introduced for this purpose.
parent 28ccc664
...@@ -109,6 +109,8 @@ ...@@ -109,6 +109,8 @@
mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1, _)(__VA_ARGS__)) mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1, _)(__VA_ARGS__))
#endif #endif
#define mrb_static_assert_powerof2(num) mrb_static_assert((num) > 0 && (num) == ((num) & -(num)), "need power of 2 for " #num)
#include "mrbconf.h" #include "mrbconf.h"
#include <mruby/common.h> #include <mruby/common.h>
...@@ -208,6 +210,7 @@ struct mrb_context { ...@@ -208,6 +210,7 @@ struct mrb_context {
#ifdef MRB_METHOD_CACHE_SIZE #ifdef MRB_METHOD_CACHE_SIZE
# undef MRB_NO_METHOD_CACHE # undef MRB_NO_METHOD_CACHE
mrb_static_assert_powerof2(MRB_METHOD_CACHE_SIZE);
#else #else
/* default method cache size: 256 */ /* default method cache size: 256 */
/* cache size needs to be power of 2 */ /* cache size needs to be power of 2 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment