Skip to content

Commit 29acd98

Browse files
authored
Make Fiddle::Pointer#to_s with JRuby consistent with CRuby (#176)
Hi, this PR makes the behavior of `Fiddle::Pointer#to_s` consistent between CRuby and JRuby. ```ruby ptr = Fiddle::Pointer.malloc(4) p ptr.to_s(4) ``` currently outputs `"\x00\x00\x00\x00"` with CRuby and `""` with JRuby.
1 parent ef2382a commit 29acd98

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/fiddle/ffi_backend.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,9 @@ def to_i
408408
end
409409
alias to_int to_i
410410

411-
# without \0
412411
def to_s(len = nil)
413412
if len
414-
ffi_ptr.get_string(0, len)
413+
ffi_ptr.read_string(len)
415414
else
416415
ffi_ptr.get_string(0)
417416
end

test/fiddle/test_pointer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def test_to_s
9292

9393
ptr[5] = 0
9494
assert_equal 'hello', ptr.to_s
95+
assert_equal "hello\0", ptr.to_s(6)
9596
end
9697

9798
def test_minus

0 commit comments

Comments
 (0)