Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 2, 2013
2 parents 42d0954 + ada6eb9 commit cf01a16
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
19 changes: 19 additions & 0 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,22 @@ sigatomic_begin() = ccall(:jl_sigatomic_begin, Void, ())
sigatomic_end() = ccall(:jl_sigatomic_end, Void, ())
disable_sigint(f::Function) = try sigatomic_begin(); f(); finally sigatomic_end(); end
reenable_sigint(f::Function) = try sigatomic_end(); f(); finally sigatomic_begin(); end

function find_library{T<:ByteString, S<:ByteString}(libnames::Array{T,1}, extrapaths::Array{S,1}=ASCIIString[])
for lib in libnames
for path in extrapaths
l = joinpath(path, lib)
p = dlopen_e(l, RTLD_LAZY)
if p != C_NULL
dlclose(p)
return l
end
end
p = dlopen_e(lib, RTLD_LAZY)
if p != C_NULL
dlclose(p)
return lib
end
end
return ""
end
1 change: 1 addition & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ function init_load_path()
abspath(JULIA_HOME,"..","local","share","julia","site",vers),
abspath(JULIA_HOME,"..","share","julia","site",vers)
]
global const DL_LOAD_PATH = ByteString[]
end

function init_sched()
Expand Down
2 changes: 2 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export
ARGS,
C_NULL,
CPU_CORES,
DL_LOAD_PATH,
OS_NAME,
ENDIAN_BOM,
ENV,
Expand Down Expand Up @@ -1204,6 +1205,7 @@ export
dlsym,
dlsym_e,
errno,
find_library,
pointer,
pointer_to_array,
cfunction,
Expand Down
12 changes: 10 additions & 2 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export CPU_CORES,
uptime,
loadavg,
free_memory,
total_memory
total_memory,
shlib_ext

import ..Base: WORD_SIZE, OS_NAME, ARCH, MACHINE, UV_error_t
import ..Base: show, repl_show
Expand Down Expand Up @@ -128,6 +129,13 @@ end
free_memory() = ccall(:uv_get_free_memory, Uint64, ())
total_memory() = ccall(:uv_get_total_memory, Uint64, ())


if OS_NAME === :Darwin
const shlib_ext = "dylib"
elseif OS_NAME === :Windows
const shlib_ext = "dll"
else
#assume OS_NAME === :Linux, or similar
const shlib_ext = "so"
end

end
5 changes: 3 additions & 2 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ extern "C" const char *jl_lookup_soname(char *pfx, size_t n)
// map from user-specified lib names to handles
static std::map<std::string, void*> libMap;

int add_library_mapping(char *lib, void *hnd)
extern "C" int add_library_mapping(char *lib, void *hnd)
{
JL_PUTS((char*)"WARNING: add_library_mapping is deprecated, use push!(DL_LOAD_PATH,\"/path/to/search\") instead.\n", JL_STDERR);
if (libMap[lib] == NULL && hnd != NULL) {
libMap[lib] = hnd;
return 0;
Expand All @@ -74,7 +75,7 @@ static void *add_library_sym(char *name, char *lib)
if (hnd == NULL) {
hnd = jl_load_dynamic_library(lib, JL_RTLD_DEFAULT);
if (hnd != NULL)
libMap[lib] = hnd;
libMap[lib] = hnd;
else
return NULL;
}
Expand Down
33 changes: 27 additions & 6 deletions src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ char *jl_lookup_soname(char *pfx, size_t n);

#define JL_RTLD(flags, FLAG) (flags & JL_RTLD_ ## FLAG ? RTLD_ ## FLAG : 0)

int jl_uv_dlopen(const char* filename, uv_lib_t* lib, unsigned flags)
static int jl_uv_dlopen(const char* filename, uv_lib_t* lib, unsigned flags)
{
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
needsSymRefreshModuleList = 1;
Expand Down Expand Up @@ -76,7 +76,7 @@ int jl_uv_dlopen(const char* filename, uv_lib_t* lib, unsigned flags)
#endif
}

uv_lib_t *jl_load_dynamic_library_(char *modname, unsigned flags, int throw_err)
static uv_lib_t *jl_load_dynamic_library_(char *modname, unsigned flags, int throw_err)
{
int error;
char *ext;
Expand All @@ -103,15 +103,36 @@ uv_lib_t *jl_load_dynamic_library_(char *modname, unsigned flags, int throw_err)
#endif
error = jl_uv_dlopen(modname,handle,flags);
if (!error) goto done;
} else {
jl_array_t* DL_LOAD_PATH = (jl_array_t*)jl_get_global(jl_main_module, jl_symbol("DL_LOAD_PATH"));
if (DL_LOAD_PATH != NULL) {
size_t i;
for (i = 0; i < jl_array_len(DL_LOAD_PATH); i++) {
char *dl_path = jl_string_data(jl_cell_data(DL_LOAD_PATH)[i]);
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] == '/')
snprintf(path, PATHBUF, "%s%s%s", dl_path, modname, ext);
else
snprintf(path, PATHBUF, "%s/%s%s", dl_path, modname, ext);
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);
error = jl_uv_dlopen(path, handle,flags);
error = jl_uv_dlopen(path, handle, flags);
if (!error) goto done;
}
#if defined(__linux__)
Expand Down Expand Up @@ -141,15 +162,15 @@ uv_lib_t *jl_load_dynamic_library(char *modname, unsigned flags)
return jl_load_dynamic_library_(modname, flags, 1);
}

void *jl_dlsym_e(uv_lib_t *handle, char *symbol)
DLLEXPORT 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;
}

void *jl_dlsym(uv_lib_t *handle, char *symbol)
DLLEXPORT void *jl_dlsym(uv_lib_t *handle, char *symbol)
{
void *ptr;
int error = uv_dlsym(handle, symbol, &ptr);
Expand Down

0 comments on commit cf01a16

Please sign in to comment.