This commit is contained in:
Nobuyoshi Nakada 2024-04-06 17:45:58 +09:00
Родитель 5d1702e01a
Коммит 4dd9e5cf74
3 изменённых файлов: 18 добавлений и 7 удалений

Просмотреть файл

@ -281,6 +281,17 @@ RBIMPL_WARNING_IGNORED(-Wgnu-zero-variadic-macro-arguments)
# define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN((cond), (expr), #expr)
#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.
*

Просмотреть файл

@ -11764,7 +11764,7 @@ sym_inspect(VALUE sym)
}
dest[0] = ':';
RUBY_ASSERT(BUILTIN_TYPE(str) == T_STRING);
RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
return str;
}

Просмотреть файл

@ -430,8 +430,8 @@ static void
set_id_entry(rb_symbols_t *symbols, rb_id_serial_t num, VALUE str, VALUE sym)
{
ASSERT_vm_locking();
RUBY_ASSERT(BUILTIN_TYPE(str) == T_STRING);
RUBY_ASSERT(SYMBOL_P(sym));
RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
RUBY_ASSERT_BUILTIN_TYPE(sym, T_SYMBOL);
size_t idx = num / ID_ENTRY_UNIT;
@ -484,10 +484,10 @@ get_id_serial_entry(rb_id_serial_t num, ID id, const enum id_entry_type t)
if (result) {
switch (t) {
case ID_ENTRY_STR:
RUBY_ASSERT(BUILTIN_TYPE(result) == T_STRING);
RUBY_ASSERT_BUILTIN_TYPE(result, T_STRING);
break;
case ID_ENTRY_SYM:
RUBY_ASSERT(SYMBOL_P(result));
RUBY_ASSERT_BUILTIN_TYPE(result, T_SYMBOL);
break;
default:
break;
@ -972,11 +972,11 @@ rb_sym2str(VALUE sym)
VALUE str;
if (DYNAMIC_SYM_P(sym)) {
str = RSYMBOL(sym)->fstr;
RUBY_ASSERT(BUILTIN_TYPE(str) == T_STRING);
RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
}
else {
str = rb_id2str(STATIC_SYM2ID(sym));
RUBY_ASSERT(str == 0 || BUILTIN_TYPE(str) == T_STRING);
if (str) RUBY_ASSERT_BUILTIN_TYPE(str, T_STRING);
}
return str;