fix linux warnings in generated C code

pull/3893/head
Nicolas Sauzede 2020-03-01 13:26:09 +01:00 committed by GitHub
parent 7a499b3cd3
commit becd87141c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 20 deletions

View File

@ -108,7 +108,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
}
buf := [1000]byte
mut output := ''
for C.fgets(buf, 1000, f) != 0 {
for C.fgets(charptr(buf), 1000, f) != 0 {
output += tos(buf, vstrlen(buf))
}
output = output.trim_space() + ':'

View File

@ -156,17 +156,14 @@ pub fn (n int) hex() string {
pub fn (n i64) hex() string {
len := if n >= 0 { n.str().len + 3 } else { 19 }
hex := malloc(len)
// QTODO
//count := C.sprintf(charptr(hex), '0x%'C.PRIx64, n)
count := C.sprintf(hex, '0x%x', n)
count := C.sprintf(charptr(hex), '0x%'C.PRIx64, n)
return tos(hex, count)
}
pub fn (n u64) hex() string {
len := if n >= 0 { n.str().len + 3 } else { 19 }
len := if n > 0 { n.str().len + 3 } else { 19 }
hex := malloc(len)
//count := C.sprintf(charptr(hex), '0x%'C.PRIx64, n)
count := C.sprintf((hex), '0x%lx', n)
count := C.sprintf(charptr(hex), '0x%'C.PRIx64, n)
return tos(hex, count)
}

View File

@ -160,7 +160,7 @@ fn (m mut map) rehash(old_range_cap u32) {
memory := calloc(probe_hash_bytes + key_value_bytes)
mut new_key_values := &KeyValue(memory)
mut new_probe_hash := &u32(memory + key_value_bytes)
for i in 0 .. (old_range_cap + 1) {
for i := u32(0); i < old_range_cap + 1; i++ {
if m.probe_hash[i] != 0 {
mut kv := m.key_values[i]
hash := wyhash.wyhash_c(kv.key.str, u64(kv.key.len), 0)
@ -210,7 +210,7 @@ fn (m mut map) cached_rehash(old_range_cap u32) {
memory := calloc(probe_hash_bytes + key_value_bytes)
mut new_probe_hash := &u32(memory + key_value_bytes)
mut new_key_values := &KeyValue(memory)
for i in 0 .. (old_range_cap + 1) {
for i := u32(0); i < old_range_cap + 1; i++ {
if m.probe_hash[i] != 0 {
mut kv := m.key_values[i]
mut probe_hash := m.probe_hash[i]
@ -332,7 +332,7 @@ pub fn (m &map) keys() []string {
return keys
}
mut j := 0
for i in 0 .. (m.range_cap + 1) {
for i := u32(0); i < m.range_cap + 1; i++ {
if m.probe_hash[i] != 0 {
keys[j] = m.key_values[i].key
j++

View File

@ -205,18 +205,18 @@ pub fn reverse_16(x u16) u16 {
// reverse_32 returns the value of x with its bits in reversed order.
[inline]
pub fn reverse_32(x u32) u32 {
mut y := (x>>u32(1) & (m0 & max_u32) | ((x & (m0 & max_u32))<<1))
y = (y>>u32(2) & (m1 & max_u32) | ((y & (m1 & max_u32))<<u32(2)))
y = (y>>u32(4) & (m2 & max_u32) | ((y & (m2 & max_u32))<<u32(4)))
mut y := ((x>>u32(1) & (m0 & max_u32)) | ((x & (m0 & max_u32))<<1))
y = ((y>>u32(2) & (m1 & max_u32)) | ((y & (m1 & max_u32))<<u32(2)))
y = ((y>>u32(4) & (m2 & max_u32)) | ((y & (m2 & max_u32))<<u32(4)))
return reverse_bytes_32(y)
}
// reverse_64 returns the value of x with its bits in reversed order.
[inline]
pub fn reverse_64(x u64) u64 {
mut y := (x>>u64(1) & (m0 & max_u64) | ((x & (m0 & max_u64))<<1))
y = (y>>u64(2) & (m1 & max_u64) | ((y & (m1 & max_u64))<<2))
y = (y>>u64(4) & (m2 & max_u64) | ((y & (m2 & max_u64))<<4))
mut y := ((x>>u64(1) & (m0 & max_u64)) | ((x & (m0 & max_u64))<<1))
y = ((y>>u64(2) & (m1 & max_u64)) | ((y & (m1 & max_u64))<<2))
y = ((y>>u64(4) & (m2 & max_u64)) | ((y & (m2 & max_u64))<<4))
return reverse_bytes_64(y)
}
@ -235,7 +235,7 @@ pub fn reverse_bytes_16(x u16) u16 {
// This function's execution time does not depend on the inputs.
[inline]
pub fn reverse_bytes_32(x u32) u32 {
y := (x>>u32(8) & (m3 & max_u32) | ((x & (m3 & max_u32))<<u32(8)))
y := ((x>>u32(8) & (m3 & max_u32)) | ((x & (m3 & max_u32))<<u32(8)))
return (y>>16) | (y<<16)
}
@ -244,8 +244,8 @@ pub fn reverse_bytes_32(x u32) u32 {
// This function's execution time does not depend on the inputs.
[inline]
pub fn reverse_bytes_64(x u64) u64 {
mut y := (x>>u64(8) & (m3 & max_u64) | ((x & (m3 & max_u64))<<u64(8)))
y = (y>>u64(16) & (m4 & max_u64) | ((y & (m4 & max_u64))<<u64(16)))
mut y := ((x>>u64(8) & (m3 & max_u64)) | ((x & (m3 & max_u64))<<u64(8)))
y = ((y>>u64(16) & (m4 & max_u64)) | ((y & (m4 & max_u64))<<u64(16)))
return (y>>32) | (y<<32)
}

View File

@ -132,7 +132,7 @@ fn multiple_of_power_of_five_32(v u32, p u32) bool {
// multiple_of_power_of_two_32 reports whether v is divisible by 2^p.
fn multiple_of_power_of_two_32(v u32, p u32) bool {
return bits.trailing_zeros_32(v) >= p
return u32(bits.trailing_zeros_32(v)) >= p
}
// log10_pow2 returns floor(log_10(2^e)).