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:
@ -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{
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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.')
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user