summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-04 07:50:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-04 07:50:34 +0000
commit0047ab96cd4de28c4e2d0f41d6e11ec494d86186 (patch)
treee370d9a401a31bff7d7506c381de6804179fa765
parent8df1863dcbd9e19b5e7f60c2e06e088105c975f5 (diff)
tkutil.c: rb_ary_cat
* ext/tk/tkutil/tkutil.c (rb_ary_cat): fallback definition. rb_ary_cat() is available since 2.0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/tk/tkutil/extconf.rb1
-rw-r--r--ext/tk/tkutil/tkutil.c28
2 files changed, 21 insertions, 8 deletions
diff --git a/ext/tk/tkutil/extconf.rb b/ext/tk/tkutil/extconf.rb
index 20b6f37..a4b5e03 100644
--- a/ext/tk/tkutil/extconf.rb
+++ b/ext/tk/tkutil/extconf.rb
@@ -6,6 +6,7 @@ begin
have_func("rb_obj_taint", "ruby.h")
have_func("rb_sym2str", "ruby.h")
have_func("rb_id2str", "ruby.h")
+ have_func("rb_ary_cat", "ruby.h")
have_func("strndup", "string.h")
create_makefile('tkutil')
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c
index 5d6613c..f18fadf 100644
--- a/ext/tk/tkutil/tkutil.c
+++ b/ext/tk/tkutil/tkutil.c
@@ -106,6 +106,22 @@ strndup(ptr, len)
}
#endif
+#ifndef HAVE_RB_ARY_CAT
+static VALUE rb_ary_cat _((VALUE, const VALUE *, long));
+static VALUE
+rb_ary_cat(ary, argv, len)
+ VALUE ary;
+ const VALUE *argv;
+ long len;
+{
+ long i;
+ for (i = 0; i < len; i++) {
+ rb_ary_push(ary, argv[i]);
+ }
+ return ary;
+}
+#endif
+
/*************************************/
#if defined(HAVE_RB_OBJ_INSTANCE_EXEC) && !defined(RUBY_VM)
@@ -584,7 +600,7 @@ assoc2kv(assoc, ary, self)
VALUE ary;
VALUE self;
{
- long i, j, len;
+ long i, len;
volatile VALUE pair;
volatile VALUE val;
volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
@@ -611,9 +627,7 @@ assoc2kv(assoc, ary, self)
rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0]));
val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]);
- }
+ rb_ary_cat(val, RARRAY_CONST_PTR(pair) + 1, RARRAY_LEN(pair) - 1);
rb_ary_push(dst, val);
}
@@ -632,7 +646,7 @@ assoc2kv_enc(assoc, ary, self)
VALUE ary;
VALUE self;
{
- long i, j, len;
+ long i, len;
volatile VALUE pair;
volatile VALUE val;
volatile VALUE dst = rb_ary_new2(2 * RARRAY_LEN(assoc));
@@ -659,9 +673,7 @@ assoc2kv_enc(assoc, ary, self)
rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0]));
val = rb_ary_new2(RARRAY_LEN(pair) - 1);
- for(j = 1; j < RARRAY_LEN(pair); j++) {
- rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]);
- }
+ rb_ary_cat(val, RARRAY_CONST_PTR(pair) + 1, RARRAY_LEN(pair) - 1);
rb_ary_push(dst, get_eval_string_core(val, Qtrue, self));
}