Module: GirFFI::InPointer

Defined in:
lib/gir_ffi/in_pointer.rb

Overview

The InPointer module handles conversion from ruby types to pointers for arguments with direction :in. This is used for arguments that are arrays, strings, or interfaces.

Class Method Summary collapse

Class Method Details

.from(type, val) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gir_ffi/in_pointer.rb', line 26

def self.from(type, val)
  return unless val

  case type
  when :utf8, :filename
    from_utf8 val
  when :gfloat, :gdouble, :gint64, :guint64
    from_basic_type type, val
  when :gint32, :guint32, :gint8, :GType
    FFI::Pointer.new val
  when GirFFI::EnumLikeBase
    FFI::Pointer.new type[val]
  when Module, :void
    val.to_ptr
  else
    raise NotImplementedError, type
  end
end

.from_array(type, ary) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gir_ffi/in_pointer.rb', line 8

def self.from_array(type, ary)
  return unless ary

  case type
  when Symbol
    from_simple_type_array type, ary
  when Module
    from_module_type_array type, ary
  when Array
    main_type, sub_type = *type
    raise "Unexpected main type #{main_type}" if main_type != :pointer

    from_pointer_array sub_type, ary
  else
    raise NotImplementedError, type
  end
end

.from_utf8(str) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/gir_ffi/in_pointer.rb', line 45

def self.from_utf8(str)
  return unless str

  ptr = FFI::MemoryPointer.from_string(str)
  ptr.autorelease = false
  ptr
end