mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 13:34:17 +02:00
[ruby/fiddle] Implement Fiddle::Pointer.read
and .write
on the
FFI backend
(https://github.com/ruby/fiddle/pull/165)
0bd963d3b8
This commit is contained in:
parent
0c7fe4b092
commit
473fb6385e
2 changed files with 8 additions and 4 deletions
|
@ -261,6 +261,14 @@ module Fiddle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.write(addr, bytes)
|
||||||
|
FFI::Pointer.new(addr).write_bytes(bytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.read(addr, len)
|
||||||
|
FFI::Pointer.new(addr).read_bytes(len)
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
alias [] to_ptr
|
alias [] to_ptr
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,10 +11,6 @@ module Fiddle
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_can_read_write_memory
|
def test_can_read_write_memory
|
||||||
if ffi_backend?
|
|
||||||
omit("Fiddle::Pointer.{read,write} don't exist in FFI backend")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Allocate some memory
|
# Allocate some memory
|
||||||
Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE) do |pointer|
|
Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE) do |pointer|
|
||||||
address = pointer.to_i
|
address = pointer.to_i
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue