Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • dl/cfunc.c
  • dl/cptr.c
  • dl/dl.c
  • dl/lib/dl.rb
  • dl/lib/dl/callback.rb
  • dl/lib/dl/cparser.rb
  • dl/lib/dl/func.rb
  • dl/lib/dl/import.rb
  • dl/lib/dl/pack.rb
  • dl/lib/dl/stack.rb
  • dl/lib/dl/struct.rb
  • dl/lib/dl/types.rb
  • dl/lib/dl/value.rb
  • dl/win32/lib/Win32API.rb

DL

Public Class Methods

dlopen(*args) click to toggle source
 
               VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
    return rb_class_new_instance(argc, argv, rb_cDLHandle);
}
            
dlunwrap(p1) click to toggle source
 
               VALUE
rb_dl_ptr2value(VALUE self, VALUE addr)
{
    rb_secure(4);
    return (VALUE)NUM2PTR(addr);
}
            
dlwrap(p1) click to toggle source
 
               VALUE
rb_dl_value2ptr(VALUE self, VALUE val)
{
    return PTR2NUM((void*)val);
}
            
fiddle?() click to toggle source
 
               # File dl/lib/dl.rb, line 9
def self.fiddle?
  Object.const_defined?(:Fiddle)
end
            
free(addr) click to toggle source

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;
}
            
malloc click to toggle source

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);
}
            
realloc(addr, size) click to toggle source

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);
}
            

Public Instance Methods

remove_callback(addr, ctype = nil) click to toggle source
remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil) click to toggle source
 
               # 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
            
remove_cdecl_callback(addr, ctype = nil) click to toggle source
 
               # File dl/lib/dl/callback.rb, line 86
def remove_cdecl_callback(addr, ctype = nil)
  remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype)
end
            
Also aliased as: remove_callback
remove_stdcall_callback(addr, ctype = nil) click to toggle source
 
               # File dl/lib/dl/callback.rb, line 90
def remove_stdcall_callback(addr, ctype = nil)
  remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype)
end
            
set_callback(ty, argc, &cbp) click to toggle source
Alias for: set_cdecl_callback
set_callback_internal(proc_entry, addr_entry, argc, ty, abi = nil, &cbp) click to toggle source
 
               # 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
            
set_cdecl_callback(ty, argc, &cbp) click to toggle source
 
               # File dl/lib/dl/callback.rb, line 42
def set_cdecl_callback(ty, argc, &cbp)
  set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp)
end
            
Also aliased as: set_callback
set_stdcall_callback(ty, argc, &cbp) click to toggle source
 
               # 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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus