summaryrefslogtreecommitdiff
path: root/include/ruby/assert.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/assert.h')
-rw-r--r--include/ruby/assert.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/include/ruby/assert.h b/include/ruby/assert.h
index ceab090427..acc5e5bbfc 100644
--- a/include/ruby/assert.h
+++ b/include/ruby/assert.h
@@ -282,22 +282,35 @@ RBIMPL_WARNING_IGNORED(-Wgnu-zero-variadic-macro-arguments)
#endif
/**
+ * A variant of #RUBY_ASSERT that asserts when either #RUBY_DEBUG or built-in
+ * type of `obj` is `type`.
+ *
+ * @param obj Object to check its built-in typue.
+ * @param type Built-in type constant, T_ARRAY, T_STRING, etc.
+ */
+#define RUBY_ASSERT_BUILTIN_TYPE(obj, type) \
+ RUBY_ASSERT(RB_TYPE_P(obj, type), \
+ "Actual type is %s", rb_builtin_type_name(BUILTIN_TYPE(obj)))
+
+/**
* This is either #RUBY_ASSERT or #RBIMPL_ASSUME, depending on #RUBY_DEBUG.
*
* @copydetails #RUBY_ASSERT
*/
#if RUBY_DEBUG
-# define RBIMPL_ASSERT_OR_ASSUME(expr) RUBY_ASSERT_ALWAYS(expr)
+# define RBIMPL_ASSERT_OR_ASSUME RUBY_ASSERT_ALWAYS
+#elif ! defined(RBIMPL_VA_OPT_ARGS)
+# define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSUME(expr)
#elif RBIMPL_COMPILER_BEFORE(Clang, 7, 0, 0)
# /* See commit 67d259c5dccd31fe49d417fec169977712ffdf10 */
-# define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSERT_NOTHING
+# define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
#elif defined(RUBY_ASSERT_NOASSUME)
# /* See commit d300a734414ef6de7e8eb563b7cc4389c455ed08 */
-# define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSERT_NOTHING
+# define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
#elif ! defined(RBIMPL_HAVE___ASSUME)
-# define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSERT_NOTHING
+# define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
#else
-# define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSUME(expr)
+# define RBIMPL_ASSERT_OR_ASSUME(expr, ...) RBIMPL_ASSUME(expr)
#endif
#endif /* RUBY_ASSERT_H */