[前][次][番号順一覧][スレッド一覧]

ruby-changes:64487

From: Kenta <ko1@a...>
Date: Wed, 23 Dec 2020 09:25:32 +0900 (JST)
Subject: [ruby-changes:64487] 01ab29cc28 (master): [memory_view] Make some rb_memroy_view_t members const

https://git.ruby-lang.org/ruby.git/commit/?id=01ab29cc28

From 01ab29cc285ec92c07cd67db6f8616690bd217f8 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Wed, 23 Dec 2020 00:43:26 +0900
Subject: [memory_view] Make some rb_memroy_view_t members const


diff --git a/ext/-test-/memory_view/memory_view.c b/ext/-test-/memory_view/memory_view.c
index 79a64cf..3156dd3 100644
--- a/ext/-test-/memory_view/memory_view.c
+++ b/ext/-test-/memory_view/memory_view.c
@@ -314,8 +314,8 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L314
 static bool
 mdview_release_memory_view(VALUE obj, rb_memory_view_t *view)
 {
-    if (view->shape) xfree(view->shape);
-    if (view->strides) xfree(view->strides);
+    if (view->shape) xfree((void *)view->shape);
+    if (view->strides) xfree((void *)view->strides);
 
     return true;
 }
diff --git a/include/ruby/memory_view.h b/include/ruby/memory_view.h
index 6ff5cbf..b5e8265 100644
--- a/include/ruby/memory_view.h
+++ b/include/ruby/memory_view.h
@@ -80,7 +80,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L80
          * item structure.  rb_memory_view_prepare_item_desc and
          * rb_memory_view_get_item allocate this memory if needed,
          * and rb_memory_view_release frees it. */
-        rb_memory_view_item_component_t *components;
+        const rb_memory_view_item_component_t *components;
 
         /* The number of components in an item. */
         size_t length;
@@ -91,15 +91,15 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L91
 
     /* ndim size array indicating the number of elements in each dimension.
      * This can be NULL when ndim == 1. */
-    ssize_t *shape;
+    const ssize_t *shape;
 
     /* ndim size array indicating the number of bytes to skip to go to the
      * next element in each dimension. */
-    ssize_t *strides;
+    const ssize_t *strides;
 
     /* The offset in each dimension when this memory view exposes a nested array.
      * Or, NULL when this memory view exposes a flat array. */
-    ssize_t *sub_offsets;
+    const ssize_t *sub_offsets;
 
     /* the private data for managing this exported memory */
     void *const private;
diff --git a/memory_view.c b/memory_view.c
index 743a736..2d4f9dc 100644
--- a/memory_view.c
+++ b/memory_view.c
@@ -748,7 +748,9 @@ rb_memory_view_prepare_item_desc(rb_memory_view_t *view) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L748
 {
     if (view->item_desc.components == NULL) {
         const char *err;
-        ssize_t n = rb_memory_view_parse_item_format(view->format, &view->item_desc.components, &view->item_desc.length, &err);
+        rb_memory_view_item_component_t **p_components =
+            (rb_memory_view_item_component_t **)&view->item_desc.components;
+        ssize_t n = rb_memory_view_parse_item_format(view->format, p_components, &view->item_desc.length, &err);
         if (n < 0) {
             rb_raise(rb_eRuntimeError,
                      "Unable to parse item format at %"PRIdSIZE" in \"%s\"",
@@ -841,7 +843,7 @@ rb_memory_view_release(rb_memory_view_t* view) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L843
             unregister_exported_object(view->obj);
             view->obj = Qnil;
             if (view->item_desc.components) {
-                xfree(view->item_desc.components);
+                xfree((void *)view->item_desc.components);
             }
         }
         return rv;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]