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
4343 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d", array_len);
4444 }
4545
46−vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length)
46+vm_array_t::vm_array_t(vm_array_t &original, word_t begin_index, word_t length)
4747 : vm_alloc_t(vm_array_t::type_desc())
4848 , _arr{ nullptr }
49− , _element_type{ original->get_element_type() }
49+ , _element_type{ original.get_element_type() }
5050 , _length{ length }
51− , _original{ original }
51+ , _original{ &original }
5252 {
53− assert(_original != nullptr);
54− assert(0 <= begin_index && begin_index < _original->get_length());
55− assert(_length >= 0 && (_length + begin_index) <= _original->get_length());
53+ assert(0 <= begin_index && (begin_index < _original->get_length() || (begin_index == _original->get_length() && length == 0)));
5654
5755 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
5856 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
164162 {
165163 // [PERF] There is a chance this copy is within the same array, therefore
166164 // 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).
168165 const auto &type_desc = *_element_type;
169166 auto source_array_element = source._arr;
170167 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
173170 inc_ref_count_in_memory(type_desc, source_array_element);
174171 source_array_element += type_desc.size_in_bytes;
175172
176− destroy_memory(type_desc, dest_array_element);
173+ dec_ref_count_in_memory(type_desc, dest_array_element);
177174 dest_array_element += type_desc.size_in_bytes;
178175 }
179176 }