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); }
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 34 def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil) 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
# File dl/lib/dl/callback.rb, line 59 def remove_cdecl_callback(addr, ctype = nil) remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype) end
# File dl/lib/dl/callback.rb, line 63 def remove_stdcall_callback(addr, ctype = nil) remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype) end
# File dl/lib/dl/callback.rb, line 7 def set_callback_internal(proc_entry, addr_entry, argc, ty, &cbp) if( argc < 0 ) raise(ArgumentError, "arity should not be less than 0.") end addr = nil 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 } } addr end
# File dl/lib/dl/callback.rb, line 26 def set_cdecl_callback(ty, argc, &cbp) set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp) end