Class: FFI::DynamicLibrary

Inherits:
Object
  • Object
show all
Defined in:
ext/ffi_c/DynamicLibrary.c

Defined Under Namespace

Classes: Symbol

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(libname, libflags) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'ext/ffi_c/DynamicLibrary.c', line 64

static VALUE
library_initialize(VALUE self, VALUE libname, VALUE libflags)
{
    Library* library;
    int flags;

    Check_Type(libflags, T_FIXNUM);

    Data_Get_Struct(self, Library, library);
    flags = libflags != Qnil ? NUM2UINT(libflags) : 0;
    
    library->handle = dl_open(libname != Qnil ? StringValueCStr(libname) : NULL, flags);
    if (library->handle == NULL) {
        char errmsg[1024];
        dl_error(errmsg, sizeof(errmsg));
        rb_raise(rb_eLoadError, "Could not open library '%s': %s",
                libname != Qnil ? StringValueCStr(libname) : "[current process]",
                errmsg);
    }
    rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
    return self;
}

Instance Attribute Details

#nameObject (readonly)

Class Method Details

.last_errorObject



100
101
102
103
104
105
106
# File 'ext/ffi_c/DynamicLibrary.c', line 100

static VALUE
library_dlerror(VALUE self)
{
    char errmsg[1024];
    dl_error(errmsg, sizeof(errmsg));
    return rb_tainted_str_new2(errmsg);
}

.open(libname, libflags) ⇒ Object



58
59
60
61
62
# File 'ext/ffi_c/DynamicLibrary.c', line 58

static VALUE
library_open(VALUE klass, VALUE libname, VALUE libflags)
{
    return library_initialize(library_allocate(klass), libname, libflags);
}

Instance Method Details

#find_function(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/ffi_c/DynamicLibrary.c', line 87

static VALUE
library_dlsym(VALUE self, VALUE name)
{
    Library* library;
    void* address = NULL;
    Check_Type(name, T_STRING);

    Data_Get_Struct(self, Library, library);
    address = dl_sym(library->handle, StringValueCStr(name));
    
    return address != NULL ? symbol_new(self, address, name) : Qnil;
}

#find_symbol(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/ffi_c/DynamicLibrary.c', line 87

static VALUE
library_dlsym(VALUE self, VALUE name)
{
    Library* library;
    void* address = NULL;
    Check_Type(name, T_STRING);

    Data_Get_Struct(self, Library, library);
    address = dl_sym(library->handle, StringValueCStr(name));
    
    return address != NULL ? symbol_new(self, address, name) : Qnil;
}

#find_variable(name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'ext/ffi_c/DynamicLibrary.c', line 87

static VALUE
library_dlsym(VALUE self, VALUE name)
{
    Library* library;
    void* address = NULL;
    Check_Type(name, T_STRING);

    Data_Get_Struct(self, Library, library);
    address = dl_sym(library->handle, StringValueCStr(name));
    
    return address != NULL ? symbol_new(self, address, name) : Qnil;
}

#last_errorObject



100
101
102
103
104
105
106
# File 'ext/ffi_c/DynamicLibrary.c', line 100

static VALUE
library_dlerror(VALUE self)
{
    char errmsg[1024];
    dl_error(errmsg, sizeof(errmsg));
    return rb_tainted_str_new2(errmsg);
}