コード例 #1
0
ファイル: dlload.c プロジェクト: casunlight/julia
uv_lib_t *jl_load_dynamic_library(char *modname)
{
    int error;
    char *ext;
    char path[PATHBUF];
    int i;
    uv_lib_t *handle=malloc(sizeof(uv_lib_t));
    handle->errmsg=NULL;

    if (modname == NULL) {
#ifdef _WIN32
        if(!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
            (LPCSTR)(&jl_load_dynamic_library),
            &handle->handle))
            jl_errorf("could not load base module", modname);
#else
        handle->handle = dlopen(NULL,RTLD_NOW);
#endif
        goto done;
    }
#ifdef _WIN32
    else if (modname[1] == ':') {
#else
    else if (modname[0] == '/') {
#endif
        error = jl_uv_dlopen(modname,handle);
        if (!error) goto done;
    }

    for(i=0; i < N_EXTENSIONS; i++) {
        ext = extensions[i];
        path[0] = '\0';
        handle->handle = NULL;
        /* try loading from standard library path */
        snprintf(path, PATHBUF, "%s%s", modname, ext);
        error = jl_uv_dlopen(path, handle);
        if (!error) goto done;
    }
#if defined(__linux__)
    char *soname = jl_lookup_soname(modname, strlen(modname));
    error = (soname==NULL) || jl_uv_dlopen(soname, handle);
    if (!error) goto done;
#endif

    //JL_PRINTF(JL_STDERR, "could not load module %s (%d): %s\n", modname, error, uv_dlerror(handle));
    jl_errorf("could not load module %s: %s", modname, uv_dlerror(handle));
    uv_dlclose(handle);
    free(handle);
    return NULL;
done:
    return handle;
}

void *jl_dlsym_e(uv_lib_t *handle, char *symbol)
{
    void *ptr;
    int  error=uv_dlsym(handle, symbol, &ptr);
    if(error) ptr=NULL;
    return ptr;
}
コード例 #2
0
static void
setup_args(void)
{
    int r, argc;
    char **argv;
    void (*Py_GetArgcArgv)(int *argc, char ***argv);
    uv_lib_t dlmain;

    r = uv_dlopen(NULL, &dlmain);
    if (r != 0) {
        return;
    }

    r = uv_dlsym(&dlmain, "Py_GetArgcArgv", (void **)&Py_GetArgcArgv);
    if (r != 0) {
        uv_dlclose(&dlmain);
        return;
    }

    Py_GetArgcArgv(&argc, &argv);
    uv_dlclose(&dlmain);

    uv_setup_args(argc, argv);
    setup_args_called = True;
}
コード例 #3
0
ファイル: rtScriptDuk.cpp プロジェクト: madanagopalt/pxCore
// Load a duktape C function from a shared library by path and name.
static duk_ret_t duv_loadlib(duk_context *ctx) {
  const char *name, *path;
  uv_lib_t lib;
  duk_c_function fn;

  // Check the args
  const duv_schema_entry schema[] = {
    { "path", duk_is_string },
    { "name", duk_is_string },
    { NULL, NULL }
  };

  dschema_check(ctx, schema);

  path = duk_get_string(ctx, 0);
  name = duk_get_string(ctx, 1);

  if (uv_dlopen(path, &lib)) {
    duk_error(ctx, DUK_ERR_ERROR, "Cannot load shared library %s", path);
    return 0;
  }
  if (uv_dlsym(&lib, name, (void**)&fn)) {
    duk_error(ctx, DUK_ERR_ERROR, "Unable to find %s in %s", name, path);
    return 0;
  }
  duk_push_c_function(ctx, fn, 0);
  return 1;
}
コード例 #4
0
ファイル: dlload.c プロジェクト: GordStephen/julia
void *jl_dlsym(jl_uv_libhandle handle, const char *symbol)
{
    void *ptr;
    int error = uv_dlsym((uv_lib_t *) handle, symbol, &ptr);
    if (error) {
        jl_errorf("could not load symbol '%s'\n%s", symbol, uv_dlerror((uv_lib_t *) handle));
    }
    return ptr;
}
コード例 #5
0
ファイル: dlload.c プロジェクト: ajpkane/julia
void *jl_dlsym(uv_lib_t *handle, char *symbol)
{
    void *ptr;
    int  error = uv_dlsym(handle, symbol, &ptr);
    if (error != 0) {
        JL_PRINTF(JL_STDERR, "symbol could not be found %s (%d): %s\n", symbol, error, uv_dlerror(handle));
    }
    return ptr;
}
コード例 #6
0
ファイル: dlload.c プロジェクト: benracine/julia
void *jl_dlsym(uv_lib_t *handle, char *symbol)
{
    void *ptr;
    int  error = uv_dlsym(handle, symbol, &ptr);
    if (error != 0) {
        JL_PRINTF(JL_STDERR, "symbol could not be found %s (%d): %s", symbol, error, handle->errmsg!=NULL?handle->errmsg:"");
    }
    return ptr;
}
コード例 #7
0
ファイル: dlload.c プロジェクト: BobPortmann/julia
void *jl_dlsym(jl_uv_libhandle handle, const char *symbol)
{
    void *ptr;
    int  error = uv_dlsym((uv_lib_t *) handle, symbol, &ptr);
    if (error != 0) {
        jl_printf(JL_STDERR, "symbol could not be found %s (%d): %s\n", symbol, error, uv_dlerror((uv_lib_t *) handle));
    }
    return ptr;
}
コード例 #8
0
ファイル: hcp.cpp プロジェクト: husqvarnagroup/hcp
bool hcp::Runtime::loadLibrary(char* path, hcp::tCodec * destination, const char** error) {
	destination->binary = uv_lib_t();

	if (uv_dlopen(path, &destination->binary) != 0) {
		if (error) {
			*error = uv_dlerror(&destination->binary);
		}

		return false;
	}

	void* loadHandle = nullptr;

	if (uv_dlsym(&destination->binary, "hcp_GetLibrary", &loadHandle) != 0) {
		uv_dlclose(&destination->binary);

		if (error) {
			*error = uv_dlerror(&destination->binary);
		}

		return false;
	}

	auto handle = ((LoadCodec)loadHandle)();

	if (handle == nullptr) {
		if (error) {
			*error = "Codec Library failed to load.";
		}

		return false;
	}

	char* codecName = (char*)hcp_Malloc(_state, 512);
	auto result = hcp_LoadCodec(_state, handle, codecName, 512);

	if (result != HCP_NOERROR) {
		if (error) {
			hcp_Free(_state, codecName);
			// this causes a memory leak
			*error = (const char*)hcp_Malloc(_state, 1024);
			hcp_GetMessage(result, (hcp_szStr)*error, 1024);
		}
		

		uv_dlclose(&destination->binary);

		return false;
	}

	destination->lib = handle;
	destination->path = path;
	destination->name = codecName;

	return true;
}
コード例 #9
0
ファイル: libuv.c プロジェクト: PKRoma/libwebsockets
int
lws_uv_plugins_destroy(struct lws_context *context)
{
	struct lws_plugin *plugin = context->plugin_list, *p;
	lws_plugin_destroy_func func;
	char path[256];
	int pofs = 0;
	void *v;
	int m;

#if  defined(__MINGW32__) || !defined(WIN32)
	pofs = 3;
#endif

	if (!plugin)
		return 0;

	while (plugin) {
		p = plugin;

#if !defined(WIN32) && !defined(__MINGW32__)
		m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s",
				 plugin->name + pofs);
		path[m - 3] = '\0';
#else
		m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s",
				 plugin->name + pofs);
		path[m - 4] = '\0';
#endif

		if (uv_dlsym(&plugin->lib, path, &v)) {
			uv_dlerror(&plugin->lib);
			lwsl_err("Failed to get %s on %s: %s", path,
					plugin->name, plugin->lib.errmsg);
		} else {
			func = (lws_plugin_destroy_func)v;
			m = func(context);
			if (m)
				lwsl_err("Destroying %s failed %d\n",
						plugin->name, m);
		}

		uv_dlclose(&p->lib);
		plugin = p->list;
		p->list = NULL;
		free(p);
	}

	context->plugin_list = NULL;

	while (uv_loop_close(&context->uv.loop))
		;

	return 0;
}
コード例 #10
0
ファイル: dl.c プロジェクト: mattn/mruby-uv
void*
mrb_uv_dlsym(mrb_state *mrb, mrb_value dl, char const *name)
{
  int err;
  void *p;
  uv_lib_t *lib = (uv_lib_t*)mrb_uv_get_ptr(mrb, dl, &dl_type);
  err = uv_dlsym(lib, name, &p);
  if(err == -1) {
    mrb_raise(mrb, E_UV_ERROR, uv_dlerror(lib));
  }
  return p;
}
コード例 #11
0
ファイル: libuv.c プロジェクト: paroga/libwebsockets
LWS_VISIBLE int
lws_plat_plugins_destroy(struct lws_context * context)
{
	struct lws_plugin *plugin = context->plugin_list, *p;
	lws_plugin_destroy_func func;
	char path[256];
	void *v;
	int m;

	if (!plugin)
		return 0;

	// lwsl_notice("%s\n", __func__);

	while (plugin) {
		p = plugin;
#if !defined(WIN32)
		m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", plugin->name + 3);
		path[m - 3] = '\0';
#else
		m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", plugin->name);
		path[m - 4] = '\0';
#endif

		if (uv_dlsym(&plugin->lib, path, &v)) {
			uv_dlerror(&plugin->lib);
			lwsl_err("Failed to get init on %s: %s",
					plugin->name, plugin->lib.errmsg);
		} else {
			func = (lws_plugin_destroy_func)v;
			m = func(context);
			if (m)
				lwsl_err("Destroying %s failed %d\n",
						plugin->name, m);
		}

		uv_dlclose(&p->lib);
		plugin = p->list;
		p->list = NULL;
		free(p);
	}

	context->plugin_list = NULL;

	return 0;
}
コード例 #12
0
ファイル: module.c プロジェクト: cryogen/oftc-ircd
bool
module_load(const char *path)
{
    Module *module;
    ModuleInfo *moduleInfo;

    module = module_new();

    module->Path = StrDup(path);

    if(uv_dlopen(path, &module->handle) < 0)
    {
        module_free(module);
        return false;
    }

    if(uv_dlsym(&module->handle, "ModuleInfoPtr", (void **)&moduleInfo) < 0)
    {
        module_free(module);
        return false;
    }

    if(moduleInfo == NULL)
    {
        module_free(module);
        return false;
    }

    if(moduleInfo->Load != NULL)
    {
        moduleInfo->Load();
    }

    vector_push_back(ModuleList, module);

    return true;
}
コード例 #13
0
ファイル: dlload.c プロジェクト: ajpkane/julia
void *jl_dlsym_e(uv_lib_t *handle, char *symbol) {
    void *ptr;
    int  error=uv_dlsym(handle, symbol, &ptr);
    if(error) ptr=NULL;
    return ptr;
}
コード例 #14
0
ファイル: dlload.c プロジェクト: BobPortmann/julia
static uv_lib_t *jl_load_dynamic_library_(const char *modname, unsigned flags, int throw_err)
{
    int error;
    char *ext;
    char path[PATHBUF];
    int i;
    uv_lib_t *handle = (uv_lib_t*)malloc(sizeof(uv_lib_t));
    handle->errmsg = NULL;

    if (modname == NULL) {
#ifdef _OS_WINDOWS_
        if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                                (LPCWSTR)(&jl_load_dynamic_library),
                                &handle->handle))
            jl_errorf("could not load base module", modname);
#else
        handle->handle = dlopen(NULL,RTLD_NOW);
#endif
        goto done;
    }
#ifdef _OS_WINDOWS_
    else if (modname[1] == ':') {
#else
    else if (modname[0] == '/') {
#endif
        error = jl_uv_dlopen(modname,handle,flags);
        if (!error) goto done;
    }
    else if (jl_base_module != NULL) {
        jl_array_t *DL_LOAD_PATH = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("DL_LOAD_PATH"));
        if (DL_LOAD_PATH != NULL) {
            size_t j;
            for (j = 0; j < jl_array_len(DL_LOAD_PATH); j++) {
                char *dl_path = jl_string_data(jl_cell_data(DL_LOAD_PATH)[j]);
                size_t len = strlen(dl_path);
                if (len == 0)
                    continue;
                for(i=0; i < N_EXTENSIONS; i++) {
                    ext = extensions[i];
                    path[0] = '\0';
                    handle->handle = NULL;
                    if (dl_path[len-1] == PATHSEPSTRING[0])
                        snprintf(path, PATHBUF, "%s%s%s", dl_path, modname, ext);
                    else
                        snprintf(path, PATHBUF, "%s" PATHSEPSTRING "%s%s", dl_path, modname, ext);
                    if (handle->errmsg) {
                        uv_dlclose(handle);
                    }
                    error = jl_uv_dlopen(path, handle, flags);
                    if (!error) goto done;
                }
            }
        }
    }
    for(i=0; i < N_EXTENSIONS; i++) {
        ext = extensions[i];
        path[0] = '\0';
        handle->handle = NULL;
        /* try loading from standard library path */
        snprintf(path, PATHBUF, "%s%s", modname, ext);
        if (handle->errmsg) {
            uv_dlclose(handle);
        }
        error = jl_uv_dlopen(path, handle, flags);
        if (!error) goto done;
    }

#if defined(__linux__) || defined(__FreeBSD__)
    {
        const char *soname = jl_lookup_soname(modname, strlen(modname));
        if (handle->errmsg) {
            free(handle->errmsg);
            handle->errmsg = NULL;
        }
        error = (soname==NULL) || jl_uv_dlopen(soname, handle, flags);
        if (!error) goto done;
    }
#endif

    if (throw_err) {
        //jl_printf(JL_STDERR, "could not load module %s (%d): %s\n", modname, error, uv_dlerror(handle));
        jl_errorf("could not load module %s: %s", modname, uv_dlerror(handle));
    }
    uv_dlclose(handle);
    free(handle);
    return NULL;
done:
    return handle;
}

jl_uv_libhandle jl_load_dynamic_library_e(const char *modname, unsigned flags)
{
    return (jl_uv_libhandle) jl_load_dynamic_library_(modname, flags, 0);
}

jl_uv_libhandle jl_load_dynamic_library(const char *modname, unsigned flags)
{
    return (jl_uv_libhandle) jl_load_dynamic_library_(modname, flags, 1);
}

void *jl_dlsym_e(jl_uv_libhandle handle, const char *symbol)
{
    void *ptr;
    int  error=uv_dlsym((uv_lib_t *) handle, symbol, &ptr);
    if (error) ptr=NULL;
    return ptr;
}
コード例 #15
0
ファイル: ls_task_setting.c プロジェクト: chuqingq/LoadGen
// master不保存settings,直接传给plugin_init()
int load_task_setting(ls_master_t* master) {
    LOG("load_task_setting()\n");
    const char* setting_file = "task/setting.json";

    char* buf;
    long len;
    FILE* f = fopen(setting_file, "r");
    if (f == NULL) {
        LOGE("Failed to open setting_file: %s\n", setting_file);// TODO errno
        return -1;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    rewind(f);

    buf = (char*) malloc(len + 1);
    if (NULL == buf) {
        LOGE("Failed to malloc for task_setting: %s\n", strerror(errno));
        return -1;
    }

    len = fread(buf, 1, len, f);
    buf[len] = '\0';

    JSONNODE* setting = json_parse(buf);

    master->num_plugins = json_size(setting);
    master->plugins = (ls_plugin_t*)malloc(master->num_plugins * sizeof(ls_plugin_t));

    ls_plugin_t* plugin;
    size_t plugin_index = 0;
    char plugin_path[128];
    for (JSONNODE_ITERATOR i = json_begin(setting); i != json_end(setting); ++i, ++plugin_index) {
        plugin = master->plugins + plugin_index;
        plugin->plugin_index = plugin_index;

        json_char* plugin_name = json_name(*i);
        if (NULL == plugin_name) {
            LOGE("Failed to get plugin_name from task_setting\n");
            return -1;
        }

        snprintf(plugin_path, sizeof(plugin_path), "plugin/%s/%s.so", plugin_name, plugin_name);

        if (uv_dlopen(plugin_path, &plugin->plugin_lib) < 0) {
            LOGE("  Failed to uv_dlopen: %s\n", uv_dlerror(&plugin->plugin_lib));
            return -1;
        }

        if (uv_dlsym(&(plugin->plugin_lib), "plugin_declare", (void**)&(plugin->plugin_declare)) < 0) {
            LOGE("  Failed to uv_dlsym\n");
            return -1;
        }

        if ((plugin->plugin_declare(plugin) < 0)) {
            LOGE("  Failed to plugin_declare\n");
            return -1;
        }

        JSONNODE* settings = *i;
        // if (plugin->master_init != NULL && (plugin->master_init)(master, settings) < 0)
        if (plugin->plugin_init != NULL && (plugin->plugin_init)(settings) < 0) {
            LOGE("ERROR failed to plugin_init()\n");
            return -1;
        }
    }

    // TODO json_free
    return 0;
}
コード例 #16
0
ファイル: libuv.c プロジェクト: paroga/libwebsockets
LWS_VISIBLE int
lws_plat_plugins_init(struct lws_context * context, const char * const *d)
{
	struct lws_plugin_capability lcaps;
	struct lws_plugin *plugin;
	lws_plugin_init_func initfunc;
	int m, ret = 0;
	void *v;
	uv_dirent_t dent;
	uv_fs_t req;
	char path[256];
	uv_loop_t loop;
	uv_lib_t lib;

	lib.errmsg = NULL;
	lib.handle = NULL;

	uv_loop_init(&loop);

	lwsl_notice("  Plugins:\n");

	while (d && *d) {

		lwsl_notice("  Scanning %s\n", *d);
		m =uv_fs_scandir(&loop, &req, *d, 0, NULL);
		if (m < 1) {
			lwsl_err("Scandir on %s failed\n", *d);
			return 1;
		}

		while (uv_fs_scandir_next(&req, &dent) != UV_EOF) {
			if (strlen(dent.name) < 7)
				continue;

			lwsl_notice("   %s\n", dent.name);

			lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d, dent.name);
			if (uv_dlopen(path, &lib)) {
				uv_dlerror(&lib);
				lwsl_err("Error loading DSO: %s\n", lib.errmsg);
				goto bail;
			}
			/* we could open it, can we get his init function? */
#if !defined(WIN32)
			m = lws_snprintf(path, sizeof(path) - 1, "init_%s",
				     dent.name + 3 /* snip lib... */);
			path[m - 3] = '\0'; /* snip the .so */
#else
			m = lws_snprintf(path, sizeof(path) - 1, "init_%s",
				     dent.name);
			path[m - 4] = '\0'; /* snip the .dll */
#endif
			if (uv_dlsym(&lib, path, &v)) {
				uv_dlerror(&lib);
				lwsl_err("Failed to get init on %s: %s",
						dent.name, lib.errmsg);
				goto bail;
			}
			initfunc = (lws_plugin_init_func)v;
			lcaps.api_magic = LWS_PLUGIN_API_MAGIC;
			m = initfunc(context, &lcaps);
			if (m) {
				lwsl_err("Initializing %s failed %d\n", dent.name, m);
				goto skip;
			}

			plugin = lws_malloc(sizeof(*plugin));
			if (!plugin) {
				lwsl_err("OOM\n");
				goto bail;
			}
			plugin->list = context->plugin_list;
			context->plugin_list = plugin;
			strncpy(plugin->name, dent.name, sizeof(plugin->name) - 1);
			plugin->name[sizeof(plugin->name) - 1] = '\0';
			plugin->lib = lib;
			plugin->caps = lcaps;
			context->plugin_protocol_count += lcaps.count_protocols;
			context->plugin_extension_count += lcaps.count_extensions;

			continue;

skip:
			uv_dlclose(&lib);
		}
bail:
		uv_fs_req_cleanup(&req);
		d++;
	}

	uv_loop_close(&loop);

	return ret;

}
コード例 #17
0
ファイル: dlload.c プロジェクト: certik/julia
uv_lib_t *jl_load_dynamic_library(char *fname)
{
    int error;
    char *modname, *ext;
    char path[PATHBUF];
    int i;
    uv_lib_t *handle=malloc(sizeof(uv_lib_t));
    handle->errmsg=NULL;

    modname = fname;
    if (modname == NULL) {
#if defined(__WIN32__)
		if(!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
          (LPCSTR)(&jl_load_dynamic_library),
          &handle->handle))
			    jl_errorf("could not load base module", fname);
#else
        handle->handle = dlopen(NULL,RTLD_NOW);
#endif
        goto done;
    }
#if defined(__WIN32__)
	else if (modname[1] == ':') {
#else
    else if (modname[0] == '/') {
#endif
        error = uv_dlopen(modname,handle);
        if (!error) goto done;
    }
    char *cwd;

    for(i=0; i < N_EXTENSIONS; i++) {
        ext = extensions[i];
        path[0] = '\0';
        handle->handle = NULL;
        if (modname[0] != '/') {
            if (julia_home) {
                /* try julia_home/../lib */
                strncpy(path, julia_home, PATHBUF-1);
                strncat(path, "/../lib/", PATHBUF-1-strlen(path));
                strncat(path, modname, PATHBUF-1-strlen(path));
                strncat(path, ext, PATHBUF-1-strlen(path));
                error = uv_dlopen(path, handle);
                if (!error) goto done;
                // if file exists but didn't load, show error details
                struct stat sbuf;
                if (stat(path, &sbuf) != -1) {
					JL_PRINTF(JL_STDERR, "could not load module %s (%d): %s\n", fname, error, uv_dlerror(handle));
                    jl_errorf("could not load module %s", fname);
                }
            }
            cwd = getcwd(path, PATHBUF);
            if (cwd != NULL) {
                /* next try load from current directory */
                strncat(path, "/", PATHBUF-1-strlen(path));
                strncat(path, modname, PATHBUF-1-strlen(path));
                strncat(path, ext, PATHBUF-1-strlen(path));
                error = uv_dlopen(path, handle);
                if (!error) goto done;
            }
        }
        /* try loading from standard library path */
        strncpy(path, modname, PATHBUF-1);
        strncat(path, ext, PATHBUF-1-strlen(path));
        error = uv_dlopen(path, handle);
        if (!error) goto done;
    }

    JL_PRINTF(JL_STDERR, "could not load module %s (%d): %s\n", fname, error, uv_dlerror(handle));
    jl_errorf("could not load module %s", fname);
    free(handle);
    return NULL;
done:
    return handle;
}

void *jl_dlsym_e(uv_lib_t *handle, char *symbol) {
    void *ptr;
    int  error=uv_dlsym(handle, symbol, &ptr);
    if(error) ptr=NULL;
    return ptr;
}
コード例 #18
0
ファイル: dlload.c プロジェクト: GordStephen/julia
static uv_lib_t *jl_load_dynamic_library_(const char *modname, unsigned flags, int throw_err)
{
    int error;
    char *ext;
    char path[PATHBUF];
    int i;
    uv_stat_t stbuf;
    uv_lib_t *handle = (uv_lib_t*)malloc(sizeof(uv_lib_t));
    handle->errmsg = NULL;

    /*
        this branch returns handle of libjulia
    */
    if (modname == NULL) {
#ifdef _OS_WINDOWS_
        if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                                (LPCWSTR)(&jl_load_dynamic_library),
                                &handle->handle)) {
            free(handle);
            jl_error("could not load base module");
        }
#else
        handle->handle = dlopen(NULL,RTLD_NOW);
#endif
        goto done;
    }
    /*
        this branch shortcuts absolute paths
    */
#ifdef _OS_WINDOWS_
    else if (modname[1] == ':') {
#else
    else if (modname[0] == '/') {
#endif
        error = jl_uv_dlopen(modname,handle,flags);
        if (!error)
            goto done;
        // bail out and show the error if file actually exists
        if (jl_stat(modname, (char*)&stbuf) == 0)
            goto notfound;
        if (handle->errmsg)
            uv_dlclose(handle);
    }
    /*
        this branch permutes all base paths in DL_LOAD_PATH with all extensions
        note: skip when !jl_base_module to avoid UndefVarError(:DL_LOAD_PATH)
    */
    else if (jl_base_module != NULL) {
        jl_array_t *DL_LOAD_PATH = (jl_array_t*)jl_get_global(jl_base_module, jl_symbol("DL_LOAD_PATH"));
        if (DL_LOAD_PATH != NULL) {
            size_t j;
            for (j = 0; j < jl_array_len(DL_LOAD_PATH); j++) {
                char *dl_path = jl_string_data(jl_cell_data(DL_LOAD_PATH)[j]);
                size_t len = strlen(dl_path);
                if (len == 0)
                    continue;
                for(i=0; i < N_EXTENSIONS; i++) {
                    ext = extensions[i];
                    path[0] = '\0';
                    handle->handle = NULL;
                    if (dl_path[len-1] == PATHSEPSTRING[0])
                        snprintf(path, PATHBUF, "%s%s%s", dl_path, modname, ext);
                    else
                        snprintf(path, PATHBUF, "%s" PATHSEPSTRING "%s%s", dl_path, modname, ext);
                    // free handle->errmsg, else it will leak on next uv_dlopen
                    if (handle->errmsg)
                        uv_dlclose(handle);
                    error = jl_uv_dlopen(path, handle, flags);
                    if (!error)
                        goto done;
                    // bail out and show the error if file actually exists
                    if (jl_stat(path, (char*)&stbuf) == 0)
                        goto notfound;
                }
            }
        }
    }

    // now fall back and look in default library paths, for all extensions
    for(i=0; i < N_EXTENSIONS; i++) {
        ext = extensions[i];
        path[0] = '\0';
        handle->handle = NULL;
        snprintf(path, PATHBUF, "%s%s", modname, ext);
        if (handle->errmsg)
            uv_dlclose(handle);
        error = jl_uv_dlopen(path, handle, flags);
        if (!error)
            goto done;
    }

#if defined(__linux__) || defined(__FreeBSD__)
// check map of versioned libs from "libX" to full soname "libX.so.ver"
    {
        const char *soname = jl_lookup_soname(modname, strlen(modname));
        error = (soname==NULL) || jl_uv_dlopen(soname, handle, flags);
        if (!error)
            goto done;
    }
#endif

notfound:
    // copy the error message into the path buffer so we can free the lib handle
    path[0] = '\0';
    snprintf(path, PATHBUF, "%s", uv_dlerror(handle));
    uv_dlclose(handle);
    free(handle);
    if (throw_err)
        jl_errorf("could not load library '%s'\n%s", modname, path);
    return NULL;

done:
    return handle;
}

jl_uv_libhandle jl_load_dynamic_library_e(const char *modname, unsigned flags)
{
    return (jl_uv_libhandle) jl_load_dynamic_library_(modname, flags, 0);
}

jl_uv_libhandle jl_load_dynamic_library(const char *modname, unsigned flags)
{
    return (jl_uv_libhandle) jl_load_dynamic_library_(modname, flags, 1);
}

void *jl_dlsym_e(jl_uv_libhandle handle, const char *symbol)
{
    void *ptr;
    int error = uv_dlsym((uv_lib_t *) handle, symbol, &ptr);
    if (error) ptr=NULL;
    return ptr;
}