1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

more C warnings fixed

This commit is contained in:
Alexander Medvednikov 2019-09-15 15:36:05 +03:00
parent e3bd72e8e2
commit 849bef987c
9 changed files with 30 additions and 25 deletions

View File

@ -45,7 +45,7 @@ fn new_scanner(file_path string) &Scanner {
if c_text[0] == 0xEF && c_text[1] == 0xBB && c_text[2] == 0xBF {
// skip three BOM bytes
offset_from_begin := 3
raw_text = tos(c_text[offset_from_begin], C.strlen(c_text) - offset_from_begin)
raw_text = tos(c_text[offset_from_begin], vstrlen(c_text) - offset_from_begin)
}
}

View File

@ -17,17 +17,19 @@ fn on_panic(f fn (int) int) {
// TODO
}
fn C.backtrace(voidptr, int) int
pub fn print_backtrace_skipping_top_frames(skipframes int) {
$if mac {
buffer := [100]byteptr
nr_ptrs := C.backtrace(buffer, 100)
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1)
nr_ptrs := C.backtrace(*voidptr(buffer), 100)
C.backtrace_symbols_fd(*voidptr(&buffer[skipframes]), nr_ptrs-skipframes, 1)
return
}
$if linux {
if C.backtrace_symbols_fd != 0 {
buffer := [100]byteptr
nr_ptrs := C.backtrace(buffer, 100)
nr_ptrs := C.backtrace(*voidptr(buffer), 100)
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1)
return
}else{

View File

@ -9,20 +9,20 @@ module builtin
pub fn (d f64) str() string {
buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(buf, '%f', d)
return tos(buf, strlen(buf))
C.sprintf(*char(buf), '%f', d)
return tos(buf, vstrlen(buf))
}
pub fn (d f32) str() string {
buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(buf, '%f', d)
return tos(buf, strlen(buf))
C.sprintf(*char(buf), '%f', d)
return tos(buf, vstrlen(buf))
}
pub fn ptr_str(ptr voidptr) string {
buf := malloc(sizeof(double) * 5 + 1)// TODO
C.sprintf(buf, '%p', ptr)
return tos(buf, strlen(buf))
C.sprintf(*char(buf), '%p', ptr)
return tos(buf, vstrlen(buf))
}
// compare floats using C epsilon
@ -160,7 +160,7 @@ pub fn (n int) hex() string {
11
}
hex := malloc(len) // 0x + \n
count := int(C.sprintf(hex, '0x%x', n))
count := int(C.sprintf(*char(hex), '0x%x', n))
return tos(hex, count)
}
@ -171,7 +171,7 @@ pub fn (n i64) hex() string {
19
}
hex := malloc(len)
count := int(C.sprintf(hex, '0x%x', n))
count := int(C.sprintf(*char(hex), '0x%llx', n))
return tos(hex, count)
}

View File

@ -211,7 +211,7 @@ pub fn (m mut map) delete(key string) {
m.size--
}
pub fn (m map) exists(key string) bool {
pub fn (m map) exists(key string) {
panic('map.exists(key) was removed from the language. Use `key in map` instead.')
}

View File

@ -22,6 +22,10 @@ pub:
// For C strings only
fn C.strlen(s byteptr) int
pub fn vstrlen(s byteptr) int {
return C.strlen(*char(s))
}
fn todo() { }
// Converts a C string to a V string.
@ -50,7 +54,7 @@ fn tos2(s byteptr) string {
if isnil(s) {
panic('tos2: nil string')
}
len := C.strlen(s)
len := vstrlen(s)
res := tos(s, len)
return res
}

View File

@ -4,8 +4,8 @@
module builtin
pub fn utf8_char_len(b byte) int {
return (( 0xe5000000 >> (( b >> 3 ) & 0x1e )) & 3 ) + 1
pub fn utf8_char_len(b byte) int {
return (( 0xe5000000 >> (( b >> 3 ) & 0x1e )) & 3 ) + 1
}
// Convert utf32 to utf8
@ -157,12 +157,11 @@ fn utf8_len(c byte) int {
pub fn utf8_getchar() int {
c := int(C.getchar())
len := utf8_len(~c)
if c < 0 {
return 0
} else if (len == 0) {
} else if len == 0 {
return c
} else if (len == 1) {
} else if len == 1 {
return -1
} else {
mut uc := int(c & ((1 << (7 - len)) - 1))
@ -171,7 +170,7 @@ pub fn utf8_getchar() int {
if c2 != -1 && (c2 >> 6) == 2 {
uc <<= 6
uc |= int((c2 & 63))
} else if (c2 == -1) {
} else if c2 == -1 {
return 0
} else {
return -1

View File

@ -138,7 +138,7 @@ pub fn read_lines(path string) []string {
mut buf_index := 0
for C.fgets(buf + buf_index, buf_len - buf_index, fp) != 0 {
len := C.strlen(buf)
len := vstrlen(buf)
if len == buf_len - 1 && buf[len - 1] != 10 {
buf_len *= 2
buf = C.realloc(buf, buf_len)
@ -307,7 +307,7 @@ pub fn exec(cmd string) ?Result {
buf := [1000]byte
mut res := ''
for C.fgets(buf, 1000, f) != 0 {
res += tos(buf, strlen(buf))
res += tos(buf, vstrlen(buf))
}
res = res.trim_space()
exit_code := pclose(f)
@ -709,7 +709,7 @@ pub fn realpath(fpath string) string {
res = int( C.realpath( fpath.str, fullpath ) )
}
if res != 0 {
return string(fullpath, strlen(fullpath))
return string(fullpath, vstrlen(fullpath))
}
return fpath
}

View File

@ -22,7 +22,7 @@ pub fn get_error_msg(code int) string {
if _ptr_text == 0 {
return ''
}
return tos(_ptr_text, C.strlen(_ptr_text))
return tos(_ptr_text, vstrlen(_ptr_text))
}
pub fn ls(path string) []string {

View File

@ -186,5 +186,5 @@ pub fn get_error_msg(code int) string {
if _ptr_text == 0 { // compare with null
return ''
}
return tos(_ptr_text, C.strlen(_ptr_text))
return tos(_ptr_text, vstrlen(_ptr_text))
}