You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Reranko05 (via GitHub)" <gi...@apache.org> on 2026/06/22 11:28:58 UTC

[PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Reranko05 opened a new pull request, #50234:
URL: https://github.com/apache/arrow/pull/50234

   ### Rationale for this change
   
   `rb_memory_view_get()` callers may pass a non-zero-initialized `rb_memory_view_t`. `primitive_array_get()` and `buffer_get()` did not initialize `item_desc.components` and `item_desc.length`, which could cause `rb_memory_view_release()` to attempt to free an invalid pointer and abort the process.
   
   ### What changes are included in this PR?
   
   This change initializes `item_desc.components` and `item_desc.length` in both `primitive_array_get()` and `buffer_get()`.
   
   It also adds regression tests that verify releasing a memory view with a non-zero-initialized `rb_memory_view_t` does not crash for both `Arrow::Int32Array` and `Arrow::Buffer`.
   
   ### Are these changes tested?
   
   Yes. Added regression tests in `test-memory-view.rb` that reproduced the crash before this change and pass after the fix.
   
   ### Are there any user-facing changes?
   
   No.
   
   **This PR contains a "Critical Fix".**
   
   This change fixes a crash that could occur when `rb_memory_view_release()` is called with a memory view whose `item_desc` members were not initialized.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4774539626

   @kou One question about the regression tests: I added the `sub_test_case` structure you suggested, but I noticed your earlier comment about avoiding the hard-coded `256` size and possibly not adding tests for this case at all.
   
   Would you prefer keeping the tests as they are now, or removing them entirely?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #50234:
URL: https://github.com/apache/arrow/pull/50234


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4767790607

   :warning: GitHub issue #45187 **has been automatically assigned in GitHub** to PR creator.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3457423184


##########
ruby/red-arrow/ext/arrow/memory-view.cpp:
##########
@@ -220,6 +221,7 @@ namespace red_arrow {
         return false;
       }
       auto view_ = reinterpret_cast<memory_view *>(view);
+      memset(view_, 0, sizeof(memory_view));

Review Comment:
   Removed rendundant assignments



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +431,56 @@ def little_endian?
                    ])
     end
   end
+
+  sub_test_case("uninitialized rb_memory_view_t") do
+    def setup
+      libruby = Fiddle.dlopen(nil)
+
+      @rb_memory_view_get = Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+
+      @rb_memory_view_release = Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+    end
+
+    def assert_release(target)
+      Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE) do |view|
+        256.times do |i|
+          view[i] = 0xAA
+        end
+
+        assert_equal(
+          true,
+          @rb_memory_view_get.call(Fiddle.dlwrap(target), view, 0)
+        )

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4776256354

   > I prefered not adding tests for this at all in the first review because I feel that we don't want to maintain these tests. But I'm OK with adding them now because they are organized now.
   
   @kou Thanks for the clarification.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3457461097


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +431,55 @@ def little_endian?
                    ])
     end
   end
+
+  sub_test_case("uninitialized rb_memory_view_t") do
+    def setup
+      libruby = Fiddle.dlopen(nil)
+
+      @rb_memory_view_get = Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+
+      @rb_memory_view_release = Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+    end
+
+    def assert_release(target)
+      size = 256 # We should use sizeof(rb_memory_view_t) but it isn't available from Ruby.

Review Comment:
   ```suggestion
         # We should use sizeof(rb_memory_view_t) but it isn't available from Ruby.
         # 256 must be larger than sizeof(rb_memory_view_t).
         size = 256
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4769959570

   @kou The lint failure appears unrelated to this PR. It was caused by a ShellCheck Docker image pull issue. The same `dev lint` workflow passes successfully on my fork.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3457424899


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +431,56 @@ def little_endian?
                    ])
     end
   end
+
+  sub_test_case("uninitialized rb_memory_view_t") do
+    def setup
+      libruby = Fiddle.dlopen(nil)
+
+      @rb_memory_view_get = Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+
+      @rb_memory_view_release = Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+    end
+
+    def assert_release(target)
+      Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE) do |view|
+        256.times do |i|

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4785883223

   @kou Thanks for the review. All CI checks have completed successfully now.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3456326456


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)

Review Comment:
   moved the regression tests into a `sub_test_case` as you suggested.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3456323288


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT

Review Comment:
   Addressed.



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3456323808


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)

Review Comment:
   Addressed.



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)
+    256.times do |i|
+      view[i] = 0xAA
+    end
+
+    assert_equal(
+      1,
+      rb_memory_view_get.call(Fiddle.dlwrap(target), view, 0)
+    )
+    assert_nothing_raised do
+      rb_memory_view_release.call(view)
+    end

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4774515368

   @kou Thanks for the review. Addressed all review comments.
   
   * Switched memory view initialization to `memset(view_, 0, sizeof(memory_view))`.
   * Added regression tests for uninitialized `rb_memory_view_t` handling under a dedicated `sub_test_case`.
   * Updated the Fiddle bindings to use `TYPE_BOOL`.
   * Used `Fiddle::Pointer.malloc(..., Fiddle::RUBY_FREE)` for automatic cleanup.
   * Replaced `assert_nothing_raised` with explicit return value checks.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3456327197


##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +473,14 @@ def little_endian?
                    ])
     end
   end
+
+  test("Int32Array with uninitialized rb_memory_view_t") do
+    array = Arrow::Int32Array.new([1, 2, 3, 4, 5])
+    assert_memory_view_release(array)
+  end
+
+  test("Buffer with uninitialized rb_memory_view_t") do
+    buffer = Arrow::Buffer.new("hello")
+    assert_memory_view_release(buffer)
+  end

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3457463610


##########
ruby/red-arrow/ext/arrow/memory-view.cpp:
##########
@@ -32,6 +32,7 @@
 #endif
 
 #include <sstream>
+#include <cstring>

Review Comment:
   Sort.
   
   ```suggestion
   #include <cstring>
   #include <sstream>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3455442906


##########
ruby/red-arrow/ext/arrow/memory-view.cpp:
##########
@@ -222,6 +222,8 @@ namespace red_arrow {
       auto view_ = reinterpret_cast<memory_view *>(view);
       view_->obj = obj;
       view_->private_data = new PrivateData();
+      view_->item_desc.components = NULL;
+      view_->item_desc.length = 0;

Review Comment:
   Could you move them just before `view_->ndim = ...` to align the order in `red_arrow::memory_view`/`rb_memory_view_t`?
   
   https://github.com/ruby/ruby/blob/e9e7f9b6b9937641b0d7f1c04c483c1cb1e8664a/include/ruby/memory_view.h#L118-L132
   
   Or how about using `memset()`?
   
   ```cpp
   auto view_ = reinterpret_cast<memory_view *>(view);
   memset(view_, 0, sizeof(memory_view));
   view_->obj = obj;
   ...
   ```



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT

Review Comment:
   ```suggestion
           Fiddle::TYPE_BOOL
   ```



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +473,14 @@ def little_endian?
                    ])
     end
   end
+
+  test("Int32Array with uninitialized rb_memory_view_t") do
+    array = Arrow::Int32Array.new([1, 2, 3, 4, 5])
+    assert_memory_view_release(array)
+  end
+
+  test("Buffer with uninitialized rb_memory_view_t") do
+    buffer = Arrow::Buffer.new("hello")
+    assert_memory_view_release(buffer)
+  end

Review Comment:
   Could you add a sub test case and move them to there?
   
   
   ```suggestion
     sub_test_case("uninitialized rb_memory_view_t") do
       def setup
         @rb_memory_view_get = ...
         @rb_memory_view_release = ...
       end
       
       def assert_release(...)
         ...
       end
   
       test("Int32Array") do
         array = Arrow::Int32Array.new([1, 2, 3, 4, 5])
         assert_release(array)
       end
   
       test("Buffer") do
         buffer = Arrow::Buffer.new("hello")
         assert_release(buffer)
       end
     end
   ```



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)
+    256.times do |i|
+      view[i] = 0xAA
+    end
+
+    assert_equal(
+      1,
+      rb_memory_view_get.call(Fiddle.dlwrap(target), view, 0)
+    )
+    assert_nothing_raised do
+      rb_memory_view_release.call(view)
+    end

Review Comment:
   Could you use `assert_equal` instead?



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)

Review Comment:
   We should use `sizeof(rb_memory_view_t)` instead of `256` but we don't have `sizeof(rb_memory_view_t)` and it's too much just for this test...
   
   How about not adding tests for this case entirely?



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT

Review Comment:
   ```suggestion
           Fiddle::TYPE_BOOL
   ```



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -29,6 +29,48 @@ def little_endian?
     [1].pack("s") == [1].pack("s<")
   end
 
+  def rb_memory_view_functions
+    libruby = Fiddle.dlopen(nil)
+
+    [
+      Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_INT
+      ),
+      Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_INT
+      ),
+    ]
+  end
+
+  def assert_memory_view_release(target)
+    rb_memory_view_get, rb_memory_view_release = rb_memory_view_functions
+
+    # Fill the buffer with non-zero garbage to mimic an
+    # uninitialized rb_memory_view_t.
+    view = Fiddle::Pointer.malloc(256)

Review Comment:
   Could you free allocated memory automatically?
   
   ```suggestion
       Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE) do |view|
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3457325249


##########
ruby/red-arrow/ext/arrow/memory-view.cpp:
##########
@@ -220,6 +221,7 @@ namespace red_arrow {
         return false;
       }
       auto view_ = reinterpret_cast<memory_view *>(view);
+      memset(view_, 0, sizeof(memory_view));

Review Comment:
   Could you remove redundant `view_->shape = NULL`, `view_->strides = NULL` and so on?



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +431,56 @@ def little_endian?
                    ])
     end
   end
+
+  sub_test_case("uninitialized rb_memory_view_t") do
+    def setup
+      libruby = Fiddle.dlopen(nil)
+
+      @rb_memory_view_get = Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+
+      @rb_memory_view_release = Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+    end
+
+    def assert_release(target)
+      Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE) do |view|
+        256.times do |i|
+          view[i] = 0xAA
+        end
+
+        assert_equal(
+          true,
+          @rb_memory_view_get.call(Fiddle.dlwrap(target), view, 0)
+        )

Review Comment:
   Could you use `assert do ... end` for method call that returns boolean?
   
   ```suggestion
           assert do
             @rb_memory_view_get.call(Fiddle.dlwrap(target), view, 0)
           end
   ```



##########
ruby/red-arrow/test/test-memory-view.rb:
##########
@@ -431,4 +431,56 @@ def little_endian?
                    ])
     end
   end
+
+  sub_test_case("uninitialized rb_memory_view_t") do
+    def setup
+      libruby = Fiddle.dlopen(nil)
+
+      @rb_memory_view_get = Fiddle::Function.new(
+        libruby["rb_memory_view_get"],
+        [
+          Fiddle::TYPE_UINTPTR_T,
+          Fiddle::TYPE_VOIDP,
+          Fiddle::TYPE_INT,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+
+      @rb_memory_view_release = Fiddle::Function.new(
+        libruby["rb_memory_view_release"],
+        [
+          Fiddle::TYPE_VOIDP,
+        ],
+        Fiddle::TYPE_BOOL
+      )
+    end
+
+    def assert_release(target)
+      Fiddle::Pointer.malloc(256, Fiddle::RUBY_FREE) do |view|
+        256.times do |i|

Review Comment:
   Could you add a comment why we use `256` here?
   
   ```ruby
   size = 256 # We should use sizeof(rb_memory_view_t) but ...
   Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) do |view|
     size.times do |i|
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50234:
URL: https://github.com/apache/arrow/pull/50234#discussion_r3456322526


##########
ruby/red-arrow/ext/arrow/memory-view.cpp:
##########
@@ -222,6 +222,8 @@ namespace red_arrow {
       auto view_ = reinterpret_cast<memory_view *>(view);
       view_->obj = obj;
       view_->private_data = new PrivateData();
+      view_->item_desc.components = NULL;
+      view_->item_desc.length = 0;

Review Comment:
   Addressed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45187: [Ruby] Ensure initializing all rb_memory_view_t members [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #50234:
URL: https://github.com/apache/arrow/pull/50234#issuecomment-4789005889

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 12b3eda46a69fbc2e7f6f9c52be345b678f4baae.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/83187503426) has more details. It also includes information about 8 possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org