Change the return type of `mrb_check_intern()` and friends.

They used to return `mrb_value` but now return `mrb_sym` for consistency
with other `intern` functions. If symbols are not defined, `check`
functions return `0`, instead of `nil` in the past.

It causes API incompatibility but I believe few people use those
functions out of the core, and those changes are very easy to handle,
hopefully.
parent a4302524
......@@ -1097,9 +1097,10 @@ MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t);
MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t);
#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, (lit ""), mrb_strlen_lit(lit))
MRB_API mrb_sym mrb_intern_str(mrb_state*,mrb_value);
MRB_API mrb_value mrb_check_intern_cstr(mrb_state*,const char*);
MRB_API mrb_value mrb_check_intern(mrb_state*,const char*,size_t);
MRB_API mrb_value mrb_check_intern_str(mrb_state*,mrb_value);
/* mrb_check_intern series functions returns 0 if the symbol is not defined */
MRB_API mrb_sym mrb_check_intern_cstr(mrb_state*,const char*);
MRB_API mrb_sym mrb_check_intern(mrb_state*,const char*,size_t);
MRB_API mrb_sym mrb_check_intern_str(mrb_state*,mrb_value);
MRB_API const char *mrb_sym_name(mrb_state*,mrb_sym);
MRB_API const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*);
MRB_API const char *mrb_sym_dump(mrb_state*,mrb_sym);
......
......@@ -151,7 +151,7 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
}
sc = mrb_class_get(mrb, method_p->class_name);
ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
ssym = mrb_check_intern_cstr(mrb, method_p->method_name);
m = mrb_method_search_vm(mrb, &sc, ssym);
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
......
......@@ -356,11 +356,9 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
MRB_API mrb_bool
mrb_class_defined(mrb_state *mrb, const char *name)
{
mrb_value sym = mrb_check_intern_cstr(mrb, name);
if (mrb_nil_p(sym)) {
return FALSE;
}
return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_symbol(sym));
mrb_sym sym = mrb_check_intern_cstr(mrb, name);
if (!sym) return FALSE;
return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), sym);
}
MRB_API mrb_bool
......@@ -372,11 +370,9 @@ mrb_class_defined_id(mrb_state *mrb, mrb_sym name)
MRB_API mrb_bool
mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name)
{
mrb_value sym = mrb_check_intern_cstr(mrb, name);
if (mrb_nil_p(sym)) {
return FALSE;
}
return mrb_const_defined_at(mrb, mrb_obj_value(outer), mrb_symbol(sym));
mrb_sym sym = mrb_check_intern_cstr(mrb, name);
if (!sym) return FALSE;
return mrb_const_defined_at(mrb, mrb_obj_value(outer), sym);
}
MRB_API mrb_bool
......
......@@ -289,24 +289,24 @@ mrb_intern_str(mrb_state *mrb, mrb_value str)
return mrb_intern(mrb, RSTRING_PTR(str), RSTRING_LEN(str));
}
MRB_API mrb_value
MRB_API mrb_sym
mrb_check_intern(mrb_state *mrb, const char *name, size_t len)
{
mrb_sym sym;
sym_validate_len(mrb, len);
sym = find_symbol(mrb, name, len, NULL);
if (sym > 0) return mrb_symbol_value(sym);
return mrb_nil_value();
if (sym > 0) return sym;
return 0;
}
MRB_API mrb_value
MRB_API mrb_sym
mrb_check_intern_cstr(mrb_state *mrb, const char *name)
{
return mrb_check_intern(mrb, name, strlen(name));
}
MRB_API mrb_value
MRB_API mrb_sym
mrb_check_intern_str(mrb_state *mrb, mrb_value str)
{
return mrb_check_intern(mrb, RSTRING_PTR(str), RSTRING_LEN(str));
......
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