From fb97c2e01ed847e4f62f0e58625976a079fe3651 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 23 Apr 2020 12:19:04 +0300 Subject: [PATCH] examples: fix path_tracing.v compilation, using (*ptr) = expression --- examples/game_of_life/modules/automaton/automaton.v | 2 +- examples/path_tracing.v | 8 ++++---- vlib/crypto/aes/aes_cbc.v | 2 +- vlib/crypto/rc4/rc4.v | 4 +--- vlib/hash/wyhash/rand.v | 9 +++------ vlib/hash/wyhash/wyhash_test.v | 7 ++----- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/examples/game_of_life/modules/automaton/automaton.v b/examples/game_of_life/modules/automaton/automaton.v index af3fc88e37..458b996b1b 100644 --- a/examples/game_of_life/modules/automaton/automaton.v +++ b/examples/game_of_life/modules/automaton/automaton.v @@ -12,7 +12,7 @@ pub mut: unsafe { mut e := &int(0) e = a.data + y*a.maxx + x - *e = newval + (*e) = newval } } [inline] pub fn (a &A2D) get(x,y int) int { diff --git a/examples/path_tracing.v b/examples/path_tracing.v index 31916b06cb..ff43249e2f 100644 --- a/examples/path_tracing.v +++ b/examples/path_tracing.v @@ -101,7 +101,7 @@ fn new_image(w int, h int) Image { // write out a .ppm file fn (image Image) save_as_ppm(file_name string) { npixels := image.width * image.height - mut f_out := os.create(file_name) or { exit } + mut f_out := os.create(file_name) or { panic(err) } f_out.writeln('P3') f_out.writeln('${image.width} ${image.height}') f_out.writeln('255') @@ -247,8 +247,8 @@ const( struct Cache { mut: - sin_tab [cache_len]f64 - cos_tab [cache_len]f64 + sin_tab [65536]f64 + cos_tab [65536]f64 } fn new_tabs() Cache { @@ -429,7 +429,7 @@ fn ray_trace(w int, h int, samps int, file_name string, scene_id int) Image { r = r + radiance(Ray{cam.o+d.mult_s(140.0), d.norm()}, 0, scene_id).mult_s(samps1) } tmp_vec := Vec{clamp(r.x),clamp(r.y),clamp(r.z)}.mult_s(.25) - *ivec = *ivec + tmp_vec + (*ivec) = *ivec + tmp_vec } } } diff --git a/vlib/crypto/aes/aes_cbc.v b/vlib/crypto/aes/aes_cbc.v index 1781364dce..cbaa7f8538 100644 --- a/vlib/crypto/aes/aes_cbc.v +++ b/vlib/crypto/aes/aes_cbc.v @@ -74,7 +74,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) { } else { src = src[x.block_size..] } - *dst = dst[x.block_size..] + (*dst) = dst[x.block_size..] } // Save the iv for the next crypt_blocks call. diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 5ff4f90c53..e818889f41 100644 --- a/vlib/crypto/rc4/rc4.v +++ b/vlib/crypto/rc4/rc4.v @@ -63,13 +63,11 @@ pub fn (c mut Cipher) xor_key_stream(dst mut []byte, src []byte) { if src.len == 0 { return } - if subtle.inexact_overlap(dst[..src.len], src) { + if subtle.inexact_overlap(dst, src) { panic('crypto.rc4: invalid buffer overlap') } mut i := c.i mut j := c.j - _ = dst[src.len-1] - *dst = dst[..src.len] // eliminate bounds check from loop for k, v in src { i += byte(1) x := c.s[i] diff --git a/vlib/hash/wyhash/rand.v b/vlib/hash/wyhash/rand.v index e6069de3dc..38a675d939 100644 --- a/vlib/hash/wyhash/rand.v +++ b/vlib/hash/wyhash/rand.v @@ -4,15 +4,12 @@ module wyhash pub fn rand_u64(seed &u64) u64 { - // QTODO - /* mut seed0 := seed unsafe{ mut seed1 := *seed0 - seed1+=wyp0 - *seed0 = seed1 + seed1 += (wyp0) + (*seed0) = seed1 return wymum(seed1^wyp1, seed1) - } - */ + } return 0 } diff --git a/vlib/hash/wyhash/wyhash_test.v b/vlib/hash/wyhash/wyhash_test.v index d85ea17f8e..f7b55a483d 100644 --- a/vlib/hash/wyhash/wyhash_test.v +++ b/vlib/hash/wyhash/wyhash_test.v @@ -28,9 +28,7 @@ fn test_wyhash() { } } -fn test_rand_u64() { - // QTODO - /* +fn test_rand_u64() { seed := u64(111) mut rand_nos := []u64 for _ in 0..40 { @@ -39,7 +37,6 @@ fn test_rand_u64() { assert rand_no != r } rand_nos << rand_no - } - */ + } assert true }