Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix_option_heap_var
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 16, 2025
2 parents fe470df + f9106a8 commit 3d78718
Show file tree
Hide file tree
Showing 31 changed files with 73 additions and 404 deletions.
22 changes: 10 additions & 12 deletions vlib/builtin/builtin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,19 @@ pub fn println(s string) {

@[manualfree]
fn _writeln_to_fd(fd int, s string) {
$if !builtin_writeln_should_write_at_once ? {
$if builtin_writeln_should_write_at_once ? {
unsafe {
buf_len := s.len + 1 // space for \n
mut buf := malloc(buf_len)
C.memcpy(buf, s.str, s.len)
buf[s.len] = `\n`
_write_buf_to_fd(fd, buf, buf_len)
free(buf)
}
} $else {
lf := u8(`\n`)
_write_buf_to_fd(fd, s.str, s.len)
_write_buf_to_fd(fd, &lf, 1)
return
}
unsafe {
buf_len := s.len + 1 // space for \n
mut buf := malloc(buf_len)
defer {
free(buf)
}
C.memcpy(buf, s.str, s.len)
buf[s.len] = `\n`
_write_buf_to_fd(fd, buf, buf_len)
}
}

Expand Down
15 changes: 0 additions & 15 deletions vlib/builtin/js/string.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,6 @@ fn (s string) index_last_(p string) int {
return -1
}

// index_last returns the position of the first character of the *last* occurrence of the `needle` string in `s`.
@[deprecated: 'use `.last_index(needle string)` instead']
pub fn (s string) index_last(needle string) ?int {
return s.last_index(needle)
}

// last_index returns the position of the first character of the *last* occurrence of the `needle` string in `s`.
@[inline]
pub fn (s string) last_index(needle string) ?int {
Expand All @@ -805,15 +799,6 @@ pub fn (s string) last_index(needle string) ?int {
return idx
}

// index_u8_last returns the index of the *last* occurrence of the byte `c` (if found) in the string.
// It returns -1, if `c` is not found.
@[deprecated: 'use `.last_index_u8(c u8)` instead']
@[deprecated_after: '2024-06-30']
@[inline]
pub fn (s string) index_u8_last(c u8) int {
return s.last_index_u8(c)
}

// last_index_u8 returns the index of the last occurrence of byte `c` if it was found in the string.
@[direct_array_access]
pub fn (s string) last_index_u8(c u8) int {
Expand Down
16 changes: 0 additions & 16 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -1249,13 +1249,6 @@ pub fn (s string) index(p string) ?int {
return idx
}

// index_last returns the position of the first character of the *last* occurrence of the `needle` string in `s`.
@[deprecated: 'use `.last_index(needle string)` instead']
@[deprecated_after: '2024-03-27']
pub fn (s string) index_last(needle string) ?int {
return s.last_index(needle)
}

// last_index returns the position of the first character of the *last* occurrence of the `needle` string in `s`.
@[inline]
pub fn (s string) last_index(needle string) ?int {
Expand Down Expand Up @@ -1386,15 +1379,6 @@ pub fn (s string) index_u8(c u8) int {
return -1
}

// index_u8_last returns the index of the *last* occurrence of the byte `c` (if found) in the string.
// It returns -1, if `c` is not found.
@[deprecated: 'use `.last_index_u8(c u8)` instead']
@[deprecated_after: '2024-06-30']
@[inline]
pub fn (s string) index_u8_last(c u8) int {
return s.last_index_u8(c)
}

// last_index_u8 returns the index of the last occurrence of byte `c` if it was found in the string.
@[direct_array_access; inline]
pub fn (s string) last_index_u8(c u8) int {
Expand Down
4 changes: 1 addition & 3 deletions vlib/builtin/utf8.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
}
} $else {
mut sb := strings.new_builder(len)
defer {
unsafe { sb.free() }
}
for i := 0; i < len; i++ {
u := unsafe { rune(_wstr[i]) }
sb.write_rune(u)
}
res := sb.str()
unsafe { sb.free() }
return res
}
}
Expand Down
17 changes: 4 additions & 13 deletions vlib/crypto/md5/md5.v
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,16 @@ pub fn (mut d Digest) write(p_ []u8) !int {
pub fn (d &Digest) sum(b_in []u8) []u8 {
// Make a copy of d so that caller can keep writing and summing.
mut d0 := d.clone()
hash := d0.checksum_internal()
hash := d0.checksum()
mut b_out := b_in.clone()
for b in hash {
b_out << b
}
return b_out
}

// TODO:
// When the deprecated "checksum()" is finally removed, restore this function name as: "checksum()"
fn (mut d Digest) checksum_internal() []u8 {
// checksum returns the byte checksum of the `Digest`,
fn (mut d Digest) checksum() []u8 {
// Append 0x80 to the end of the message and then append zeros
// until the length is a multiple of 56 bytes. Finally append
// 8 bytes representing the message length in bits.
Expand All @@ -143,19 +142,11 @@ fn (mut d Digest) checksum_internal() []u8 {
return digest
}

// checksum returns the byte checksum of the `Digest`,
// it is an internal method and is not recommended because its results are not idempotent.
@[deprecated: 'checksum() will be changed to a private method, use sum() instead']
@[deprecated_after: '2024-04-30']
pub fn (mut d Digest) checksum() []u8 {
return d.checksum_internal()
}

// sum returns the MD5 checksum of the data.
pub fn sum(data []u8) []u8 {
mut d := new()
d.write(data) or { panic(err) }
return d.checksum_internal()
return d.checksum()
}

fn block(mut dig Digest, p []u8) {
Expand Down
7 changes: 0 additions & 7 deletions vlib/crypto/pem/pem.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ const pem_end = '\n-----END '
const pem_eol = '-----'
const colon = ':'

// new returns a new `Block` with the specified block_type
@[deprecated: 'use Block.new instead']
@[inline]
pub fn new(block_type string) Block {
return Block.new(block_type)
}

@[params]
pub struct EncodeConfig {
pub mut:
Expand Down
17 changes: 4 additions & 13 deletions vlib/crypto/sha1/sha1.v
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,16 @@ pub fn (mut d Digest) write(p_ []u8) !int {
pub fn (d &Digest) sum(b_in []u8) []u8 {
// Make a copy of d so that caller can keep writing and summing.
mut d0 := d.clone()
hash := d0.checksum_internal()
hash := d0.checksum()
mut b_out := b_in.clone()
for b in hash {
b_out << b
}
return b_out
}

// TODO:
// When the deprecated "checksum()" is finally removed, restore this function name as: "checksum()"
fn (mut d Digest) checksum_internal() []u8 {
// checksum returns the current byte checksum of the `Digest`,
fn (mut d Digest) checksum() []u8 {
mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
mut tmp := []u8{len: (64)}
Expand All @@ -148,19 +147,11 @@ fn (mut d Digest) checksum_internal() []u8 {
return digest
}

// checksum returns the current byte checksum of the `Digest`,
// it is an internal method and is not recommended because its results are not idempotent.
@[deprecated: 'checksum() will be changed to a private method, use sum() instead']
@[deprecated_after: '2024-04-30']
pub fn (mut d Digest) checksum() []u8 {
return d.checksum_internal()
}

// sum returns the SHA-1 checksum of the bytes passed in `data`.
pub fn sum(data []u8) []u8 {
mut d := new()
d.write(data) or { panic(err) }
return d.checksum_internal()
return d.checksum()
}

fn block(mut dig Digest, p []u8) {
Expand Down
26 changes: 6 additions & 20 deletions vlib/crypto/sha256/sha256.v
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn (mut d Digest) write(p_ []u8) !int {
pub fn (d &Digest) sum(b_in []u8) []u8 {
// Make a copy of d so that caller can keep writing and summing.
mut d0 := d.clone()
hash := d0.checksum_internal()
hash := d0.checksum()
mut b_out := b_in.clone()
if d0.is224 {
for b in hash[..size224] {
Expand All @@ -163,9 +163,9 @@ pub fn (d &Digest) sum(b_in []u8) []u8 {
return b_out
}

// TODO:
// When the deprecated "checksum()" is finally removed, restore this function name as: "checksum()"
fn (mut d Digest) checksum_internal() []u8 {
// checksum returns the current byte checksum of the Digest,
// it is an internal method and is not recommended because its results are not idempotent.
fn (mut d Digest) checksum() []u8 {
mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
mut tmp := []u8{len: (64)}
Expand Down Expand Up @@ -196,20 +196,6 @@ fn (mut d Digest) checksum_internal() []u8 {
return digest
}

// checksum returns the current byte checksum of the Digest,
// it is an internal method and is not recommended because its results are not idempotent.
@[deprecated: 'checksum() will be changed to a private method, use sum() instead']
@[deprecated_after: '2024-04-30']
pub fn (mut d Digest) checksum() []u8 {
out := d.checksum_internal()
// if this digest has `size224` length, return the correct `size224` checksum
if d.is224 {
return out[0..size224]
}
// otherwise, returns a normal size
return out
}

// sum returns the SHA256 checksum of the bytes in `data`.
// Example: assert sha256.sum('V'.bytes()).len > 0 == true
pub fn sum(data []u8) []u8 {
Expand All @@ -220,14 +206,14 @@ pub fn sum(data []u8) []u8 {
pub fn sum256(data []u8) []u8 {
mut d := new()
d.write(data) or { panic(err) }
return d.checksum_internal()
return d.checksum()
}

// sum224 returns the SHA224 checksum of the data.
pub fn sum224(data []u8) []u8 {
mut d := new224()
d.write(data) or { panic(err) }
sum := d.checksum_internal()
sum := d.checksum()
mut sum224 := []u8{len: size224}
copy(mut sum224, sum[..size224])
return sum224
Expand Down
38 changes: 8 additions & 30 deletions vlib/crypto/sha512/sha512.v
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn (mut d Digest) write(p_ []u8) !int {
pub fn (d &Digest) sum(b_in []u8) []u8 {
// Make a copy of d so that caller can keep writing and summing.
mut d0 := d.clone()
hash := d0.checksum_internal()
hash := d0.checksum()
mut b_out := b_in.clone()
match d0.function {
.sha384 {
Expand All @@ -235,9 +235,9 @@ pub fn (d &Digest) sum(b_in []u8) []u8 {
return b_out
}

// TODO:
// When the deprecated "checksum()" is finally removed, restore this function name as: "checksum()"
fn (mut d Digest) checksum_internal() []u8 {
// checksum returns the current byte checksum of the Digest,
// it is an internal method and is not recommended because its results are not idempotent.
fn (mut d Digest) checksum() []u8 {
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
mut len := d.len
mut tmp := []u8{len: (128)}
Expand Down Expand Up @@ -269,40 +269,18 @@ fn (mut d Digest) checksum_internal() []u8 {
return digest
}

// checksum returns the current byte checksum of the Digest,
// it is an internal method and is not recommended because its results are not idempotent.
@[deprecated: 'checksum() will be changed to a private method, use sum() instead']
@[deprecated_after: '2024-04-30']
pub fn (mut d Digest) checksum() []u8 {
out := d.checksum_internal()
match d.function {
.sha384 {
return out[0..size384]
}
.sha512_224 {
return out[0..size224]
}
.sha512_256 {
return out[0..size256]
}
else {
return out
}
}
}

// sum512 returns the SHA512 checksum of the data.
pub fn sum512(data []u8) []u8 {
mut d := new_digest(.sha512)
d.write(data) or { panic(err) }
return d.checksum_internal()
return d.checksum()
}

// sum384 returns the SHA384 checksum of the data.
pub fn sum384(data []u8) []u8 {
mut d := new_digest(.sha384)
d.write(data) or { panic(err) }
sum := d.checksum_internal()
sum := d.checksum()
mut sum384 := []u8{len: size384}
copy(mut sum384, sum[..size384])
return sum384
Expand All @@ -312,7 +290,7 @@ pub fn sum384(data []u8) []u8 {
pub fn sum512_224(data []u8) []u8 {
mut d := new_digest(.sha512_224)
d.write(data) or { panic(err) }
sum := d.checksum_internal()
sum := d.checksum()
mut sum224 := []u8{len: size224}
copy(mut sum224, sum[..size224])
return sum224
Expand All @@ -322,7 +300,7 @@ pub fn sum512_224(data []u8) []u8 {
pub fn sum512_256(data []u8) []u8 {
mut d := new_digest(.sha512_256)
d.write(data) or { panic(err) }
sum := d.checksum_internal()
sum := d.checksum()
mut sum256 := []u8{len: size256}
copy(mut sum256, sum[..size256])
return sum256
Expand Down
Loading

0 comments on commit 3d78718

Please sign in to comment.