summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-19 08:17:56 (GMT)
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-19 08:17:56 (GMT)
commit26b08ed144e8f051158d746ef5098408433cd022 (patch)
tree275f02c6a29c8007790b0ab2416933895aca5073 /array.c
parent66bd6ffcbcc2147b2696087266f4f6db8b38cce9 (diff)
don't abuse RSTRING_PTR (2nd try)
r61827, r61947 was about to fix this. The proper way to allocate memory region is called ALLOCV_N. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/array.c b/array.c
index 5bc69f6..5cb86f2 100644
--- a/array.c
+++ b/array.c
@@ -5064,8 +5064,6 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
return Qnil;
}
-#define tmpbuf(n, size) rb_str_tmp_new((n)*(size))
-#define tmpbuf_discard(s) (rb_str_resize((s), 0L), RBASIC_SET_CLASS_RAW(s, rb_cString))
#define tmpary(n) rb_ary_tmp_new(n)
#define tmpary_discard(a) (ary_discard(a), RBASIC_SET_CLASS_RAW(a, rb_cArray))
@@ -5568,15 +5566,14 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
{
int n = argc+1; /* How many arrays we're operating on */
volatile VALUE t0 = tmpary(n);
- volatile VALUE t1 = tmpbuf(n, sizeof(int));
+ volatile VALUE t1 = Qundef;
VALUE *arrays = RARRAY_PTR(t0); /* The arrays we're computing the product of */
- int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
+ int *counters = ALLOCV_N(int, t1, n); /* The current position in each one */
VALUE result = Qnil; /* The array we'll be returning, when no block given */
long i,j;
long resultlen = 1;
RBASIC_CLEAR_CLASS(t0);
- RBASIC_CLEAR_CLASS(t1);
/* initialize the arrays of arrays */
ARY_SET_LEN(t0, n);
@@ -5647,7 +5644,7 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
}
done:
tmpary_discard(t0);
- tmpbuf_discard(t1);
+ ALLOCV_END(t1);
return NIL_P(result) ? ary : result;
}