History

Bug in debugger when printing a vm_alloc Bug in vm_string - get_rune/set_rune Update all instantiations of vm_string to use {} - fixed issues

arr committed 9 years ago

Commit bd1f4931 parent 57e9d245 files · +32 −20Browse files

Unified · Split

5 files
  1. src/exec/debugger.cpp +15 −3
  2. src/include/vm_memory.h +1 −1
  3. src/vm/execution_table.cpp +13 −13
  4. src/vm/module_reader.cpp +1 −1
  5. src/vm/string.cpp +2 −2
src/exec/debugger.cpp+15−3
@@ -251,7 +251,7 @@ namespace · 250 unmodified lines
251251 return ss;
252252 }
253253
254− std::ostream& operator<<(std::ostream &ss, const vm_alloc_t *alloc)
254+ std::ostream& safe_alloc_print(std::ostream &ss, const vm_alloc_t *alloc, int recurse_depth)
255255 {
256256 if (alloc == nullptr)
257257 {
@@ -277,15 +277,27 @@ namespace · 19 unmodified lines
277277 {
278278 ss << "size: " << alloc->alloc_type->size_in_bytes << " alloc";
279279
280− enum_pointer_fields(*alloc->alloc_type, alloc->get_allocation(), [&ss](pointer_t p, std::size_t o)
280+ enum_pointer_fields(*alloc->alloc_type, alloc->get_allocation(), [&ss, recurse_depth](pointer_t p, std::size_t o)
281281 {
282− ss << "\n [" << o << "] " << vm_alloc_t::from_allocation(p);
282+ ss << "\n";
283+ std::fill_n(std::ostream_iterator<std::ostream::char_type>{ ss }, 4 * recurse_depth, ' ');
284+ ss << "[" << o << "] ";
285+
286+ if (recurse_depth < 2)
287+ safe_alloc_print(ss, vm_alloc_t::from_allocation(p), recurse_depth + 1);
288+ else
289+ ss << "...";
283290 });
284291 }
285292
286293 return ss;
287294 }
288295
296+ std::ostream& operator<<(std::ostream &ss, const vm_alloc_t *alloc)
297+ {
298+ return safe_alloc_print(ss, alloc, 0);
299+ }
300+
289301 std::ostream& operator<<(std::ostream &ss, const vm_thread_state_t s)
290302 {
291303 switch (s)
src/include/vm_memory.h+1−1
@@ -85,7 +85,7 @@ namespace disvm · 84 unmodified lines
8585
8686 auto offset_accum = std::size_t{ 0 };
8787 auto memory = reinterpret_cast<word_t *>(data);
88− for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += 8)
88+ for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += (8 * sizeof(pointer_t)))
8989 {
9090 const auto words8 = type_desc.pointer_map[i];
9191 if (words8 != 0)
src/vm/execution_table.cpp+13−13
@@ -179,7 +179,7 @@ namespace · 178 unmodified lines
179179 if (arr->get_element_type() != intrinsic_type_desc::type<byte_t>())
180180 throw vm_user_exception{ "Invalid array element type for string conversion" };
181181
182− auto new_string = new vm_string_t(arr->get_length(), reinterpret_cast<uint8_t *>(arr->at(0)));
182+ auto new_string = new vm_string_t{ static_cast<std::size_t>(arr->get_length()), reinterpret_cast<uint8_t *>(arr->at(0)) };
183183 str = new_string->get_allocation();
184184 }
185185
@@ -202,10 +202,10 @@ namespace · 16 unmodified lines
202202 auto buffer = std::array<char, sizeof("-2147483648")>{};
203203
204204 const auto w = vt_ref<word_t>(r.src);
205− const auto len = std::sprintf(buffer.data(), "%d", w);
206− assert(static_cast<std::size_t>(len) <= buffer.size());
205+ const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%d", w));
206+ assert(len <= buffer.size());
207207
208− auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
208+ auto new_string = new vm_string_t{ len, reinterpret_cast<uint8_t *>(buffer.data()) };
209209 auto prev = at_val<vm_alloc_t>(r.dest);
210210 dec_ref_count_and_free(prev);
211211
@@ -228,10 +228,10 @@ namespace · 16 unmodified lines
228228 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};
229229
230230 const auto real = vt_ref<real_t>(r.src);
231− const auto len = std::sprintf(buffer.data(), "%g", real);
232− assert(static_cast<std::size_t>(len) <= buffer.size());
231+ const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%g", real));
232+ assert(len <= buffer.size());
233233
234− auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
234+ auto new_string = new vm_string_t{ len, reinterpret_cast<uint8_t *>(buffer.data()) };
235235
236236 auto prev = at_val<vm_alloc_t>(r.dest);
237237 dec_ref_count_and_free(prev);
@@ -255,10 +255,10 @@ namespace · 17 unmodified lines
255255 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};
256256
257257 const auto b = vt_ref<big_t>(r.src);
258− const auto len = std::sprintf(buffer.data(), "%lld", b);
259− assert(static_cast<std::size_t>(len) <= buffer.size());
258+ const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%lld", b));
259+ assert(len <= buffer.size());
260260
261− auto new_string = new vm_string_t(len, reinterpret_cast<uint8_t *>(buffer.data()));
261+ auto new_string = new vm_string_t{ len, reinterpret_cast<uint8_t *>(buffer.data()) };
262262
263263 auto prev = at_val<vm_alloc_t>(r.dest);
264264 dec_ref_count_and_free(prev);
@@ -762,11 +762,11 @@ namespace · 497 unmodified lines
762762 if (try_append_to_s1)
763763 return nullptr;
764764
765− return new vm_string_t(*s1, 0, s1->get_length());
765+ return new vm_string_t{ *s1, 0, s1->get_length() };
766766 }
767767
768768 if (!try_append_to_s1)
769− return new vm_string_t(*s1, *s2);
769+ return new vm_string_t{ *s1, *s2 };
770770
771771 s1->append(*s2);
772772 return nullptr;
@@ -805,7 +805,7 @@ namespace · 32 unmodified lines
805805
806806 if (str != nullptr)
807807 {
808− auto new_string = new vm_string_t(*str, start, end);
808+ auto new_string = new vm_string_t{ *str, start, end };
809809 pt_ref(r.dest) = new_string->get_allocation();
810810 }
811811 else if (start == 0 && end == 0)
src/vm/module_reader.cpp+1−1
@@ -431,7 +431,7 @@ namespace · 430 unmodified lines
431431 if (str_bytes != count)
432432 throw module_reader_exception{ "Failed to read string data" };
433433
434− auto new_string = new vm_string_t(str_buffer.size(), str_buffer.data());
434+ auto new_string = new vm_string_t{ str_buffer.size(), str_buffer.data() };
435435 *reinterpret_cast<pointer_t *>(data_dest) = new_string->get_allocation();
436436 break;
437437 }
src/vm/string.cpp+2−2
@@ -397,7 +397,7 @@ word_t vm_string_t::get_length() const · 396 unmodified lines
397397
398398 runtime::rune_t vm_string_t::get_rune(word_t index) const
399399 {
400− if (index < 0 && _length <= index)
400+ if (index < 0 || _length <= index)
401401 throw index_out_of_range_memory{ 0, _length - 1, index };
402402
403403 // Determine if local or allocated memory
@@ -423,7 +423,7 @@ void vm_string_t::set_rune(word_t index, rune_t value) · 19 unmodified lines
423423 throw invalid_utf8{};
424424
425425 // Index equal to length is allowed to grow the string
426− if (index < 0 && _length <= index)
426+ if (index < 0 || _length < index)
427427 throw index_out_of_range_memory{ 0, _length, index };
428428
429429 // Determine if local or allocated memory