Skip to content

Commit

Permalink
load_library() panics on errors when err=0
Browse files Browse the repository at this point in the history
load_library with `err=0` now panics on errors, provided that the
file is openable. It used to never panic on errors, leading to
confusion between when cases the libjuliacodegen library had been
intentionally removed and when it tried but failed to load.

Fixes JuliaLang#47027
  • Loading branch information
apaz-cli committed Oct 27, 2022
1 parent 0c382c2 commit a4cadda
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ void jl_loader_print_stderr3(const char * msg1, const char * msg2, const char *
}

/* Wrapper around dlopen(), with extra relative pathing thrown in*/
/* If err, then loads the library successfully or panics.
* If !err, then loads the library or returns null if it could not be opened,
* or panics if opening failed for any other reason. */
static void * load_library(const char * rel_path, const char * src_dir, int err) {
void * handle = NULL;

Expand All @@ -55,19 +58,21 @@ static void * load_library(const char * rel_path, const char * src_dir, int err)
strncat(path, rel_path, sizeof(path) - 1);

#if defined(_OS_WINDOWS_)
#define PATH_EXISTS() !_waccess(wpath, EACCES)
wchar_t wpath[2*JL_PATH_MAX + 1] = {0};
if (!utf8_to_wchar(path, wpath, 2*JL_PATH_MAX)) {
jl_loader_print_stderr3("ERROR: Unable to convert path ", path, " to wide string!\n");
exit(1);
}
handle = (void *)LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
#else
#define PATH_EXISTS() !access(path, R_OK)
handle = dlopen(path, RTLD_NOW | (err ? RTLD_GLOBAL : RTLD_LOCAL));
#endif

if (handle == NULL) {
if (!err)
if (!err && !PATH_EXISTS())
return NULL;
#undef PATH_EXISTS
jl_loader_print_stderr3("ERROR: Unable to load dependent library ", path, "\n");
#if defined(_OS_WINDOWS_)
LPWSTR wmsg = TEXT("");
Expand Down

0 comments on commit a4cadda

Please sign in to comment.