summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-12-16 08:15:13 -0800
committerJeremy Evans <code@jeremyevans.net>2020-12-18 09:54:11 -0800
commit52fb696ee7d01b1d55a1d5c42c60c6a5ebfc4502 (patch)
tree86045676ae96f24768fdc841ca613ee314731c82 /error.c
parent7b06085c7bf8cc0db157e46fb11d16a6447d4d63 (diff)
Switch rb_category_warn{,ing} to accept an rb_warning_category_t
Since we decided to only allowing specific warning categories, there is no reason to have an API that accepts a general string, as it is more error-prone. Switch to only allowing the specific warning categories. As rb_category_warn{,ing} are public API, this requires making rb_warning_category_t public API as well.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3917
Diffstat (limited to 'error.c')
-rw-r--r--error.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/error.c b/error.c
index e10485dc4e..2b637421f7 100644
--- a/error.c
+++ b/error.c
@@ -77,6 +77,7 @@ static ID id_deprecated;
static ID id_experimental;
static VALUE sym_category;
static VALUE warning_categories;
+static VALUE warning_category_t_map;
extern const char ruby_description[];
@@ -403,11 +404,11 @@ rb_warn(const char *fmt, ...)
}
void
-rb_category_warn(const char *category, const char *fmt, ...)
+rb_category_warn(rb_warning_category_t category, const char *fmt, ...)
{
if (!NIL_P(ruby_verbose)) {
with_warning_string(mesg, 0, fmt) {
- rb_warn_category(mesg, ID2SYM(rb_intern(category)));
+ rb_warn_category(mesg, rb_hash_fetch(warning_category_t_map, INT2NUM(category)));
}
}
}
@@ -435,11 +436,11 @@ rb_warning(const char *fmt, ...)
/* rb_category_warning() reports only in verbose mode */
void
-rb_category_warning(const char *category, const char *fmt, ...)
+rb_category_warning(rb_warning_category_t category, const char *fmt, ...)
{
if (RTEST(ruby_verbose)) {
with_warning_string(mesg, 0, fmt) {
- rb_warn_category(mesg, ID2SYM(rb_intern(category)));
+ rb_warn_category(mesg, rb_hash_fetch(warning_category_t_map, INT2NUM(category)));
}
}
}
@@ -2839,6 +2840,13 @@ Init_Exception(void)
rb_gc_register_mark_object(warning_categories);
rb_hash_aset(warning_categories, ID2SYM(rb_intern_const("deprecated")), Qtrue);
rb_obj_freeze(warning_categories);
+
+ warning_category_t_map = rb_hash_new();
+ rb_gc_register_mark_object(warning_category_t_map);
+ rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_NONE), Qnil);
+ rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_DEPRECATED), ID2SYM(rb_intern_const("deprecated")));
+ rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_EXPERIMENTAL), ID2SYM(rb_intern_const("experimental")));
+ rb_obj_freeze(warning_category_t_map);
}
void