Class: DL::CarriedFunction

Inherits:
Function show all
Defined in:
lib/dl/func.rb

Constant Summary

Constants included from DL

ALIGN_CHAR, ALIGN_DOUBLE, ALIGN_FLOAT, ALIGN_INT, ALIGN_INTPTR_T, ALIGN_LONG, ALIGN_LONG_LONG, ALIGN_PTRDIFF_T, ALIGN_SHORT, ALIGN_SIZE_T, ALIGN_SSIZE_T, ALIGN_UINTPTR_T, ALIGN_VOIDP, BUILD_RUBY_PLATFORM, BUILD_RUBY_VERSION, CdeclCallbackAddrs, CdeclCallbackProcs, DLSTACK_SIZE, MAX_CALLBACK, NULL, RTLD_GLOBAL, RTLD_LAZY, RTLD_NOW, RUBY_FREE, SEM, SIZEOF_CHAR, SIZEOF_DOUBLE, SIZEOF_FLOAT, SIZEOF_INT, SIZEOF_INTPTR_T, SIZEOF_LONG, SIZEOF_LONG_LONG, SIZEOF_PTRDIFF_T, SIZEOF_SHORT, SIZEOF_SIZE_T, SIZEOF_SSIZE_T, SIZEOF_UINTPTR_T, SIZEOF_VOIDP, StdcallCallbackAddrs, StdcallCallbackProcs, TYPE_CHAR, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INT, TYPE_INTPTR_T, TYPE_LONG, TYPE_LONG_LONG, TYPE_PTRDIFF_T, TYPE_SHORT, TYPE_SIZE_T, TYPE_SSIZE_T, TYPE_UINTPTR_T, TYPE_VOID, TYPE_VOIDP

Instance Method Summary collapse

Methods inherited from Function

#bind, #bound?, #call, call_type_to_abi, class_fiddle_closure_cfunc, #name, #to_i, #unbind, #unbind_at_call, #wrap_result

Methods included from ValueUtil

#signed_value, #unsigned_value, #wrap_arg, #wrap_args

Methods included from DL

dlopen, dlunwrap, dlwrap, fiddle?, free, malloc, realloc, #remove_callback_internal, #remove_cdecl_callback, #remove_stdcall_callback, #set_callback_internal, #set_cdecl_callback, #set_stdcall_callback

Constructor Details

#initialize(cfunc, argtypes, n) ⇒ CarriedFunction

Returns a new instance of CarriedFunction.



218
219
220
221
222
223
# File 'lib/dl/func.rb', line 218

def initialize(cfunc, argtypes, n)
  super(cfunc, argtypes)
  @carrier = []
  @index = n
  @mutex = Mutex.new
end

Instance Method Details

#bind_at_call(&block) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/dl/func.rb', line 233

def bind_at_call(&block)
  userdata = @carrier[-1]
  userdata[0].push(block)
  bind{|*args|
    ptr = args[@index]
    if( !ptr )
      raise(RuntimeError, "The index of userdata should be lower than #{args.size}.")
    end
    userdata = dlunwrap(Integer(ptr))
    args[@index] = userdata[1]
    userdata[0][0].call(*args)
  }
  @mutex.unlock()
end

#create_carrier(data) ⇒ Object



225
226
227
228
229
230
231
# File 'lib/dl/func.rb', line 225

def create_carrier(data)
  ary = []
  userdata = [ary, data]
  @mutex.lock()
  @carrier.push(userdata)
  return dlwrap(userdata)
end