Sha256: 45bfcd9c74d533e13e7925c18a32a7d7f76251c28d1ca536348995a3106c42ff

Contents?: true

Size: 484 Bytes

Versions: 3

Compression:

Stored size: 484 Bytes

Contents

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)
      # 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

3 entries across 3 versions & 1 rubygems

Version Path
gir_ffi-0.9.2 lib/gir_ffi/object_store.rb
gir_ffi-0.9.1 lib/gir_ffi/object_store.rb
gir_ffi-0.9.0 lib/gir_ffi/object_store.rb