`base/runtime`: do not free the original block on a failed heap resize
The default heap allocator freed old_ptr when the underlying allocation
failed (allocated_mem == nil). On the realloc path (heap_resize) the original
block is left intact on failure, and on the copy/fresh path old_ptr has not
been copied or freed yet, so freeing it left the caller holding a dangling
pointer. A [dynamic] array whose resize failed therefore double-freed its
data on the next delete (reported as free(): invalid pointer / use-after-free).
Return .Out_Of_Memory without freeing anything; the caller retains ownership
of the original block.
Fixes#7262
The runtime implementations of quaternion division are incorrect when
calculating q/r with nonzero jmag(r) and either nonzero imag(q) or
kmag(q). Notably, the inverse 1/r is still calculated correctly
because imag(1) = kmag(1) = 0.
The mistake can be verified by calculating (a/b)*b which will be very
different from both a and a * (1/b) * b.
The compile-time constant folding is correct, see exact_value.cpp
in function exact_binary_operator_value -> ExactValue_Quaternion ->
Token_Quo.
quo256 :: proc(q, r: quaternion256) -> quaternion256 { return q/r }
a: quaternion256 : 3 + 5i + 7j + 11k
b: quaternion256 : 2 + 7i + 3j + 5k
c: quaternion256 : a/b
fmt.println("comp", abs((c*b) - a))
fmt.println("run ", abs(quo256(a,b)*b - a))
// both values should be very close to zero;
// without fix, only the first is
* For `-o:size` and below, uses the type erased approach
* For `-o:speed` and above, the inlined form is used
This is necessary because a generic `mem_copy_non_overlapping` cannot be optimized when type erasure is used, meaning in a hot path where `append_elem` is used a lot; thus `mem_copy_non_overlapping` becomes a bottleneck.