Sha256: 51bd376376cae4879e89f798632a3f1302fda32b60b455104d8b3174bd3203b2

Contents?: true

Size: 558 Bytes

Versions: 8

Compression:

Stored size: 558 Bytes

Contents

# frozen_string_literal: true
module GirFFI
  # Helper class for storing objects for later retrieval. Used to store user
  # data arguments.
  class ObjectStore
    def initialize
      @store = {}
    end

    def store(obj)
      return FFI::Pointer::NULL if obj.nil?
      # FIXME: Don't use object_id!
      key = obj.object_id
      @store[key] = obj
      FFI::Pointer.new(key)
    end

    def fetch(ptr)
      return if ptr.null?
      key = ptr.address
      if @store.key? key
        @store[key]
      else
        ptr
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gir_ffi-0.11.1 lib/gir_ffi/object_store.rb
gir_ffi-0.11.0 lib/gir_ffi/object_store.rb
gir_ffi-0.10.2 lib/gir_ffi/object_store.rb
gir_ffi-0.10.1 lib/gir_ffi/object_store.rb
gir_ffi-0.10.0 lib/gir_ffi/object_store.rb
gir_ffi-0.10.0.pre1 lib/gir_ffi/object_store.rb
gir_ffi-0.9.5 lib/gir_ffi/object_store.rb
gir_ffi-0.9.4 lib/gir_ffi/object_store.rb