Created
October 18, 2008 00:13
-
-
Save rue/17568 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From a95d5bcc0ecc2263710d8769627813ac8e70dab4 Mon Sep 17 00:00:00 2001 | |
| From: Eero Saynatkari <[email protected]> | |
| Date: Sat, 18 Oct 2008 03:10:45 +0300 | |
| Subject: [PATCH] Simplified NativeLibrary logic slightly. | |
| --- | |
| vm/native_libraries.cpp | 43 ++++++++++++++++++------------------------- | |
| vm/native_libraries.hpp | 47 ++++++++++++++++++----------------------------- | |
| 2 files changed, 36 insertions(+), 54 deletions(-) | |
| diff --git a/vm/native_libraries.cpp b/vm/native_libraries.cpp | |
| index 4ff0253..a8784ec 100644 | |
| --- a/vm/native_libraries.cpp | |
| +++ b/vm/native_libraries.cpp | |
| @@ -12,55 +12,43 @@ | |
| namespace rubinius { | |
| - void VM::init_native_libraries() | |
| - { | |
| + void VM::init_native_libraries() { | |
| globals.rubinius.get()->set_const(this, "LIBSUFFIX", String::create(this, RBX_LIBSUFFIX)); | |
| + | |
| rbx_dlinit(); | |
| } | |
| void* NativeLibrary::find_symbol(STATE, String* name, Object* library_name) { | |
| - rbx_dlhandle library = open(state, library_name); | |
| - | |
| - void* symbol = rbx_dlsym(library, name->c_str()); | |
| - | |
| - if (symbol == NULL) { | |
| - /* TODO: Why are we using this at all? dlopen should handle. */ | |
| - symbol = rbx_dlsym_default(name->c_str()); | |
| + void* symbol = rbx_dlsym(NativeLibrary::open(state, library_name), name->c_str()); | |
| - if (symbol == NULL) { | |
| - std::string message("NativeLibrary::find_symbol(): "); | |
| - message += rbx_dlerror(); | |
| - | |
| - Exception::system_call_error(state, message); | |
| - } | |
| + if(rbx_dlnosuch(symbol)) { | |
| + std::string message("NativeLibrary::load_symbol(): "); | |
| + Exception::system_call_error(state, message + rbx_dlerror()); | |
| } | |
| return symbol; | |
| } | |
| - /* TODO: Should be caching the default lib . */ | |
| rbx_dlhandle NativeLibrary::open(STATE, Object* name) { | |
| - std::ostringstream error_message("NativeLibrary::open(): "); | |
| - | |
| - /* TODO: fix */ | |
| if (name->nil_p()) { | |
| - return rbx_dldefault(); | |
| + return NativeLibrary::use_this_process(); | |
| } | |
| /* We should always get path without file extension. */ | |
| std::string path(as<String>(name)->c_str()); | |
| + std::ostringstream error_message("NativeLibrary::open(): "); | |
| rbx_dlhandle library = rbx_dlopen((path + RBX_LIBSUFFIX).c_str()); | |
| #ifdef RBX_LIBSUFFIX2 | |
| - if (library == NULL) { | |
| - error_message << rbx_dlerror() << "; "; | |
| + if(rbx_dlnosuch(library)) { | |
| + error_message << rbx_dlerror() << "; "; | |
| - library = rbx_dlopen((path + RBX_LIBSUFFIX2).c_str()); | |
| - } | |
| + library = rbx_dlopen((path + RBX_LIBSUFFIX2).c_str()); | |
| + } | |
| #endif | |
| - if (library == NULL) { | |
| + if(rbx_dlnosuch(library)) { | |
| error_message << rbx_dlerror(); | |
| Exception::system_call_error(state, error_message.str()); | |
| } | |
| @@ -68,5 +56,10 @@ namespace rubinius { | |
| return library; | |
| } | |
| + rbx_dlhandle NativeLibrary::use_this_process() { | |
| + static rbx_dlhandle self = rbx_dldefault(); | |
| + return self; | |
| + } | |
| + | |
| } | |
| diff --git a/vm/native_libraries.hpp b/vm/native_libraries.hpp | |
| index a53daf8..f413f74 100644 | |
| --- a/vm/native_libraries.hpp | |
| +++ b/vm/native_libraries.hpp | |
| @@ -14,33 +14,17 @@ | |
| #endif | |
| -#ifdef CONFIG_USE_LTDL | |
| +/* Little dynamic loading API. */ | |
| -#error | |
| +#include <dlfcn.h> | |
| - #include "ltdl.h" | |
| - | |
| - #define rbx_dlinit() lt_dlinit() | |
| - #define rbx_dlhandle lt_dlhandle | |
| - #define rbx_dldefault() lt_dlopen(NULL) | |
| - #define rbx_dlopen(name) lt_dlopen(name) | |
| - #define rbx_dlsym lt_dlsym | |
| - #define rbx_dlsym_default(name) lt_dlsym(NULL, name) | |
| - #define rbx_dlerror lt_dlerror | |
| - | |
| -#else | |
| - | |
| - #include <dlfcn.h> | |
| - | |
| - #define rbx_dlinit() /* No expansion */ | |
| - #define rbx_dlhandle void* | |
| - #define rbx_dldefault() RTLD_DEFAULT | |
| - #define rbx_dlopen(name) dlopen(name, RTLD_NOW | RTLD_GLOBAL) | |
| - #define rbx_dlsym dlsym | |
| - #define rbx_dlsym_default(name) dlsym(RTLD_DEFAULT, name) | |
| - #define rbx_dlerror dlerror | |
| - | |
| -#endif | |
| + #define rbx_dlerror dlerror | |
| + #define rbx_dldefault() RTLD_DEFAULT | |
| + #define rbx_dlhandle void* | |
| + #define rbx_dlinit() /* No expansion */ | |
| + #define rbx_dlnosuch(ptr) ((ptr) == NULL) | |
| + #define rbx_dlopen(name) dlopen(name, RTLD_NOW | RTLD_GLOBAL) | |
| + #define rbx_dlsym dlsym | |
| namespace rubinius { | |
| @@ -52,11 +36,16 @@ namespace rubinius { | |
| public: /* Interface */ | |
| /** Obtain function pointer to given symbol in given lib. */ | |
| - static void* find_symbol(STATE, String* name, Object* library_name); | |
| - /** Loader error message, if any. */ | |
| - static String* last_error_message(); | |
| + static void* find_symbol(STATE, String* name, Object* library_name); | |
| + | |
| /** Load and open a native library (or this process if nil.) */ | |
| - static rbx_dlhandle open(STATE, Object* library_name); | |
| + static rbx_dlhandle open(STATE, Object* library_name); | |
| + | |
| + | |
| + private: /* Internals */ | |
| + | |
| + /** Pseudo-library handle to this process and all its symbols. */ | |
| + static rbx_dlhandle use_this_process(); | |
| }; | |
| -- | |
| 1.5.4.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment