summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 11:47:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 11:47:39 +0000
commit673aa230507d2c0d363dee81de83dab322f9c4ad (patch)
tree701a721b77875f20883530e22b042a147c0a2d9f
parent6def265d793d401f59d57349190fdd1974f166e4 (diff)
class.c: rest kwargs
* class.c (rb_get_kwargs): when values is non-null, remove extracted keywords from the rest keyword argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--class.c11
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 81c1754c9d..c7ba7b8580 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Dec 8 20:47:35 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * class.c (rb_get_kwargs): when values is non-null, remove
+ extracted keywords from the rest keyword argument.
+
Sun Dec 8 20:26:54 2013 Yutaka Kanemoto <kanemoto@ruby-lang.org>
* common.mk (ruby.imp): avoid circular dependency on AIX
diff --git a/class.c b/class.c
index 5a4bf05e3b..c7b310965b 100644
--- a/class.c
+++ b/class.c
@@ -1914,6 +1914,12 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
int i = 0, j;
int rest = 0;
VALUE missing = Qnil;
+ st_data_t key;
+
+#define extract_kwarg(keyword, val) \
+ (key = (st_data_t)(keyword), values ? \
+ st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \
+ st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val)))
if (optional < 0) {
rest = 1;
@@ -1929,7 +1935,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
VALUE keyword = ID2SYM(table[i]);
if (keyword_hash) {
st_data_t val;
- if (st_lookup(rb_hash_tbl_raw(keyword_hash), (st_data_t)keyword, &val)) {
+ if (extract_kwarg(keyword, &val)) {
if (values) values[i] = (VALUE)val;
continue;
}
@@ -1945,7 +1951,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
if (optional && keyword_hash) {
for (i = 0; i < optional; i++) {
st_data_t val;
- if (st_lookup(rb_hash_tbl_raw(keyword_hash), ID2SYM(table[required+i]), &val)) {
+ if (extract_kwarg(ID2SYM(table[required+i]), &val)) {
if (values) values[required+i] = (VALUE)val;
j++;
}
@@ -1957,6 +1963,7 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
}
}
return j;
+#undef extract_kwarg
}
/*!