vlib: fix mutable args

pull/1502/head^2
joe-conigliaro 2019-08-07 17:53:33 +10:00 committed by Alexander Medvednikov
parent 34e0b164eb
commit 0bcc53c366
13 changed files with 54 additions and 54 deletions

View File

@ -196,7 +196,7 @@ fn find_msvc() ?MsvcResult {
} }
} }
pub fn cc_msvc(v *V) { pub fn cc_msvc(v mut V) {
r := find_msvc() or { r := find_msvc() or {
println('Could not find MSVC') println('Could not find MSVC')

View File

@ -37,15 +37,15 @@ fn bitget(instance BitField, bitnr int) int {
return (instance.field[bitslot(bitnr)] >> u32(bitnr % SLOT_SIZE)) & 1 return (instance.field[bitslot(bitnr)] >> u32(bitnr % SLOT_SIZE)) & 1
} }
fn bitset(instance BitField, bitnr int) { fn bitset(instance mut BitField, bitnr int) {
instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] | bitmask(bitnr) instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] | bitmask(bitnr)
} }
fn bitclear(instance BitField, bitnr int) { fn bitclear(instance mut BitField, bitnr int) {
instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] & ~bitmask(bitnr) instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] & ~bitmask(bitnr)
} }
fn bittoggle(instance BitField, bitnr int) { fn bittoggle(instance mut BitField, bitnr int) {
instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] ^ bitmask(bitnr) instance.field[bitslot(bitnr)] = instance.field[bitslot(bitnr)] ^ bitmask(bitnr)
} }
/* /*
@ -65,7 +65,7 @@ fn bitnslots(length int) int {
return (length - 1) / SLOT_SIZE + 1 return (length - 1) / SLOT_SIZE + 1
} }
fn cleartail(instance BitField) { fn cleartail(instance mut BitField) {
tail := instance.size % SLOT_SIZE tail := instance.size % SLOT_SIZE
if tail != 0 { if tail != 0 {
// create a mask for the tail // create a mask for the tail

View File

@ -62,7 +62,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst, src []byte) {
for src.len > 0 { for src.len > 0 {
// Write the xor to dst, then encrypt in place. // Write the xor to dst, then encrypt in place.
cipher.xor_bytes(dst.left(x.block_size), src.left(x.block_size), iv) cipher.xor_bytes(mut dst.left(x.block_size), src.left(x.block_size), iv)
x.b.encrypt(dst.left(x.block_size), dst.left(x.block_size)) x.b.encrypt(dst.left(x.block_size), dst.left(x.block_size))
// Move to the next block with this block as the next iv. // Move to the next block with this block as the next iv.
@ -79,7 +79,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst, src []byte) {
copy(x.iv, iv) copy(x.iv, iv)
} }
pub fn (x &AesCbc) decrypt_blocks(dst, src []byte) { pub fn (x &AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
if src.len%x.block_size != 0 { if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks') panic('crypto.cipher: input not full blocks')
} }
@ -114,7 +114,7 @@ pub fn (x &AesCbc) decrypt_blocks(dst, src []byte) {
// The first block is special because it uses the saved iv. // The first block is special because it uses the saved iv.
x.b.decrypt(dst.slice(start, end), src.slice(start, end)) x.b.decrypt(dst.slice(start, end), src.slice(start, end))
cipher.xor_bytes(dst.slice(start, end), dst.slice(start, end), x.iv) cipher.xor_bytes(mut dst.slice(start, end), dst.slice(start, end), x.iv)
// Set the new iv to the first block we copied earlier. // Set the new iv to the first block we copied earlier.

View File

@ -87,10 +87,10 @@ fn encrypt_block_generic(xk []u32, dst, src []byte) {
s3 ^= xk[k+3] s3 ^= xk[k+3]
_ = dst[15] // early bounds check _ = dst[15] // early bounds check
binary.big_endian_put_u32(dst.left(4), s0) binary.big_endian_put_u32(mut dst.left(4), s0)
binary.big_endian_put_u32(dst.slice(4, 8), s1) binary.big_endian_put_u32(mut dst.slice(4, 8), s1)
binary.big_endian_put_u32(dst.slice(8, 12), s2) binary.big_endian_put_u32(mut dst.slice(8, 12), s2)
binary.big_endian_put_u32(dst.slice(12, 16), s3) binary.big_endian_put_u32(mut dst.slice(12, 16), s3)
} }
// Decrypt one block from src into dst, using the expanded key xk. // Decrypt one block from src into dst, using the expanded key xk.
@ -141,10 +141,10 @@ fn decrypt_block_generic(xk []u32, dst, src []byte) {
s3 ^= xk[k+3] s3 ^= xk[k+3]
_ = dst[15] // early bounds check _ = dst[15] // early bounds check
binary.big_endian_put_u32(dst.left(4), s0) binary.big_endian_put_u32(mut dst.left(4), s0)
binary.big_endian_put_u32(dst.slice(4, 8), s1) binary.big_endian_put_u32(mut dst.slice(4, 8), s1)
binary.big_endian_put_u32(dst.slice(8, 12), s2) binary.big_endian_put_u32(mut dst.slice(8, 12), s2)
binary.big_endian_put_u32(dst.slice(12, 16), s3) binary.big_endian_put_u32(mut dst.slice(12, 16), s3)
} }
// Apply SBox0 to each byte in w. // Apply SBox0 to each byte in w.

View File

@ -127,14 +127,14 @@ pub fn (d mut Digest) checksum() []byte {
// sum returns the MD5 checksum of the data. // sum returns the MD5 checksum of the data.
pub fn sum(data []byte) []byte { pub fn sum(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) d.write(mut data)
return d.checksum() return d.checksum()
} }
fn block(dig &Digest, p []byte) { fn block(dig mut Digest, p []byte) {
// For now just use block_generic until we have specific // For now just use block_generic until we have specific
// architecture optimized versions // architecture optimized versions
block_generic(dig, p) block_generic(mut dig, p)
} }
pub fn (d &Digest) size() int { return Size } pub fn (d &Digest) size() int { return Size }

View File

@ -49,7 +49,7 @@ pub fn new_cipher(key []byte) ?Cipher {
// //
// Deprecated: Reset can't guarantee that the key will be entirely removed from // Deprecated: Reset can't guarantee that the key will be entirely removed from
// the process's memory. // the process's memory.
pub fn (c &Cipher) reset() { pub fn (c mut Cipher) reset() {
for i in c.s { for i in c.s {
c.s[i] = u32(0) c.s[i] = u32(0)
} }
@ -59,7 +59,7 @@ pub fn (c &Cipher) reset() {
// xor_key_stream sets dst to the result of XORing src with the key stream. // xor_key_stream sets dst to the result of XORing src with the key stream.
// Dst and src must overlap entirely or not at all. // Dst and src must overlap entirely or not at all.
pub fn (c &Cipher) xor_key_stream(dst, src []byte) { pub fn (c mut Cipher) xor_key_stream(dst mut []byte, src []byte) {
if src.len == 0 { if src.len == 0 {
return return
} }

View File

@ -15,7 +15,7 @@ fn test_crypto_rc4() {
mut src := 'toencrypt'.bytes() mut src := 'toencrypt'.bytes()
// src & dst same, encrypt in place // src & dst same, encrypt in place
c.xor_key_stream(src, src) // encrypt data c.xor_key_stream(mut src, src) // encrypt data
c.reset() c.reset()

View File

@ -115,16 +115,16 @@ fn (d mut Digest) checksum() []byte {
// Length in bits. // Length in bits.
len <<= u64(3) len <<= u64(3)
binary.big_endian_put_u64(tmp, len) binary.big_endian_put_u64(mut tmp, len)
d.write(tmp.left(8)) d.write(mut tmp.left(8))
mut digest := [byte(0); Size] mut digest := [byte(0); Size]
binary.big_endian_put_u32(digest, d.h[0]) binary.big_endian_put_u32(mut digest, d.h[0])
binary.big_endian_put_u32(digest.right(4), d.h[1]) binary.big_endian_put_u32(mut digest.right(4), d.h[1])
binary.big_endian_put_u32(digest.right(8), d.h[2]) binary.big_endian_put_u32(mut digest.right(8), d.h[2])
binary.big_endian_put_u32(digest.right(12), d.h[3]) binary.big_endian_put_u32(mut digest.right(12), d.h[3])
binary.big_endian_put_u32(digest.right(16), d.h[4]) binary.big_endian_put_u32(mut digest.right(16), d.h[4])
return digest return digest
} }
@ -132,7 +132,7 @@ fn (d mut Digest) checksum() []byte {
// Sum returns the SHA-1 checksum of the data. // Sum returns the SHA-1 checksum of the data.
pub fn sum(data []byte) []byte { pub fn sum(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) d.write(mut data)
return d.checksum() return d.checksum()
} }

View File

@ -99,7 +99,7 @@ fn (d mut Digest) write(p mut []byte) ?int {
n := copy(d.x.right(d.nx), p) n := copy(d.x.right(d.nx), p)
d.nx += n d.nx += n
if d.nx == Chunk { if d.nx == Chunk {
block(d, d.x) block(mut d, d.x)
d.nx = 0 d.nx = 0
} }
if n >= p.len { if n >= p.len {
@ -110,7 +110,7 @@ fn (d mut Digest) write(p mut []byte) ?int {
} }
if p.len >= Chunk { if p.len >= Chunk {
n := p.len &~ (Chunk - 1) n := p.len &~ (Chunk - 1)
block(d, p.left(n)) block(mut d, p.left(n))
if n >= p.len { if n >= p.len {
p = []byte p = []byte
} else { } else {
@ -153,7 +153,7 @@ fn (d mut Digest) checksum() []byte {
// Length in bits. // Length in bits.
len <<= u64(3) len <<= u64(3)
binary.big_endian_put_u64(mut tmp, len) binary.big_endian_put_u64(mut tmp, len)
d.write(tmp.left(8)) d.write(mut tmp.left(8))
if d.nx != 0 { if d.nx != 0 {
panic('d.nx != 0') panic('d.nx != 0')
@ -169,7 +169,7 @@ fn (d mut Digest) checksum() []byte {
binary.big_endian_put_u32(mut digest.right(20), d.h[5]) binary.big_endian_put_u32(mut digest.right(20), d.h[5])
binary.big_endian_put_u32(mut digest.right(24), d.h[6]) binary.big_endian_put_u32(mut digest.right(24), d.h[6])
if !d.is224 { if !d.is224 {
binary.big_endian_put_u32(digest.right(28), d.h[7]) binary.big_endian_put_u32(mut digest.right(28), d.h[7])
} }
return digest return digest
@ -183,24 +183,24 @@ pub fn sum(data []byte) []byte {
// sum256 returns the SHA256 checksum of the data. // sum256 returns the SHA256 checksum of the data.
pub fn sum256(data []byte) []byte { pub fn sum256(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) d.write(mut data)
return d.checksum() return d.checksum()
} }
// sum224 returns the SHA224 checksum of the data. // sum224 returns the SHA224 checksum of the data.
pub fn sum224(data []byte) []byte { pub fn sum224(data []byte) []byte {
mut d := new224() mut d := new224()
d.write(data) d.write(mut data)
sum := d.checksum() sum := d.checksum()
mut sum224 := [byte(0); Size224] mut sum224 := [byte(0); Size224]
copy(sum224, sum.left(Size224)) copy(sum224, sum.left(Size224))
return sum224 return sum224
} }
fn block(dig &Digest, p []byte) { fn block(dig mut Digest, p []byte) {
// For now just use block_generic until we have specific // For now just use block_generic until we have specific
// architecture optimized versions // architecture optimized versions
block_generic(dig, p) block_generic(mut dig, p)
} }
pub fn (d &Digest) size() int { pub fn (d &Digest) size() int {

View File

@ -146,8 +146,7 @@ fn new384() *Digest {
return _new(crypto.Hash.SHA384) return _new(crypto.Hash.SHA384)
} }
fn (d mut Digest) write(p_ []byte) ?int { fn (d mut Digest) write(p mut []byte) ?int {
mut p := p_
nn := p.len nn := p.len
d.len += u64(nn) d.len += u64(nn)
if d.nx > 0 { if d.nx > 0 {
@ -210,9 +209,9 @@ fn (d mut Digest) checksum() []byte {
tmp[0] = 0x80 tmp[0] = 0x80
if int(len)%128 < 112 { if int(len)%128 < 112 {
d.write(tmp.left(112-int(len)%128)) d.write(mut tmp.left(112-int(len)%128))
} else { } else {
d.write(tmp.left(128+112-int(len)%128)) d.write(mut tmp.left(128+112-int(len)%128))
} }
// Length in bits. // Length in bits.
@ -220,7 +219,7 @@ fn (d mut Digest) checksum() []byte {
binary.big_endian_put_u64(mut tmp, u64(0)) // upper 64 bits are always zero, because len variable has type u64 binary.big_endian_put_u64(mut tmp, u64(0)) // upper 64 bits are always zero, because len variable has type u64
binary.big_endian_put_u64(mut tmp.right(8), len) binary.big_endian_put_u64(mut tmp.right(8), len)
d.write(tmp.left(16)) d.write(mut tmp.left(16))
if d.nx != 0 { if d.nx != 0 {
panic('d.nx != 0') panic('d.nx != 0')
@ -245,14 +244,14 @@ fn (d mut Digest) checksum() []byte {
// sum512 returns the SHA512 checksum of the data. // sum512 returns the SHA512 checksum of the data.
pub fn sum512(data []byte) []byte { pub fn sum512(data []byte) []byte {
mut d := _new(crypto.Hash.SHA512) mut d := _new(crypto.Hash.SHA512)
d.write(data) d.write(mut data)
return d.checksum() return d.checksum()
} }
// sum384 returns the SHA384 checksum of the data. // sum384 returns the SHA384 checksum of the data.
pub fn sum384(data []byte) []byte { pub fn sum384(data []byte) []byte {
mut d := _new(crypto.Hash.SHA384) mut d := _new(crypto.Hash.SHA384)
d.write(data) d.write(mut data)
sum := d.checksum() sum := d.checksum()
mut sum384 := [byte(0); Size384] mut sum384 := [byte(0); Size384]
copy(sum384, sum.left(Size384)) copy(sum384, sum.left(Size384))
@ -262,7 +261,7 @@ pub fn sum384(data []byte) []byte {
// sum512_224 returns the Sum512/224 checksum of the data. // sum512_224 returns the Sum512/224 checksum of the data.
pub fn sum512_224(data []byte) []byte { pub fn sum512_224(data []byte) []byte {
mut d := _new(crypto.Hash.SHA512_224) mut d := _new(crypto.Hash.SHA512_224)
d.write(data) d.write(mut data)
sum := d.checksum() sum := d.checksum()
mut sum224 := [byte(0); Size224] mut sum224 := [byte(0); Size224]
copy(sum224, sum.left(Size224)) copy(sum224, sum.left(Size224))
@ -272,7 +271,7 @@ pub fn sum512_224(data []byte) []byte {
// Sum512_256 returns the Sum512/256 checksum of the data. // Sum512_256 returns the Sum512/256 checksum of the data.
pub fn sum512_256(data []byte) []byte { pub fn sum512_256(data []byte) []byte {
mut d := _new(crypto.Hash.SHA512_256) mut d := _new(crypto.Hash.SHA512_256)
d.write(data) d.write(mut data)
sum := d.checksum() sum := d.checksum()
mut sum256 := [byte(0); Size256] mut sum256 := [byte(0); Size256]
copy(sum256, sum.left(Size256)) copy(sum256, sum.left(Size256))
@ -282,7 +281,7 @@ pub fn sum512_256(data []byte) []byte {
fn block(dig mut Digest, p []byte) { fn block(dig mut Digest, p []byte) {
// For now just use block_generic until we have specific // For now just use block_generic until we have specific
// architecture optimized versions // architecture optimized versions
block_generic(mut dig, p) block_generic(mut dig, mut p)
} }
pub fn (d &Digest) size() int { pub fn (d &Digest) size() int {

View File

@ -94,7 +94,7 @@ const(
] ]
) )
fn block_generic(dig mut Digest, p []byte) { fn block_generic(dig mut Digest, p mut []byte) {
mut w := [u64(0); 80] mut w := [u64(0); 80]
mut h0 := dig.h[0] mut h0 := dig.h[0]

View File

@ -250,7 +250,7 @@ pub fn identity() Mat4 {
} }
// returns *f32 without allocation // returns *f32 without allocation
pub fn identity2(res *f32) { pub fn identity2(res mut *f32) {
res[0] = 1 res[0] = 1
res[5] = 1 res[5] = 1
res[10] = 1 res[10] = 1

View File

@ -824,14 +824,15 @@ fn parse_query_silent(query string) Values {
fn _parse_query(m mut Values, query string) ?bool { fn _parse_query(m mut Values, query string) ?bool {
mut had_error := false mut had_error := false
for query != '' { mut q := query
mut key := query for q != '' {
mut key := q
mut i := key.index_any('&;') mut i := key.index_any('&;')
if i >= 0 { if i >= 0 {
query = key.right(i+1) q = key.right(i+1)
key = key.left(i) key = key.left(i)
} else { } else {
query = '' q = ''
} }
if key == '' { if key == '' {
continue continue