Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more
VALUE rb_dl_dlopen(int argc, VALUE argv[], VALUE self) { return rb_class_new_instance(argc, argv, rb_cDLHandle); }
VALUE rb_dl_ptr2value(VALUE self, VALUE addr) { rb_secure(4); return (VALUE)NUM2PTR(addr); }
VALUE rb_dl_value2ptr(VALUE self, VALUE val) { return PTR2NUM((void*)val); }
# File dl/lib/dl.rb, line 9 def self.fiddle? Object.const_defined?(:Fiddle) end
Free the memory at address addr
VALUE rb_dl_free(VALUE self, VALUE addr) { void *ptr = NUM2PTR(addr); rb_secure(4); ruby_xfree(ptr); return Qnil; }
Allocate size
bytes of memory and return the integer memory
address for the allocated memory.
VALUE rb_dl_malloc(VALUE self, VALUE size) { void *ptr; rb_secure(4); ptr = (void*)ruby_xmalloc(NUM2INT(size)); return PTR2NUM(ptr); }
Change the size of the memory allocated at the memory location
addr
to size
bytes. Returns the memory address
of the reallocated memory, which may be different than the address passed
in.
VALUE rb_dl_realloc(VALUE self, VALUE addr, VALUE size) { void *ptr = NUM2PTR(addr); rb_secure(4); ptr = (void*)ruby_xrealloc(ptr, NUM2INT(size)); return PTR2NUM(ptr); }
# File dl/lib/dl/callback.rb, line 54 def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil) if DL.fiddle? addr = addr.to_i return false unless proc_entry.key?(addr) proc_entry.delete(addr) true else index = nil if( ctype ) addr_entry[ctype].each_with_index{|xaddr, idx| if( xaddr == addr ) index = idx end } else addr_entry.each{|ty,entry| entry.each_with_index{|xaddr, idx| if( xaddr == addr ) index = idx end } } end if( index and proc_entry[ctype][index] ) proc_entry[ctype][index] = nil return true else return false end end end
# File dl/lib/dl/callback.rb, line 86 def remove_cdecl_callback(addr, ctype = nil) remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype) end
# File dl/lib/dl/callback.rb, line 90 def remove_stdcall_callback(addr, ctype = nil) remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype) end
# File dl/lib/dl/callback.rb, line 14 def set_callback_internal(proc_entry, addr_entry, argc, ty, abi = nil, &cbp) if( argc < 0 ) raise(ArgumentError, "arity should not be less than 0.") end addr = nil if DL.fiddle? abi ||= Fiddle::Function::DEFAULT closure = Fiddle::Closure::BlockCaller.new(ty, [TYPE_VOIDP] * argc, abi, &cbp) proc_entry[closure.to_i] = closure addr = closure.to_i else SEM.synchronize{ ary = proc_entry[ty] (0...MAX_CALLBACK).each{|n| idx = (n * DLSTACK_SIZE) + argc if( ary[idx].nil? ) ary[idx] = cbp addr = addr_entry[ty][idx] break end } } end addr end
# File dl/lib/dl/callback.rb, line 42 def set_cdecl_callback(ty, argc, &cbp) set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp) end
# File dl/lib/dl/callback.rb, line 46 def set_stdcall_callback(ty, argc, &cbp) if DL.fiddle? set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, Fiddle::Function::STDCALL, &cbp) else set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, &cbp) end end