Sha256: abf2f8e78557fe6f1243596f485e3621af79b295f00804862f90a332d26dd7f0

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

# frozen_string_literal: true

require "gir_ffi/class_base"

module GirFFI
  # Base class for generated classes representing boxed types.
  class BoxedBase < StructBase
    def initialize
      store_pointer(nil)
    end

    def self.make_finalizer(struct)
      proc do
        if struct.owned?
          struct.owned = nil
          GObject.boxed_free gtype, struct.to_ptr
        end
      end
    end

    def self.copy(val)
      ptr = GObject.boxed_copy(gtype, val)
      wrap(ptr)
    end

    private

    def store_pointer(*)
      super
      make_finalizer
    end

    def make_finalizer
      ObjectSpace.define_finalizer self, self.class.make_finalizer(struct)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-0.15.3 lib/gir_ffi/boxed_base.rb
gir_ffi-0.15.2 lib/gir_ffi/boxed_base.rb
gir_ffi-0.15.1 lib/gir_ffi/boxed_base.rb
gir_ffi-0.15.0 lib/gir_ffi/boxed_base.rb