class GirFFI::Builders::CallbackArgumentBuilder
Convertor for arguments for ruby callbacks. Used when building the argument mapper for callbacks.
Public Instance Methods
allow_none?()
click to toggle source
All arguments to the argument mapper must always be provided. They may be nil, though.
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 24 def allow_none? false end
block_argument?()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 18 def block_argument? false end
call_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 41 def call_argument_name pre_converted_name if [:in, :inout].include?(direction) && !array_arg end
capture_variable_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 45 def capture_variable_name result_name if [:out, :inout].include?(direction) && !array_arg end
method_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 14 def method_argument_name @method_argument_name ||= name || new_variable end
out_parameter_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 32 def out_parameter_name @out_parameter_name ||= if direction == :inout new_variable else pre_converted_name end end
post_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 62 def post_conversion case direction when :out, :inout [value_to_pointer_conversion] when :error [ "rescue => #{result_name}", value_to_pointer_conversion, "end" ] else [] end end
pre_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 49 def pre_conversion case direction when :in [ingoing_pre_conversion] when :out [out_parameter_preparation] when :inout [out_parameter_preparation, ingoing_pre_conversion] when :error [out_parameter_preparation, "begin"] end end
pre_converted_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 28 def pre_converted_name @pre_converted_name ||= new_variable end
Private Instance Methods
allocated_by_us?()
click to toggle source
Check if an out argument needs to be allocated by us, the callee. Since caller_allocates is false by default, we must also check that the type is a pointer. For example, an out parameter of type gint8* will always be allocate by the caller.
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 163 def allocated_by_us? direction == :out && !@arginfo.caller_allocates? && type_info.pointer? && ![:object, :zero_terminated].include?(specialized_type_tag) end
ingoing_pre_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 124 def ingoing_pre_conversion "#{pre_converted_name} = #{pre_convertor.conversion}" end
length_argument_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 170 def length_argument_name length_arg&.pre_converted_name end
needs_c_to_ruby_conversion?()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 120 def needs_c_to_ruby_conversion? type_info.needs_c_to_ruby_conversion_for_callbacks? end
out_parameter_preparation()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 144 def out_parameter_preparation value = if allocated_by_us? ffi_type = TypeMap.type_specification_to_ffi_type type_spec.last "FFI::MemoryPointer.new(#{ffi_type.inspect})" \ ".tap { |ptr| #{method_argument_name}.put_pointer 0, ptr }" else method_argument_name end "#{out_parameter_name} = #{value}" end
pointer_to_value_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 99 def pointer_to_value_conversion pointer_value_convertor.pointer_to_value(out_parameter_name) end
pointer_value_convertor()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 91 def pointer_value_convertor @pointer_value_convertor ||= if allocated_by_us? PointerValueConvertor.new(type_spec[1]) else PointerValueConvertor.new(type_spec) end end
post_convertor()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 128 def post_convertor @post_convertor ||= if type_info.needs_ruby_to_c_conversion_for_callbacks? RubyToCConvertor.new(type_info, post_convertor_argument) else NullConvertor.new(post_convertor_argument) end end
post_convertor_argument()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 136 def post_convertor_argument if array_arg "#{array_arg.capture_variable_name}.length" else result_name end end
pre_convertor()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 108 def pre_convertor @pre_convertor ||= if user_data? ClosureConvertor.new(pre_convertor_argument) elsif needs_c_to_ruby_conversion? CToRubyConvertor.new(type_info, pre_convertor_argument, length_argument_name) else NullConvertor.new(pre_convertor_argument) end end
pre_convertor_argument()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 83 def pre_convertor_argument if direction == :inout pointer_to_value_conversion else method_argument_name end end
result_name()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 79 def result_name @result_name ||= new_variable end
type_spec()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 155 def type_spec type_info.tag_or_class end
value_to_pointer_conversion()
click to toggle source
# File lib/gir_ffi/builders/callback_argument_builder.rb, line 103 def value_to_pointer_conversion pointer_value_convertor.value_to_pointer(out_parameter_name, post_convertor.conversion) end