History

Pull out buffered_reader.h from the VM source base and insert into the global include. Update the buffered_reader implementation to help with symbol (sbl) file parsing.

arr committed 9 years ago

Commit 3b54d821 parent 2e5c41c2 files · +62 −42Browse files

Showing the changes to src/vm/module_reader.cpp (1 of 2 files). Show all

Unified · Split

src/vm/module_reader.cpp+4−21
@@ -141,23 +141,6 @@ namespace · 140 unmodified lines
141141 return r;
142142 }
143143
144− bool read_next_string(util::buffered_reader_t &reader, std::vector<uint8_t> &char_buffer)
145− {
146− assert(char_buffer.size() == 0);
147− char_buffer.reserve(1024);
148−
149− auto success = bool{};
150− auto value = uint8_t{};
151− std::tie(success, value) = reader.get_next_byte();
152− while (success && value != 0)
153− {
154− char_buffer.push_back(value);
155− std::tie(success, value) = reader.get_next_byte();
156− }
157−
158− return success;
159− }
160−
161144 byte_t *read_8byte_segments(util::buffered_reader_t &reader, datum_type_t type, uint32_t segment_count, byte_t *dest)
162145 {
163146 assert(type == datum_type_t::value_real64 || type == datum_type_t::value_bit64);
@@ -519,7 +502,7 @@ namespace · 355 unmodified lines
519502 void read_module_name(util::buffered_reader_t &reader, vm_module_t &modobj)
520503 {
521504 auto string_buffer = std::vector<uint8_t>{};
522− if (!read_next_string(reader, string_buffer))
505+ if (!reader.get_bytes_until(0, string_buffer))
523506 throw module_reader_exception{ "Failed to read module name" };
524507
525508 modobj.module_name = std::make_unique<vm_string_t>(string_buffer.size(), string_buffer.data());
@@ -550,7 +533,7 @@ namespace · 24 unmodified lines
550533 if (!success) throw module_reader_exception{ "Failed to read linkage signature" };
551534
552535 auto string_buffer = std::vector<uint8_t>{};
553− if (!read_next_string(reader, string_buffer))
536+ if (!reader.get_bytes_until(0, string_buffer))
554537 throw module_reader_exception{ "Failed to read linkage name" };
555538
556539 item.name = std::make_unique<vm_string_t>(string_buffer.size(), string_buffer.data());
@@ -594,7 +577,7 @@ namespace · 37 unmodified lines
594577 if (!success) throw module_reader_exception{ "Failed to read import function signature" };
595578
596579 auto string_buffer = std::vector<uint8_t>{};
597− if (!read_next_string(reader, string_buffer))
580+ if (!reader.get_bytes_until(0, string_buffer))
598581 throw module_reader_exception{ "Failed to read import function name" };
599582
600583 func.name = std::make_unique<vm_string_t>(string_buffer.size(), string_buffer.data());
@@ -666,7 +649,7 @@ namespace · 65 unmodified lines
666649 exception_t except{};
667650
668651 auto string_buffer = std::vector<uint8_t>{};
669− if (!read_next_string(reader, string_buffer))
652+ if (!reader.get_bytes_until(0, string_buffer))
670653 throw module_reader_exception{ "Failed to read exception name" };
671654
672655 except.name = std::make_unique<vm_string_t>(string_buffer.size(), string_buffer.data());