Module: GirFFI::ArgHelper
- Defined in:
- lib/gir_ffi/arg_helper.rb
Overview
Helper module containing methods used during argument conversion in generated methods.
Defined Under Namespace
Classes: ObjectStore
Constant Summary collapse
- OBJECT_STORE =
ObjectStore.new
Class Method Summary collapse
- .cast_from_pointer(type, it) ⇒ Object
- .cast_pointer_to_int32(ptr) ⇒ Object
- .cast_uint32_to_int32(val) ⇒ Object
- .check_error(errpp) ⇒ Object
- .check_fixed_array_size(size, arr, name) ⇒ Object
- .ptr_to_utf8_length(ptr, len) ⇒ Object
Class Method Details
.cast_from_pointer(type, it) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gir_ffi/arg_helper.rb', line 48 def self.cast_from_pointer type, it case type when :utf8, :filename it.to_utf8 when :gint32, :gint8 cast_pointer_to_int32 it when Class type.wrap it when :guint32 it.address when Array main_type, subtype = *type raise "Unexpected main type #{main_type}" if main_type != :pointer case subtype when Array container_type, *element_type = *subtype raise "Unexpected container type #{container_type}" if container_type != :ghash GLib::HashTable.wrap(element_type, it) else raise "Unexpected subtype #{subtype}" end else raise "Don't know how to cast #{type}" end end |
.cast_pointer_to_int32(ptr) ⇒ Object
83 84 85 |
# File 'lib/gir_ffi/arg_helper.rb', line 83 def self.cast_pointer_to_int32 ptr cast_uint32_to_int32(ptr.address & 0xffffffff) end |
.cast_uint32_to_int32(val) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/gir_ffi/arg_helper.rb', line 75 def self.cast_uint32_to_int32 val if val >= 0x80000000 -(0x100000000-val) else val end end |
.check_error(errpp) ⇒ Object
37 38 39 40 |
# File 'lib/gir_ffi/arg_helper.rb', line 37 def self.check_error errpp err = GLib::Error.wrap(errpp.read_pointer) raise GLibError, err if err end |
.check_fixed_array_size(size, arr, name) ⇒ Object
42 43 44 45 46 |
# File 'lib/gir_ffi/arg_helper.rb', line 42 def self.check_fixed_array_size size, arr, name unless arr.size == size raise ArgumentError, "#{name} should have size #{size}" end end |
.ptr_to_utf8_length(ptr, len) ⇒ Object
33 34 35 |
# File 'lib/gir_ffi/arg_helper.rb', line 33 def self.ptr_to_utf8_length ptr, len ptr.null? ? nil : ptr.read_string(len) end |