Class: FFI::MemoryPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/systemd/ffi_size_t.rb

Class Method Summary collapse

Class Method Details

.monkey_patch_type_i_need!(which) ⇒ Object

monkey patch a read_size_t and write_size_t method onto FFI::MemoryPointer. see github.com/ffi/ffi/issues/118



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/systemd/ffi_size_t.rb', line 7

def self.monkey_patch_type_i_need!(which)
  return if self.respond_to?("read_#{which}")

  type = FFI.find_type(which)
  type, _ = FFI::TypeDefs.find do |(name, t)|
    method_defined?("read_#{name}") if t == type
  end

  raise "Unable to patch in reader/writer for #{which}" if type.nil?

  alias_method "read_#{which}", "read_#{type}"
  alias_method "write_#{which}", "write_#{type}"
end