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

In Files

  • dl/dl.c
  • dl/lib/dl/import.rb
  • dl/lib/dl/struct.rb
  • dl/lib/dl/types.rb
  • dl/lib/dl/win32.rb
  • dl/sym.c

DL

Public Class Methods

callback(p1, p2 = v2) click to toggle source
 
               static VALUE
rb_dl_callback(int argc, VALUE argv[], VALUE self)
{
  VALUE type, proc;
  int rettype, entry, i;
  char fname[127];

  rb_secure(4);
  proc = Qnil;
  switch (rb_scan_args(argc, argv, "11", &type, &proc)) {
  case 1:
    if (rb_block_given_p()) {
      proc = rb_block_proc();
    }
    else{
      proc = Qnil;
    }
  default:
    break;
  }

  StringValue(type);
  switch (RSTRING(type)->ptr[0]) {
  case '0':
    rettype = 0x00;
    break;
  case 'C':
    rettype = 0x01;
    break;
  case 'H':
    rettype = 0x02;
    break;
  case 'I':
    rettype = 0x03;
    break;
  case 'L':
    rettype = 0x04;
    break;
  case 'F':
    rettype = 0x05;
    break;
  case 'D':
    rettype = 0x06;
    break;
  case 'P':
    rettype = 0x07;
    break;
  default:
    rb_raise(rb_eDLTypeError, "unsupported type `%c'", RSTRING(type)->ptr[0]);
  }

  entry = -1;
  for (i=0; i < MAX_CALLBACK; i++) {
    if (rb_hash_aref(DLFuncTable, rb_assoc_new(INT2NUM(rettype), INT2NUM(i))) == Qnil) {
      entry = i;
      break;
    }
  }
  if (entry < 0) {
    rb_raise(rb_eDLError, "too many callbacks are defined.");
  }

  rb_hash_aset(DLFuncTable,
               rb_assoc_new(INT2NUM(rettype),INT2NUM(entry)),
               rb_assoc_new(type,proc));
  sprintf(fname, "rb_dl_callback_func_%d_%d", rettype, entry);
  return rb_dlsym_new((void (*)())rb_dl_callback_table[rettype][entry],
                      fname, RSTRING(type)->ptr);
}
            
define_callback(p1, p2 = v2) click to toggle source
 
               static VALUE
rb_dl_callback(int argc, VALUE argv[], VALUE self)
{
  VALUE type, proc;
  int rettype, entry, i;
  char fname[127];

  rb_secure(4);
  proc = Qnil;
  switch (rb_scan_args(argc, argv, "11", &type, &proc)) {
  case 1:
    if (rb_block_given_p()) {
      proc = rb_block_proc();
    }
    else{
      proc = Qnil;
    }
  default:
    break;
  }

  StringValue(type);
  switch (RSTRING(type)->ptr[0]) {
  case '0':
    rettype = 0x00;
    break;
  case 'C':
    rettype = 0x01;
    break;
  case 'H':
    rettype = 0x02;
    break;
  case 'I':
    rettype = 0x03;
    break;
  case 'L':
    rettype = 0x04;
    break;
  case 'F':
    rettype = 0x05;
    break;
  case 'D':
    rettype = 0x06;
    break;
  case 'P':
    rettype = 0x07;
    break;
  default:
    rb_raise(rb_eDLTypeError, "unsupported type `%c'", RSTRING(type)->ptr[0]);
  }

  entry = -1;
  for (i=0; i < MAX_CALLBACK; i++) {
    if (rb_hash_aref(DLFuncTable, rb_assoc_new(INT2NUM(rettype), INT2NUM(i))) == Qnil) {
      entry = i;
      break;
    }
  }
  if (entry < 0) {
    rb_raise(rb_eDLError, "too many callbacks are defined.");
  }

  rb_hash_aset(DLFuncTable,
               rb_assoc_new(INT2NUM(rettype),INT2NUM(entry)),
               rb_assoc_new(type,proc));
  sprintf(fname, "rb_dl_callback_func_%d_%d", rettype, entry);
  return rb_dlsym_new((void (*)())rb_dl_callback_table[rettype][entry],
                      fname, RSTRING(type)->ptr);
}
            
dlopen(*args) click to toggle source
 
               VALUE
rb_dl_dlopen(int argc, VALUE argv[], VALUE self)
{
  rb_secure(2);
  return rb_class_new_instance(argc, argv, rb_cDLHandle);
}
            
last_error() click to toggle source
 
               static VALUE
rb_dl_get_last_error(VALUE self)
{
  return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLErrno);
}
            
last_error=(p1) click to toggle source
 
               static VALUE
rb_dl_set_last_error(VALUE self, VALUE val)
{
  errno = NUM2INT(val);
  rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLErrno, val);
  return Qnil;
}
            
malloc(p1) click to toggle source
 
               VALUE
rb_dl_malloc(VALUE self, VALUE size)
{
  rb_secure(4);
  return rb_dlptr_malloc(DLNUM2LONG(size), dlfree);
}
            
remove_callback(p1) click to toggle source
 
               static VALUE
rb_dl_remove_callback(VALUE mod, VALUE sym)
{
  freefunc_t f;
  int i, j;

  rb_secure(4);
  f = rb_dlsym2csym(sym);
  for (i=0; i < CALLBACK_TYPES; i++) {
    for (j=0; j < MAX_CALLBACK; j++) {
      if (rb_dl_callback_table[i][j] == f) {
        rb_hash_aset(DLFuncTable, rb_assoc_new(INT2NUM(i),INT2NUM(j)),Qnil);
        break;
      }
    }
  }
  return Qnil;
}
            
sizeof(p1) click to toggle source
 
               static VALUE
rb_dl_sizeof(VALUE self, VALUE str)
{
  return INT2NUM(dlsizeof(StringValuePtr(str)));
}
            
strdup(p1) click to toggle source
 
               VALUE
rb_dl_strdup(VALUE self, VALUE str)
{
  SafeStringValue(str);
  return rb_dlptr_new(strdup(RSTRING(str)->ptr), RSTRING(str)->len, dlfree);
}
            
win32_last_error() click to toggle source
 
               static VALUE
rb_dl_win32_get_last_error(VALUE self)
{
  return rb_thread_local_aref(rb_thread_current(), rb_dl_id_DLW32Error);
}
            
win32_last_error=(p1) click to toggle source
 
               static VALUE
rb_dl_win32_set_last_error(VALUE self, VALUE val)
{
    SetLastError(NUM2INT(val));
    rb_thread_local_aset(rb_thread_current(), rb_dl_id_DLW32Error, val);
    return Qnil;
}
            

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