libutil: remove exception handling workingness check

within lix itself this problem is caught by the test suite. outside of
lix itself three cases can be had: either the problem is fully inside
lix libs, fully inside user code, or it exists at the boundary. the
first is caught by the test suite, the second isn't caught at all, and
the third is something lix should not be responsible for.

Change-Id: I95aa35d8cb6f0ef5816a2941c467bc0c15916063
This commit is contained in:
eldritch horrors 2024-03-17 23:52:11 +01:00
parent 4050245faa
commit d9a83886f9
5 changed files with 0 additions and 33 deletions

View file

@ -402,8 +402,6 @@ void assertLibStoreInitialized() {
void initLibStore() { void initLibStore() {
initLibUtil();
if (sodium_init() == -1) if (sodium_init() == -1)
throw Error("could not initialise libsodium"); throw Error("could not initialise libsodium");

View file

@ -15,11 +15,6 @@ void BaseError::addTrace(std::shared_ptr<Pos> && e, HintFmt hint)
err.traces.push_front(Trace { .pos = std::move(e), .hint = hint }); err.traces.push_front(Trace { .pos = std::move(e), .hint = hint });
} }
void throwExceptionSelfCheck(){
// This is meant to be caught in initLibUtil()
throw SysError("C++ exception handling is broken. This would appear to be a problem with the way Nix was compiled and/or linked and/or loaded.");
}
// c++ std::exception descendants must have a 'const char* what()' function. // c++ std::exception descendants must have a 'const char* what()' function.
// This stringifies the error and caches it for use by what(), or similarly by msg(). // This stringifies the error and caches it for use by what(), or similarly by msg().
const std::string & BaseError::calcWhat() const const std::string & BaseError::calcWhat() const

View file

@ -200,8 +200,4 @@ public:
} }
}; };
/** Throw an exception for the purpose of checking that exception handling works; see 'initLibUtil()'.
*/
void throwExceptionSelfCheck();
} }

View file

@ -52,26 +52,6 @@ extern char * * environ __attribute__((weak));
namespace nix { namespace nix {
void initLibUtil() {
// Check that exception handling works. Exception handling has been observed
// not to work on darwin when the linker flags aren't quite right.
// In this case we don't want to expose the user to some unrelated uncaught
// exception, but rather tell them exactly that exception handling is
// broken.
// When exception handling fails, the message tends to be printed by the
// C++ runtime, followed by an abort.
// For example on macOS we might see an error such as
// libc++abi: terminating with uncaught exception of type nix::SysError: error: C++ exception handling is broken. This would appear to be a problem with the way Nix was compiled and/or linked and/or loaded.
bool caught = false;
try {
throwExceptionSelfCheck();
} catch (const nix::Error & _e) {
caught = true;
}
// This is not actually the main point of this check, but let's make sure anyway:
assert(caught);
}
std::optional<std::string> getEnv(const std::string & key) std::optional<std::string> getEnv(const std::string & key)
{ {
char * value = getenv(key.c_str()); char * value = getenv(key.c_str());

View file

@ -33,8 +33,6 @@ namespace nix {
struct Sink; struct Sink;
struct Source; struct Source;
void initLibUtil();
/** /**
* The system for which Nix is compiled. * The system for which Nix is compiled.
*/ */