Module: GirFFI::ArgHelper
- Defined in:
- lib/gir_ffi/arg_helper.rb
Overview
Helper module containing methods used during argument conversion in generated methods.
Constant Summary collapse
- OBJECT_STORE =
ObjectStore.new
Class Method Summary collapse
-
.cast_from_pointer(type, ptr) ⇒ Object
NOTE: Only used in List, SList and HashTable classes.
- .cast_pointer_to_int32(ptr) ⇒ Object
- .cast_uint32_to_int32(val) ⇒ Object
- .check_error(errpp) ⇒ Object
- .check_fixed_array_size(size, arr, name) ⇒ Object
- .store(obj) ⇒ Object
Class Method Details
.cast_from_pointer(type, ptr) ⇒ Object
NOTE: Only used in List, SList and HashTable classes. TODO: Stop using basic types and instead cast type to an ITypeInfo look-alike.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gir_ffi/arg_helper.rb', line 27 def self.cast_from_pointer(type, ptr) case type when Symbol cast_from_simple_type_pointer(type, ptr) when Class type.wrap ptr when Array cast_from_complex_type_pointer(type, ptr) end end |
.cast_pointer_to_int32(ptr) ⇒ Object
46 47 48 |
# File 'lib/gir_ffi/arg_helper.rb', line 46 def self.cast_pointer_to_int32(ptr) cast_uint32_to_int32(ptr.address & 0xffffffff) end |
.cast_uint32_to_int32(val) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/gir_ffi/arg_helper.rb', line 38 def self.cast_uint32_to_int32(val) if val >= 0x80000000 -(0x100000000 - val) else val end end |
.check_error(errpp) ⇒ Object
13 14 15 16 |
# File 'lib/gir_ffi/arg_helper.rb', line 13 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
18 19 20 21 22 |
# File 'lib/gir_ffi/arg_helper.rb', line 18 def self.check_fixed_array_size(size, arr, name) unless arr.size.equal? size raise ArgumentError, "#{name} should have size #{size}" end end |
.store(obj) ⇒ Object
50 51 52 |
# File 'lib/gir_ffi/arg_helper.rb', line 50 def self.store(obj) OBJECT_STORE.store(obj) end |