vlib: fix mutable args
parent
34e0b164eb
commit
0bcc53c366
|
@ -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 {
|
||||
println('Could not find MSVC')
|
||||
|
||||
|
|
|
@ -37,15 +37,15 @@ fn bitget(instance BitField, bitnr int) int {
|
|||
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)
|
||||
}
|
||||
|
||||
fn bitclear(instance BitField, bitnr int) {
|
||||
fn bitclear(instance mut BitField, bitnr int) {
|
||||
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)
|
||||
}
|
||||
/*
|
||||
|
@ -65,7 +65,7 @@ fn bitnslots(length int) int {
|
|||
return (length - 1) / SLOT_SIZE + 1
|
||||
}
|
||||
|
||||
fn cleartail(instance BitField) {
|
||||
fn cleartail(instance mut BitField) {
|
||||
tail := instance.size % SLOT_SIZE
|
||||
if tail != 0 {
|
||||
// create a mask for the tail
|
||||
|
|
|
@ -62,7 +62,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst, src []byte) {
|
|||
|
||||
for src.len > 0 {
|
||||
// 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))
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
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 {
|
||||
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.
|
||||
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.
|
||||
|
|
|
@ -87,10 +87,10 @@ fn encrypt_block_generic(xk []u32, dst, src []byte) {
|
|||
s3 ^= xk[k+3]
|
||||
|
||||
_ = dst[15] // early bounds check
|
||||
binary.big_endian_put_u32(dst.left(4), s0)
|
||||
binary.big_endian_put_u32(dst.slice(4, 8), s1)
|
||||
binary.big_endian_put_u32(dst.slice(8, 12), s2)
|
||||
binary.big_endian_put_u32(dst.slice(12, 16), s3)
|
||||
binary.big_endian_put_u32(mut dst.left(4), s0)
|
||||
binary.big_endian_put_u32(mut dst.slice(4, 8), s1)
|
||||
binary.big_endian_put_u32(mut dst.slice(8, 12), s2)
|
||||
binary.big_endian_put_u32(mut dst.slice(12, 16), s3)
|
||||
}
|
||||
|
||||
// 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]
|
||||
|
||||
_ = dst[15] // early bounds check
|
||||
binary.big_endian_put_u32(dst.left(4), s0)
|
||||
binary.big_endian_put_u32(dst.slice(4, 8), s1)
|
||||
binary.big_endian_put_u32(dst.slice(8, 12), s2)
|
||||
binary.big_endian_put_u32(dst.slice(12, 16), s3)
|
||||
binary.big_endian_put_u32(mut dst.left(4), s0)
|
||||
binary.big_endian_put_u32(mut dst.slice(4, 8), s1)
|
||||
binary.big_endian_put_u32(mut dst.slice(8, 12), s2)
|
||||
binary.big_endian_put_u32(mut dst.slice(12, 16), s3)
|
||||
}
|
||||
|
||||
// Apply SBox0 to each byte in w.
|
||||
|
|
|
@ -127,14 +127,14 @@ pub fn (d mut Digest) checksum() []byte {
|
|||
// sum returns the MD5 checksum of the data.
|
||||
pub fn sum(data []byte) []byte {
|
||||
mut d := new()
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
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
|
||||
// architecture optimized versions
|
||||
block_generic(dig, p)
|
||||
block_generic(mut dig, p)
|
||||
}
|
||||
|
||||
pub fn (d &Digest) size() int { return Size }
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn new_cipher(key []byte) ?Cipher {
|
|||
//
|
||||
// Deprecated: Reset can't guarantee that the key will be entirely removed from
|
||||
// the process's memory.
|
||||
pub fn (c &Cipher) reset() {
|
||||
pub fn (c mut Cipher) reset() {
|
||||
for i in c.s {
|
||||
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.
|
||||
// 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 {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ fn test_crypto_rc4() {
|
|||
mut src := 'toencrypt'.bytes()
|
||||
|
||||
// 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()
|
||||
|
||||
|
|
|
@ -115,16 +115,16 @@ fn (d mut Digest) checksum() []byte {
|
|||
|
||||
// Length in bits.
|
||||
len <<= u64(3)
|
||||
binary.big_endian_put_u64(tmp, len)
|
||||
d.write(tmp.left(8))
|
||||
binary.big_endian_put_u64(mut tmp, len)
|
||||
d.write(mut tmp.left(8))
|
||||
|
||||
mut digest := [byte(0); Size]
|
||||
|
||||
binary.big_endian_put_u32(digest, d.h[0])
|
||||
binary.big_endian_put_u32(digest.right(4), d.h[1])
|
||||
binary.big_endian_put_u32(digest.right(8), d.h[2])
|
||||
binary.big_endian_put_u32(digest.right(12), d.h[3])
|
||||
binary.big_endian_put_u32(digest.right(16), d.h[4])
|
||||
binary.big_endian_put_u32(mut digest, d.h[0])
|
||||
binary.big_endian_put_u32(mut digest.right(4), d.h[1])
|
||||
binary.big_endian_put_u32(mut digest.right(8), d.h[2])
|
||||
binary.big_endian_put_u32(mut digest.right(12), d.h[3])
|
||||
binary.big_endian_put_u32(mut digest.right(16), d.h[4])
|
||||
|
||||
return digest
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ fn (d mut Digest) checksum() []byte {
|
|||
// Sum returns the SHA-1 checksum of the data.
|
||||
pub fn sum(data []byte) []byte {
|
||||
mut d := new()
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
return d.checksum()
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ fn (d mut Digest) write(p mut []byte) ?int {
|
|||
n := copy(d.x.right(d.nx), p)
|
||||
d.nx += n
|
||||
if d.nx == Chunk {
|
||||
block(d, d.x)
|
||||
block(mut d, d.x)
|
||||
d.nx = 0
|
||||
}
|
||||
if n >= p.len {
|
||||
|
@ -110,7 +110,7 @@ fn (d mut Digest) write(p mut []byte) ?int {
|
|||
}
|
||||
if p.len >= Chunk {
|
||||
n := p.len &~ (Chunk - 1)
|
||||
block(d, p.left(n))
|
||||
block(mut d, p.left(n))
|
||||
if n >= p.len {
|
||||
p = []byte
|
||||
} else {
|
||||
|
@ -153,7 +153,7 @@ fn (d mut Digest) checksum() []byte {
|
|||
// Length in bits.
|
||||
len <<= u64(3)
|
||||
binary.big_endian_put_u64(mut tmp, len)
|
||||
d.write(tmp.left(8))
|
||||
d.write(mut tmp.left(8))
|
||||
|
||||
if 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(24), d.h[6])
|
||||
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
|
||||
|
@ -183,24 +183,24 @@ pub fn sum(data []byte) []byte {
|
|||
// sum256 returns the SHA256 checksum of the data.
|
||||
pub fn sum256(data []byte) []byte {
|
||||
mut d := new()
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
return d.checksum()
|
||||
}
|
||||
|
||||
// sum224 returns the SHA224 checksum of the data.
|
||||
pub fn sum224(data []byte) []byte {
|
||||
mut d := new224()
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
sum := d.checksum()
|
||||
mut sum224 := [byte(0); Size224]
|
||||
copy(sum224, sum.left(Size224))
|
||||
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
|
||||
// architecture optimized versions
|
||||
block_generic(dig, p)
|
||||
block_generic(mut dig, p)
|
||||
}
|
||||
|
||||
pub fn (d &Digest) size() int {
|
||||
|
|
|
@ -146,8 +146,7 @@ fn new384() *Digest {
|
|||
return _new(crypto.Hash.SHA384)
|
||||
}
|
||||
|
||||
fn (d mut Digest) write(p_ []byte) ?int {
|
||||
mut p := p_
|
||||
fn (d mut Digest) write(p mut []byte) ?int {
|
||||
nn := p.len
|
||||
d.len += u64(nn)
|
||||
if d.nx > 0 {
|
||||
|
@ -210,9 +209,9 @@ fn (d mut Digest) checksum() []byte {
|
|||
tmp[0] = 0x80
|
||||
|
||||
if int(len)%128 < 112 {
|
||||
d.write(tmp.left(112-int(len)%128))
|
||||
d.write(mut tmp.left(112-int(len)%128))
|
||||
} else {
|
||||
d.write(tmp.left(128+112-int(len)%128))
|
||||
d.write(mut tmp.left(128+112-int(len)%128))
|
||||
}
|
||||
|
||||
// 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.right(8), len)
|
||||
d.write(tmp.left(16))
|
||||
d.write(mut tmp.left(16))
|
||||
|
||||
if 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.
|
||||
pub fn sum512(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512)
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
return d.checksum()
|
||||
}
|
||||
|
||||
// sum384 returns the SHA384 checksum of the data.
|
||||
pub fn sum384(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA384)
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
sum := d.checksum()
|
||||
mut sum384 := [byte(0); 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.
|
||||
pub fn sum512_224(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512_224)
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
sum := d.checksum()
|
||||
mut sum224 := [byte(0); 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.
|
||||
pub fn sum512_256(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512_256)
|
||||
d.write(data)
|
||||
d.write(mut data)
|
||||
sum := d.checksum()
|
||||
mut sum256 := [byte(0); Size256]
|
||||
copy(sum256, sum.left(Size256))
|
||||
|
@ -282,7 +281,7 @@ pub fn sum512_256(data []byte) []byte {
|
|||
fn block(dig mut Digest, p []byte) {
|
||||
// For now just use block_generic until we have specific
|
||||
// architecture optimized versions
|
||||
block_generic(mut dig, p)
|
||||
block_generic(mut dig, mut p)
|
||||
}
|
||||
|
||||
pub fn (d &Digest) size() int {
|
||||
|
|
|
@ -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 h0 := dig.h[0]
|
||||
|
|
|
@ -250,7 +250,7 @@ pub fn identity() Mat4 {
|
|||
}
|
||||
|
||||
// returns *f32 without allocation
|
||||
pub fn identity2(res *f32) {
|
||||
pub fn identity2(res mut *f32) {
|
||||
res[0] = 1
|
||||
res[5] = 1
|
||||
res[10] = 1
|
||||
|
|
|
@ -824,14 +824,15 @@ fn parse_query_silent(query string) Values {
|
|||
|
||||
fn _parse_query(m mut Values, query string) ?bool {
|
||||
mut had_error := false
|
||||
for query != '' {
|
||||
mut key := query
|
||||
mut q := query
|
||||
for q != '' {
|
||||
mut key := q
|
||||
mut i := key.index_any('&;')
|
||||
if i >= 0 {
|
||||
query = key.right(i+1)
|
||||
q = key.right(i+1)
|
||||
key = key.left(i)
|
||||
} else {
|
||||
query = ''
|
||||
q = ''
|
||||
}
|
||||
if key == '' {
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue