Use string_view for trap and hostLimit (#8153)
Followup to
https://github.com/WebAssembly/binaryen/pull/8086#discussion_r2620918735
diff --git a/src/shell-interface.h b/src/shell-interface.h
index 7a42617..03b4c81 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -325,16 +325,15 @@
return true;
}
- void trap(const char* why) override {
+ void trap(std::string_view why) override {
std::cout << "[trap " << why << "]\n";
throw TrapException();
}
- void hostLimit(const char* why) override {
+ void hostLimit(std::string_view why) override {
std::cout << "[host limit " << why << "]\n";
throw HostLimitException();
}
-
void throwException(const WasmException& exn) override { throw exn; }
};
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index b33fb5a..455c247 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -451,12 +451,12 @@
throw FailToEvalException("grow table");
}
- void trap(const char* why) override {
- throw FailToEvalException(std::string("trap: ") + why);
+ void trap(std::string_view why) override {
+ throw FailToEvalException(std::string("trap: ") + std::string(why));
}
- void hostLimit(const char* why) override {
- throw FailToEvalException(std::string("trap: ") + why);
+ void hostLimit(std::string_view why) override {
+ throw FailToEvalException(std::string("trap: ") + std::string(why));
}
void throwException(const WasmException& exn) override {
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 3dad278..d46dde4 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -86,7 +86,7 @@
}
Literals values;
- Name breakTo; // if non-null, a break is going on
+ Name breakTo; // if non-null, a break is going on
Tag* suspendTag = nullptr; // if non-null, breakTo must be SUSPEND_FLOW, and
// this is the tag being suspended
@@ -2694,9 +2694,9 @@
return makeGCData(std::move(contents), curr->type);
}
- virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); }
+ virtual void trap(std::string_view why) { WASM_UNREACHABLE("unimp"); }
- virtual void hostLimit(const char* why) { WASM_UNREACHABLE("unimp"); }
+ virtual void hostLimit(std::string_view why) { WASM_UNREACHABLE("unimp"); }
virtual void throwException(const WasmException& exn) {
WASM_UNREACHABLE("unimp");
@@ -2929,9 +2929,11 @@
Flow visitResumeThrow(ResumeThrow* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStackSwitch(StackSwitch* curr) { return Flow(NONCONSTANT_FLOW); }
- void trap(const char* why) override { throw NonconstantException(); }
+ void trap(std::string_view why) override { throw NonconstantException(); }
- void hostLimit(const char* why) override { throw NonconstantException(); }
+ void hostLimit(std::string_view why) override {
+ throw NonconstantException();
+ }
virtual void throwException(const WasmException& exn) override {
throw NonconstantException();
@@ -2974,8 +2976,8 @@
const Literal& value,
Index oldSize,
Index newSize) = 0;
- virtual void trap(const char* why) = 0;
- virtual void hostLimit(const char* why) = 0;
+ virtual void trap(std::string_view why) = 0;
+ virtual void hostLimit(std::string_view why) = 0;
virtual void throwException(const WasmException& exn) = 0;
// Get the Tag instance for a tag implemented in the host, that is, not
// among the linked ModuleRunner instances, but imported from the host.
@@ -4741,13 +4743,13 @@
Flow visitResumeThrow(ResumeThrow* curr) { return doResume(curr); }
Flow visitStackSwitch(StackSwitch* curr) { return Flow(NONCONSTANT_FLOW); }
- void trap(const char* why) override {
+ void trap(std::string_view why) override {
// Traps break all current continuations - they will never be resumable.
self()->clearContinuationStore();
externalInterface->trap(why);
}
- void hostLimit(const char* why) override {
+ void hostLimit(std::string_view why) override {
self()->clearContinuationStore();
externalInterface->hostLimit(why);
}