mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Fift] Fix an issue of FunC/Tolk WASM which truncated long fif output
As it turned out, PSTRING() created a buffer of 128K. If asm_code exceeded this buffer, it was truncated. I've just dropped PSTRING() from there in favor of std::string.
This commit is contained in:
parent
ebbab54cda
commit
0bcc0b3c12
1 changed files with 12 additions and 7 deletions
|
@ -114,7 +114,7 @@ class MemoryFileLoader : public fift::FileLoader {
|
||||||
std::map<std::string, std::string, std::less<>> files_;
|
std::map<std::string, std::string, std::less<>> files_;
|
||||||
};
|
};
|
||||||
|
|
||||||
td::Result<fift::SourceLookup> create_source_lookup(std::string main, bool need_preamble = true, bool need_asm = true,
|
td::Result<fift::SourceLookup> create_source_lookup(std::string&& main, bool need_preamble = true, bool need_asm = true,
|
||||||
bool need_ton_util = true, bool need_lisp = true,
|
bool need_ton_util = true, bool need_lisp = true,
|
||||||
bool need_w3_code = true, bool need_fift_ext = true,
|
bool need_w3_code = true, bool need_fift_ext = true,
|
||||||
bool need_disasm = true, std::string dir = "") {
|
bool need_disasm = true, std::string dir = "") {
|
||||||
|
@ -189,7 +189,7 @@ td::Result<fift::SourceLookup> run_fift(fift::SourceLookup source_lookup, std::o
|
||||||
} // namespace
|
} // namespace
|
||||||
td::Result<FiftOutput> mem_run_fift(std::string source, std::vector<std::string> args, std::string fift_dir) {
|
td::Result<FiftOutput> mem_run_fift(std::string source, std::vector<std::string> args, std::string fift_dir) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
TRY_RESULT(source_lookup, create_source_lookup(source, true, true, true, true, true, true, true, fift_dir));
|
TRY_RESULT(source_lookup, create_source_lookup(std::move(source), true, true, true, true, true, true, true, fift_dir));
|
||||||
TRY_RESULT_ASSIGN(source_lookup, run_fift(std::move(source_lookup), &ss, true, std::move(args)));
|
TRY_RESULT_ASSIGN(source_lookup, run_fift(std::move(source_lookup), &ss, true, std::move(args)));
|
||||||
FiftOutput res;
|
FiftOutput res;
|
||||||
res.source_lookup = std::move(source_lookup);
|
res.source_lookup = std::move(source_lookup);
|
||||||
|
@ -207,16 +207,21 @@ td::Result<FiftOutput> mem_run_fift(SourceLookup source_lookup, std::vector<std:
|
||||||
td::Result<fift::SourceLookup> create_mem_source_lookup(std::string main, std::string fift_dir, bool need_preamble,
|
td::Result<fift::SourceLookup> create_mem_source_lookup(std::string main, std::string fift_dir, bool need_preamble,
|
||||||
bool need_asm, bool need_ton_util, bool need_lisp,
|
bool need_asm, bool need_ton_util, bool need_lisp,
|
||||||
bool need_w3_code) {
|
bool need_w3_code) {
|
||||||
return create_source_lookup(main, need_preamble, need_asm, need_ton_util, need_lisp, need_w3_code, false, false,
|
return create_source_lookup(std::move(main), need_preamble, need_asm, need_ton_util, need_lisp, need_w3_code, false, false,
|
||||||
fift_dir);
|
fift_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
td::Result<td::Ref<vm::Cell>> compile_asm(td::Slice asm_code, std::string fift_dir, bool is_raw) {
|
td::Result<td::Ref<vm::Cell>> compile_asm(td::Slice asm_code, std::string fift_dir, bool is_raw) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
TRY_RESULT(source_lookup,
|
std::string sb;
|
||||||
create_source_lookup(PSTRING() << "\"Asm.fif\" include\n " << (is_raw ? "<{" : "") << asm_code << "\n"
|
sb.reserve(asm_code.size() + 100);
|
||||||
<< (is_raw ? "}>c" : "") << " boc>B \"res\" B>file",
|
sb.append("\"Asm.fif\" include\n ");
|
||||||
true, true, true, false, false, false, false, fift_dir));
|
sb.append(is_raw ? "<{" : "");
|
||||||
|
sb.append(asm_code.data(), asm_code.size());
|
||||||
|
sb.append(is_raw ? "}>c" : "");
|
||||||
|
sb.append(" boc>B \"res\" B>file");
|
||||||
|
|
||||||
|
TRY_RESULT(source_lookup, create_source_lookup(std::move(sb), true, true, true, false, false, false, false, fift_dir));
|
||||||
TRY_RESULT(res, run_fift(std::move(source_lookup), &ss));
|
TRY_RESULT(res, run_fift(std::move(source_lookup), &ss));
|
||||||
TRY_RESULT(boc, res.read_file("res"));
|
TRY_RESULT(boc, res.read_file("res"));
|
||||||
return vm::std_boc_deserialize(std::move(boc.data));
|
return vm::std_boc_deserialize(std::move(boc.data));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue