# File lib/util/wrapper.rb, line 89
      def fetch_instance(impl, attachment_method = nil)
        # if the impl has a wrapper already attached, then return it
        if impl.instance_variable_defined?(:@proton_wrapper)
          return impl.instance_variable_get(:@proton_wrapper)
        end
        unless attachment_method.nil?
          record = Cproton.__send__(attachment_method, impl)
          rbkey = Cproton.pni_void2rbkey(Cproton.pn_record_get(record, RBCTX))
          # if we don't have a key, then we don't have an object
          return nil if rbkey.nil?
          registry_key = Cproton.Pn_rbkey_get_key_value(rbkey)
        else
          registry_key = get_key(impl)
        end
        # if the object's not in the registry then return
        return nil unless Qpid::Proton::Util::Wrapper.registry.has_key?(registry_key)

        result = Qpid::Proton::Util::Wrapper.registry[registry_key]
        # result = nil unless result.weakref_alive?
        if result.nil?
          raise Qpid::Proton::ProtonError.new("missing object for key=#{registry_key}")
        else
          # update the impl since the Swig wrapper for it may have changed
          result.impl = impl
        end
        return result
      end