Skip to content

Instantly share code, notes, and snippets.

@WardBrian
Created May 11, 2023 18:25
Show Gist options
  • Save WardBrian/ce7bfb93fafe60fc699c6c9fe3fa06ae to your computer and use it in GitHub Desktop.
Save WardBrian/ce7bfb93fafe60fc699c6c9fe3fa06ae to your computer and use it in GitHub Desktop.
#include <stdexcept>
#include <iostream>
void maybe_throw(int should_throw) {
if (should_throw)
throw std::domain_error("exception in C++: dummy");
}
extern "C" int some_fn(int should_throw) {
try {
maybe_throw(should_throw);
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
return 0;
}
run(`g++ dummy.cpp -shared -fPIC -o dummy.so`)
dummy = Libc.Libdl.dlopen("./dummy.so")
println(ccall(Libc.Libdl.dlsym(dummy, "some_fn"), Cint, (Cint,), 0))
println(ccall(Libc.Libdl.dlsym(dummy, "some_fn"), Cint, (Cint,), 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment