Sha256: fc33c100516b979acf97bfb914b1637fac322ecda36c8d0e6d4233f7d97ccf56

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "gir_ffi/builders/base_return_value_builder"
require "gir_ffi/builders/ruby_to_c_convertor"

module GirFFI
  module Builders
    # Implements building post-processing statements for return values of
    # callbacks.
    class CallbackReturnValueBuilder < BaseReturnValueBuilder
      def post_conversion
        optional_outgoing_ref + base_post_conversion
      end

      private

      def has_post_conversion?
        relevant? && needs_ruby_to_c_conversion?
      end

      def needs_ruby_to_c_conversion?
        type_info.needs_ruby_to_c_conversion_for_callbacks?
      end

      def optional_outgoing_ref
        if outgoing_ref_needed?
          ["#{capture_variable_name}.ref"]
        else
          []
        end
      end

      def base_post_conversion
        if !has_post_conversion?
          []
        elsif specialized_type_tag == :object
          ["#{post_converted_name} = #{post_convertor.conversion}.to_ptr"]
        else
          ["#{post_converted_name} = #{post_convertor.conversion}"]
        end
      end

      def post_convertor
        @post_convertor ||= RubyToCConvertor.new(type_info, capture_variable_name)
      end

      def outgoing_ref_needed?
        ownership_transfer == :everything && specialized_type_tag == :object
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gir_ffi-0.18.0 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.17.0 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.16.1 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.16.0 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.9 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.8 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.7 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.6 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.5 lib/gir_ffi/builders/callback_return_value_builder.rb
gir_ffi-0.15.4 lib/gir_ffi/builders/callback_return_value_builder.rb