summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-09-03 08:00:10 -0700
committerJeremy Evans <code@jeremyevans.net>2020-09-28 08:38:06 -0700
commit346301e2329c46362a6089311d0a64b8734b35ec (patch)
tree4b74d3d91bc7cf52cc4e1f50f8d62c3918aff26c /include
parent92c3ad9c276d048bf6fba1145ffccf8678fe8af1 (diff)
Add rb_category_warn{,ing} for warning messages with categories
This adds the following C-API functions that can be used to emit warnings with categories included: ```c void rb_category_warn(const char *, const char*, ...) void rb_category_warning(const char*, const char*, ...) ``` Internally in error.c, there is an rb_warn_category function that will call Warning.warn with the string and the category keyword if it doesn't have an arity of 1, and will call Warning.warn with just the string if it has an arity of 1. This refactors the rb_warn_deprecated{,_to_remove} functions to use rb_warn_category. This makes Kernel#warn accept a category keyword and pass it to Warning.warn, so that Ruby methods can more easily emit warnings with categories. rb_warn_category makes sure that the passed category is a already defined category symbol before calling Warning.warn. The only currently defined warning category is :deprecated, since that is what is already used. More categories can be added in later commits.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3508
Diffstat (limited to 'include')
-rw-r--r--include/ruby/internal/error.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/ruby/internal/error.h b/include/ruby/internal/error.h
index 98f016d995..dc842cc6f6 100644
--- a/include/ruby/internal/error.h
+++ b/include/ruby/internal/error.h
@@ -63,10 +63,12 @@ VALUE *rb_ruby_debug_ptr(void);
/* reports if `-W' specified */
PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
+PRINTF_ARGS(void rb_category_warning(const char*, const char*, ...), 2, 3);
PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4);
PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
/* reports always */
COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
+COLDFUNC PRINTF_ARGS(void rb_category_warn(const char *, const char*, ...), 2, 3);
PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
RBIMPL_SYMBOL_EXPORT_END()