Created
May 11, 2023 18:25
-
-
Save WardBrian/ce7bfb93fafe60fc699c6c9fe3fa06ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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