Commit 9e1ed8ab authored by Kevin Modzelewski's avatar Kevin Modzelewski

Properly throw ImportErrors on dlopen failure

I think it'd be nicer to just abort() like we do here, but
cffi is actually testing this behavior (that loading an invalid
library causes an ImportError).

This is being exposed now because before, the library would fail
to compile due to -Werror=implicit-function-declaration and not even
get to the loading step.
parent c5aa72ac
......@@ -138,23 +138,16 @@ extern "C" Box* import(int level, Box* from_imports, llvm::StringRef module_name
BoxedModule* importCExtension(BoxedString* full_name, const std::string& last_name, const std::string& path) {
void* handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
const char* s = dlerror();
// raiseExcHelper(ImportError, "%s", dlerror());
fprintf(stderr, "%s\n", s);
exit(1);
}
if (!handle)
raiseExcHelper(ImportError, "%s", dlerror());
assert(handle);
std::string initname = "init" + last_name;
void (*init)() = (void (*)())dlsym(handle, initname.c_str());
char* error;
if ((error = dlerror()) != NULL) {
// raiseExcHelper(ImportError, "%s", error);
fprintf(stderr, "%s\n", error);
exit(1);
}
if ((error = dlerror()) != NULL)
raiseExcHelper(ImportError, "%s", error);
assert(init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment