summaryrefslogtreecommitdiff
path: root/include/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-04-06 17:45:58 +0900
committerNobuyoshi Nakada <[email protected]>2024-04-08 11:13:29 +0900
commit4dd9e5cf7447ec70a55206fd5e1b9e8c79dbba7e (patch)
tree008d9f18d1f674f4acd1f859e84d252856eafb82 /include/ruby
parent5d1702e01a36e11b183fe29ce10780a9b1a41cf0 (diff)
Add builtin type assertion
Diffstat (limited to 'include/ruby')
-rw-r--r--include/ruby/assert.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/ruby/assert.h b/include/ruby/assert.h
index ceab090427..e9edd9e640 100644
--- a/include/ruby/assert.h
+++ b/include/ruby/assert.h
@@ -282,6 +282,17 @@ 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