### Home Classes Methods

### In Files

- ext/ffi_c/ffi.c

### Parent

Object

### Namespace

- CLASS FFI::DynamicLibrary::Symbol

### Methods

- ::last_error
- ::new
- ::open
- #find_function
- #find_symbol
- #find_variable
- #last_error

### Files

- Makefile
- ChangeLog
- LICENSE
- README
- compile
- configure
- depcomp
- stamp-vti
- install-sh
- libtool-version
- mdate-sh
- missing

### Class/Module Index

Quicksearch

- FFI
- FFI::AbstractMemory
- FFI::AutoPointer
- FFI::AutoPointer::CallableReleaser
- FFI::AutoPointer::DefaultReleaser
- FFI::AutoPointer::Releaser
- FFI::ConstGenerator
- FFI::ConstGenerator::Constant
- FFI::DataConverter
- FFI::DynamicLibrary
- FFI::DynamicLibrary::Symbol
- FFI::Enum
- FFI::Enums
- FFI::Function
- FFI::FunctionType
- FFI::Generator
- FFI::Generator::Task
- FFI::IO
- FFI::LastError
- FFI::Library
- FFI::ManagedStruct
- FFI::MemoryPointer
- FFI::NativeType
- FFI::NotFoundError
- FFI::NullPointerError
- FFI::Platform
- FFI::PlatformError
- FFI::Pointer
- FFI::StrPtrConverter
- FFI::Struct
- FFI::Struct::InlineArray
- FFI::Struct::ManagedStructConverter
- FFI::StructByValue
- FFI::StructGenerator
- FFI::StructGenerator::Field
- FFI::StructLayout
- FFI::StructLayout::Enum
- FFI::StructLayout::InnerStruct
- FFI::StructLayout::Mapped
- FFI::StructLayoutBuilder
- FFI::Type
- FFI::Type::Builtin
- FFI::TypesGenerator
- FFI::Union
- FFI::VariadicInvoker

No matching classes.

# FFI::DynamicLibrary

### Attributes

name[R]

### Public Class Methods

last_error click to toggle source
@return [String] library's last error string

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

initialize(libname, libflags) click to toggle source
@param [String] libname name of library to open
@param [Fixnum] libflags flags for library to open
@return [FFI::DynamicLibrary]
@raise {LoadError} if +libname+ cannot be opened
A new DynamicLibrary instance.

    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);
        }
    #ifdef __CYGWIN__
        // On Cygwin 1.7.17 "dlsym(dlopen(0,0), 'getpid')" fails. (dlerror: "No such process")
        // As a workaround we can use "dlsym(RTLD_DEFAULT, 'getpid')" instead.
        // Since 0 == RTLD_DEFAULT we won't call dl_close later.
        if (libname == Qnil) {
            dl_close(library->handle);
            library->handle = RTLD_DEFAULT;
        }
    #endif
        rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]"));
        return self;
    }

open(libname, libflags) click to toggle source
@param libname (see #initialize)
@param libflags (see #initialize)
@return [FFI::DynamicLibrary]
@raise {LoadError} if +libname+ cannot be opened
Open a library.

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

### Public Instance Methods

find_function(name) click to toggle source
@param [String] name library function's name
@return [FFI::DynamicLibrary::Symbol] library function symbol

    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) click to toggle source
@param [String] name library symbol's name
@return [FFI::DynamicLibrary::Symbol] library symbol

    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) click to toggle source
@param [String] name library variable's name
@return [FFI::DynamicLibrary::Symbol] library variable symbol

    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_error click to toggle source
@return [String] library's last error string

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.