diff options
author | Thomas Lively <tlively@google.com> | 2022-10-11 11:16:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 16:16:14 +0000 |
commit | b83450ed1fd98cec4453024f57f892b31851ea50 (patch) | |
tree | bf0467d96c9966d0f4699ea0afcdf25905b4098c /src/tools/wasm-ctor-eval.cpp | |
parent | 6d4ac3162c290e32a98de349d49e26e904a40414 (diff) | |
download | binaryen-b83450ed1fd98cec4453024f57f892b31851ea50.tar.gz binaryen-b83450ed1fd98cec4453024f57f892b31851ea50.tar.bz2 binaryen-b83450ed1fd98cec4453024f57f892b31851ea50.zip |
Make `Name` a pointer, length pair (#5122)
With the goal of supporting null characters (i.e. zero bytes) in strings.
Rewrite the underlying interned `IString` to store a `std::string_view` rather
than a `const char*`, reduce the number of map lookups necessary to intern a
string, and present a more immutable interface.
Most importantly, replace the `c_str()` method that returned a `const char*`
with a `toString()` method that returns a `std::string`. This new method can
correctly handle strings containing null characters. A `const char*` can still
be had by calling `data()` on the `std::string_view`, although this usage should
be discouraged.
This change is NFC in spirit, although not in practice. It does not intend to
support any particular new functionality, but it is probably now possible to use
strings containing null characters in at least some cases. At least one parser
bug is also incidentally fixed. Follow-on PRs will explicitly support and test
strings containing nulls for particular use cases.
The C API still uses `const char*` to represent strings. As strings containing
nulls become better supported by the rest of Binaryen, this will no longer be
sufficient. Updating the C and JS APIs to use pointer, length pairs is left as
future work.
Diffstat (limited to 'src/tools/wasm-ctor-eval.cpp')
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 45cc63c37..40abe2f76 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -67,7 +67,8 @@ public: auto* global = wasm.getGlobal(curr->name); if (global->imported()) { throw FailToEvalException(std::string("read from imported global ") + - global->module.str + "." + global->base.str); + global->module.toString() + "." + + global->base.toString()); } return ModuleRunnerBase<EvallingModuleRunner>::visitGlobalGet(curr); @@ -184,13 +185,14 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { auto* globalExport = inst->wasm.getExportOrNull(global->base); if (!globalExport) { throw FailToEvalException(std::string("importGlobals: ") + - global->module.str + "." + - global->base.str); + global->module.toString() + "." + + global->base.toString()); } globals[global->name] = inst->globals[globalExport->value]; } else { throw FailToEvalException(std::string("importGlobals: ") + - global->module.str + "." + global->base.str); + global->module.toString() + "." + + global->base.toString()); } }); } @@ -255,8 +257,8 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { extra = RECOMMENDATION "consider --ignore-external-input"; } throw FailToEvalException(std::string("call import: ") + - import->module.str + "." + import->base.str + - extra); + import->module.toString() + "." + + import->base.toString() + extra); } // We assume the table is not modified FIXME @@ -318,13 +320,14 @@ struct CtorEvalExternalInterface : EvallingModuleRunner::ExternalInterface { auto* func = wasm->getFunction(targetFunc); if (func->type != sig) { throw FailToEvalException(std::string("callTable signature mismatch: ") + - targetFunc.str); + targetFunc.toString()); } if (!func->imported()) { return instance.callFunctionInternal(targetFunc, arguments); } else { throw FailToEvalException( - std::string("callTable on imported function: ") + targetFunc.str); + std::string("callTable on imported function: ") + + targetFunc.toString()); } } |