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
251 return ss;251 return ss;
252 }252 }
253 253
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)
255 {255 {
256 if (alloc == nullptr)256 if (alloc == nullptr)
257 {257 {
@@ -277,15 +277,27 @@ namespace · 19 unmodified lines
277 {277 {
278 ss << "size: " << alloc->alloc_type->size_in_bytes << " alloc";278 ss << "size: " << alloc->alloc_type->size_in_bytes << " alloc";
279 279
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)
281 {281 {
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 << "...";
283 });290 });
284 }291 }
285 292
286 return ss;293 return ss;
287 }294 }
288 295
296 std::ostream& operator<<(std::ostream &ss, const vm_alloc_t *alloc)
297 {
298 return safe_alloc_print(ss, alloc, 0);
299 }
300
289 std::ostream& operator<<(std::ostream &ss, const vm_thread_state_t s)301 std::ostream& operator<<(std::ostream &ss, const vm_thread_state_t s)
290 {302 {
291 switch (s)303 switch (s)
src/include/vm_memory.h+1−1
@@ -85,7 +85,7 @@ namespace disvm · 84 unmodified lines
85 85
86 auto offset_accum = std::size_t{ 0 };86 auto offset_accum = std::size_t{ 0 };
87 auto memory = reinterpret_cast<word_t *>(data);87 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)))
89 {89 {
90 const auto words8 = type_desc.pointer_map[i];90 const auto words8 = type_desc.pointer_map[i];
91 if (words8 != 0)91 if (words8 != 0)
src/vm/execution_table.cpp+13−13
@@ -179,7 +179,7 @@ namespace · 178 unmodified lines
179 if (arr->get_element_type() != intrinsic_type_desc::type<byte_t>())179 if (arr->get_element_type() != intrinsic_type_desc::type<byte_t>())
180 throw vm_user_exception{ "Invalid array element type for string conversion" };180 throw vm_user_exception{ "Invalid array element type for string conversion" };
181 181
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)) };
183 str = new_string->get_allocation();183 str = new_string->get_allocation();
184 }184 }
185 185
@@ -202,10 +202,10 @@ namespace · 16 unmodified lines
202 auto buffer = std::array<char, sizeof("-2147483648")>{};202 auto buffer = std::array<char, sizeof("-2147483648")>{};
203 203
204 const auto w = vt_ref<word_t>(r.src);204 const auto w = vt_ref<word_t>(r.src);
205 const auto len = std::sprintf(buffer.data(), "%d", w);205 const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%d", w));
206 assert(static_cast<std::size_t>(len) <= buffer.size());206 assert(len <= buffer.size());
207 207
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()) };
209 auto prev = at_val<vm_alloc_t>(r.dest);209 auto prev = at_val<vm_alloc_t>(r.dest);
210 dec_ref_count_and_free(prev);210 dec_ref_count_and_free(prev);
211 211
@@ -228,10 +228,10 @@ namespace · 16 unmodified lines
228 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};228 auto buffer = std::array<char, sizeof("-2.2250738585072014e-308")>{};
229 229
230 const auto real = vt_ref<real_t>(r.src);230 const auto real = vt_ref<real_t>(r.src);
231 const auto len = std::sprintf(buffer.data(), "%g", real);231 const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%g", real));
232 assert(static_cast<std::size_t>(len) <= buffer.size());232 assert(len <= buffer.size());
233 233
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()) };
235 235
236 auto prev = at_val<vm_alloc_t>(r.dest);236 auto prev = at_val<vm_alloc_t>(r.dest);
237 dec_ref_count_and_free(prev);237 dec_ref_count_and_free(prev);
@@ -255,10 +255,10 @@ namespace · 17 unmodified lines
255 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};255 auto buffer = std::array<char, sizeof("-9223372036854775808")>{};
256 256
257 const auto b = vt_ref<big_t>(r.src);257 const auto b = vt_ref<big_t>(r.src);
258 const auto len = std::sprintf(buffer.data(), "%lld", b);258 const auto len = static_cast<std::size_t>(std::sprintf(buffer.data(), "%lld", b));
259 assert(static_cast<std::size_t>(len) <= buffer.size());259 assert(len <= buffer.size());
260 260
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()) };
262 262
263 auto prev = at_val<vm_alloc_t>(r.dest);263 auto prev = at_val<vm_alloc_t>(r.dest);
264 dec_ref_count_and_free(prev);264 dec_ref_count_and_free(prev);
@@ -762,11 +762,11 @@ namespace · 497 unmodified lines
762 if (try_append_to_s1)762 if (try_append_to_s1)
763 return nullptr;763 return nullptr;
764 764
765 return new vm_string_t(*s1, 0, s1->get_length());765 return new vm_string_t{ *s1, 0, s1->get_length() };
766 }766 }
767 767
768 if (!try_append_to_s1)768 if (!try_append_to_s1)
769 return new vm_string_t(*s1, *s2);769 return new vm_string_t{ *s1, *s2 };
770 770
771 s1->append(*s2);771 s1->append(*s2);
772 return nullptr;772 return nullptr;
@@ -805,7 +805,7 @@ namespace · 32 unmodified lines
805 805
806 if (str != nullptr)806 if (str != nullptr)
807 {807 {
808 auto new_string = new vm_string_t(*str, start, end);808 auto new_string = new vm_string_t{ *str, start, end };
809 pt_ref(r.dest) = new_string->get_allocation();809 pt_ref(r.dest) = new_string->get_allocation();
810 }810 }
811 else if (start == 0 && end == 0)811 else if (start == 0 && end == 0)
src/vm/module_reader.cpp+1−1
@@ -431,7 +431,7 @@ namespace · 430 unmodified lines
431 if (str_bytes != count)431 if (str_bytes != count)
432 throw module_reader_exception{ "Failed to read string data" };432 throw module_reader_exception{ "Failed to read string data" };
433 433
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() };
435 *reinterpret_cast<pointer_t *>(data_dest) = new_string->get_allocation();435 *reinterpret_cast<pointer_t *>(data_dest) = new_string->get_allocation();
436 break;436 break;
437 }437 }
src/vm/string.cpp+2−2
@@ -397,7 +397,7 @@ word_t vm_string_t::get_length() const · 396 unmodified lines
397 397
398runtime::rune_t vm_string_t::get_rune(word_t index) const398runtime::rune_t vm_string_t::get_rune(word_t index) const
399{399{
400 if (index < 0 && _length <= index)400 if (index < 0 || _length <= index)
401 throw index_out_of_range_memory{ 0, _length - 1, index };401 throw index_out_of_range_memory{ 0, _length - 1, index };
402 402
403 // Determine if local or allocated memory403 // 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
423 throw invalid_utf8{};423 throw invalid_utf8{};
424 424
425 // Index equal to length is allowed to grow the string425 // Index equal to length is allowed to grow the string
426 if (index < 0 && _length <= index)426 if (index < 0 || _length < index)
427 throw index_out_of_range_memory{ 0, _length, index };427 throw index_out_of_range_memory{ 0, _length, index };
428 428
429 // Determine if local or allocated memory429 // Determine if local or allocated memory