summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authorKenta Murata <mrkn@users.noreply.github.com>2020-12-11 09:41:12 +0900
committerGitHub <noreply@github.com>2020-12-11 09:41:12 +0900
commit9b0c36b39032cffff3c62a2b0e1fc38fa429f5ea (patch)
tree667648b7563a97e5d5270baccd5654d5de91358c /ext/-test-
parent6b1d2de6cc2e85fda7885fe77dbd7c99c4eb1ef2 (diff)
Import fiddle-1.0.4 (#3860)
I don't use tool/sync_default_gem.rb because the last sync was incomplete. Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org> Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Co-authored-by: sinisterchipmunk <sinisterchipmunk@gmail.com> Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Notes
Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/memory_view/memory_view.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/-test-/memory_view/memory_view.c b/ext/-test-/memory_view/memory_view.c
index 53656b145c6..61d02464b83 100644
--- a/ext/-test-/memory_view/memory_view.c
+++ b/ext/-test-/memory_view/memory_view.c
@@ -275,15 +275,15 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags)
return 0;
}
- ssize_t i, ndim = RARRAY_LEN(shape_v);
+ ssize_t ndim = RARRAY_LEN(shape_v);
+ if (!NIL_P(strides_v) && RARRAY_LEN(strides_v) != ndim) {
+ rb_raise(rb_eArgError, "strides has an invalid dimension");
+ }
+
ssize_t *shape = ALLOC_N(ssize_t, ndim);
- ssize_t *strides = NULL;
+ ssize_t *strides = ALLOC_N(ssize_t, ndim);
+ ssize_t i;
if (!NIL_P(strides_v)) {
- if (RARRAY_LEN(strides_v) != ndim) {
- rb_raise(rb_eArgError, "strides has an invalid dimension");
- }
-
- strides = ALLOC_N(ssize_t, ndim);
for (i = 0; i < ndim; ++i) {
shape[i] = NUM2SSIZET(RARRAY_AREF(shape_v, i));
strides[i] = NUM2SSIZET(RARRAY_AREF(strides_v, i));
@@ -293,6 +293,12 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags)
for (i = 0; i < ndim; ++i) {
shape[i] = NUM2SSIZET(RARRAY_AREF(shape_v, i));
}
+
+ i = ndim - 1;
+ strides[i] = item_size;
+ for (; i > 0; --i) {
+ strides[i-1] = strides[i] * shape[i];
+ }
}
rb_memory_view_init_as_byte_array(view, obj, RSTRING_PTR(buf_v), RSTRING_LEN(buf_v), true);