Skip to content

Commit

Permalink
Better error message on library loading failure
Browse files Browse the repository at this point in the history
  • Loading branch information
thierry-martinez committed Feb 26, 2021
1 parent 2be0a2f commit b6608db
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pyml_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ open_library(const char *filename)
return LoadLibrary(filename);
}

void
static char *
get_library_error()
{
return "Unable to load library";
}

static void
close_library(library_t library)
{
if (!FreeLibrary(library)) {
Expand Down Expand Up @@ -90,6 +96,12 @@ open_library(const char *filename)
return dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
}

static char *
get_library_error()
{
return dlerror();
}

void
close_library(library_t filename)
{
Expand Down Expand Up @@ -660,7 +672,7 @@ py_load_library(value filename_ocaml, value debug_build_ocaml)
const char *filename = String_val(Field(filename_ocaml, 0));
library = open_library(filename);
if (!library) {
failwith("Library not found");
failwith(get_library_error());
}
}
else {
Expand Down

0 comments on commit b6608db

Please sign in to comment.