diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-19 01:04:15 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-19 01:04:15 +0000 |
commit | 081fdb84cafee20ed306b0c5640738416a6c0c20 (patch) | |
tree | c87c2778e539c528bf4a603a797fc4ae5ca92510 | |
parent | 473d87099b3b9f10cabe60e9e4d82e3500c07624 (diff) | |
download | ruby-081fdb84cafee20ed306b0c5640738416a6c0c20.tar.gz |
class.c: check kw hash
* class.c (rb_keyword_error_new): get rid of an intermediate
string and check if keys are symbols.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | class.c | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -1776,19 +1776,21 @@ rb_define_attr(VALUE klass, const char *name, int read, int write) VALUE rb_keyword_error_new(const char *error, VALUE keys) { - const char *msg = ""; - VALUE error_message; - - if (RARRAY_LEN(keys) == 1) { - keys = RARRAY_AREF(keys, 0); - } - else { - keys = rb_ary_join(keys, rb_usascii_str_new2(", ")); - msg = "s"; + const VALUE *ptr = RARRAY_CONST_PTR(keys); + long i = 0, len = RARRAY_LEN(keys); + VALUE error_message = rb_sprintf("%s keyword%.*s", error, len > 1, "s"); + + if (len > 0) { + rb_str_cat_cstr(error_message, ": "); + while (1) { + const VALUE k = ptr[i]; + Check_Type(k, T_SYMBOL); /* wrong hash is given to rb_get_kwargs */ + rb_str_append(error_message, rb_sym2str(k)); + if (++i >= len) break; + rb_str_cat_cstr(error_message, ", "); + } } - error_message = rb_sprintf("%s keyword%s: %"PRIsVALUE, error, msg, keys); - return rb_exc_new_str(rb_eArgError, error_message); } |