History

Address more bugs found during limbo compiler testing

arr committed 9 years ago

Commit 84ac3311 parent 220aaf26 files · +52 −63Browse files

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

Unified · Split

src/vm/array.cpp+5−8
@@ -43,16 +43,14 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t lengt · 42 unmodified lines
43 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d", array_len);43 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d", array_len);
44}44}
45 45
46vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length)46vm_array_t::vm_array_t(vm_array_t &original, word_t begin_index, word_t length)
47 : vm_alloc_t(vm_array_t::type_desc())47 : vm_alloc_t(vm_array_t::type_desc())
48 , _arr{ nullptr }48 , _arr{ nullptr }
49 , _element_type{ original->get_element_type() }49 , _element_type{ original.get_element_type() }
50 , _length{ length }50 , _length{ length }
51 , _original{ original }51 , _original{ &original }
52{52{
53 assert(_original != nullptr);53 assert(0 <= begin_index && (begin_index < _original->get_length() || (begin_index == _original->get_length() && length == 0)));
54 assert(0 <= begin_index && begin_index < _original->get_length());
55 assert(_length >= 0 && (_length + begin_index) <= _original->get_length());
56 54
57 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())55 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
58 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length);56 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length);
@@ -164,7 +162,6 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 105 unmodified lines
164 {162 {
165 // [PERF] There is a chance this copy is within the same array, therefore163 // [PERF] There is a chance this copy is within the same array, therefore
166 // a check could be made to not ref count memory that is going to be moved.164 // a check could be made to not ref count memory that is going to be moved.
167 // The Inferno implementation of slicela handles this case (libinterp/xec.c).
168 const auto &type_desc = *_element_type;165 const auto &type_desc = *_element_type;
169 auto source_array_element = source._arr;166 auto source_array_element = source._arr;
170 auto dest_array_element = dest_arr;167 auto dest_array_element = dest_arr;
@@ -173,7 +170,7 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 2 unmodified lines
173 inc_ref_count_in_memory(type_desc, source_array_element);170 inc_ref_count_in_memory(type_desc, source_array_element);
174 source_array_element += type_desc.size_in_bytes;171 source_array_element += type_desc.size_in_bytes;
175 172
176 destroy_memory(type_desc, dest_array_element);173 dec_ref_count_in_memory(type_desc, dest_array_element);
177 dest_array_element += type_desc.size_in_bytes;174 dest_array_element += type_desc.size_in_bytes;
178 }175 }
179 }176 }