more C warnings fixed
parent
e3bd72e8e2
commit
849bef987c
|
@ -45,7 +45,7 @@ fn new_scanner(file_path string) &Scanner {
|
||||||
if c_text[0] == 0xEF && c_text[1] == 0xBB && c_text[2] == 0xBF {
|
if c_text[0] == 0xEF && c_text[1] == 0xBB && c_text[2] == 0xBF {
|
||||||
// skip three BOM bytes
|
// skip three BOM bytes
|
||||||
offset_from_begin := 3
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,19 @@ fn on_panic(f fn (int) int) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn C.backtrace(voidptr, int) int
|
||||||
|
|
||||||
pub fn print_backtrace_skipping_top_frames(skipframes int) {
|
pub fn print_backtrace_skipping_top_frames(skipframes int) {
|
||||||
$if mac {
|
$if mac {
|
||||||
buffer := [100]byteptr
|
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)
|
C.backtrace_symbols_fd(*voidptr(&buffer[skipframes]), nr_ptrs-skipframes, 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$if linux {
|
$if linux {
|
||||||
if C.backtrace_symbols_fd != 0 {
|
if C.backtrace_symbols_fd != 0 {
|
||||||
buffer := [100]byteptr
|
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)
|
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs-skipframes, 1)
|
||||||
return
|
return
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -9,20 +9,20 @@ module builtin
|
||||||
|
|
||||||
pub fn (d f64) str() string {
|
pub fn (d f64) str() string {
|
||||||
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
||||||
C.sprintf(buf, '%f', d)
|
C.sprintf(*char(buf), '%f', d)
|
||||||
return tos(buf, strlen(buf))
|
return tos(buf, vstrlen(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (d f32) str() string {
|
pub fn (d f32) str() string {
|
||||||
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
||||||
C.sprintf(buf, '%f', d)
|
C.sprintf(*char(buf), '%f', d)
|
||||||
return tos(buf, strlen(buf))
|
return tos(buf, vstrlen(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ptr_str(ptr voidptr) string {
|
pub fn ptr_str(ptr voidptr) string {
|
||||||
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
buf := malloc(sizeof(double) * 5 + 1)// TODO
|
||||||
C.sprintf(buf, '%p', ptr)
|
C.sprintf(*char(buf), '%p', ptr)
|
||||||
return tos(buf, strlen(buf))
|
return tos(buf, vstrlen(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare floats using C epsilon
|
// compare floats using C epsilon
|
||||||
|
@ -160,7 +160,7 @@ pub fn (n int) hex() string {
|
||||||
11
|
11
|
||||||
}
|
}
|
||||||
hex := malloc(len) // 0x + \n
|
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)
|
return tos(hex, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ pub fn (n i64) hex() string {
|
||||||
19
|
19
|
||||||
}
|
}
|
||||||
hex := malloc(len)
|
hex := malloc(len)
|
||||||
count := int(C.sprintf(hex, '0x%x', n))
|
count := int(C.sprintf(*char(hex), '0x%llx', n))
|
||||||
return tos(hex, count)
|
return tos(hex, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ pub fn (m mut map) delete(key string) {
|
||||||
m.size--
|
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.')
|
panic('map.exists(key) was removed from the language. Use `key in map` instead.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ pub:
|
||||||
// For C strings only
|
// For C strings only
|
||||||
fn C.strlen(s byteptr) int
|
fn C.strlen(s byteptr) int
|
||||||
|
|
||||||
|
pub fn vstrlen(s byteptr) int {
|
||||||
|
return C.strlen(*char(s))
|
||||||
|
}
|
||||||
|
|
||||||
fn todo() { }
|
fn todo() { }
|
||||||
|
|
||||||
// Converts a C string to a V string.
|
// Converts a C string to a V string.
|
||||||
|
@ -50,7 +54,7 @@ fn tos2(s byteptr) string {
|
||||||
if isnil(s) {
|
if isnil(s) {
|
||||||
panic('tos2: nil string')
|
panic('tos2: nil string')
|
||||||
}
|
}
|
||||||
len := C.strlen(s)
|
len := vstrlen(s)
|
||||||
res := tos(s, len)
|
res := tos(s, len)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
module builtin
|
module builtin
|
||||||
|
|
||||||
pub fn utf8_char_len(b byte) int {
|
pub fn utf8_char_len(b byte) int {
|
||||||
return (( 0xe5000000 >> (( b >> 3 ) & 0x1e )) & 3 ) + 1
|
return (( 0xe5000000 >> (( b >> 3 ) & 0x1e )) & 3 ) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert utf32 to utf8
|
// Convert utf32 to utf8
|
||||||
|
@ -157,12 +157,11 @@ fn utf8_len(c byte) int {
|
||||||
pub fn utf8_getchar() int {
|
pub fn utf8_getchar() int {
|
||||||
c := int(C.getchar())
|
c := int(C.getchar())
|
||||||
len := utf8_len(~c)
|
len := utf8_len(~c)
|
||||||
|
|
||||||
if c < 0 {
|
if c < 0 {
|
||||||
return 0
|
return 0
|
||||||
} else if (len == 0) {
|
} else if len == 0 {
|
||||||
return c
|
return c
|
||||||
} else if (len == 1) {
|
} else if len == 1 {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
} else {
|
||||||
mut uc := int(c & ((1 << (7 - len)) - 1))
|
mut uc := int(c & ((1 << (7 - len)) - 1))
|
||||||
|
@ -171,7 +170,7 @@ pub fn utf8_getchar() int {
|
||||||
if c2 != -1 && (c2 >> 6) == 2 {
|
if c2 != -1 && (c2 >> 6) == 2 {
|
||||||
uc <<= 6
|
uc <<= 6
|
||||||
uc |= int((c2 & 63))
|
uc |= int((c2 & 63))
|
||||||
} else if (c2 == -1) {
|
} else if c2 == -1 {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
} else {
|
||||||
return -1
|
return -1
|
||||||
|
|
|
@ -138,7 +138,7 @@ pub fn read_lines(path string) []string {
|
||||||
|
|
||||||
mut buf_index := 0
|
mut buf_index := 0
|
||||||
for C.fgets(buf + buf_index, buf_len - buf_index, fp) != 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 {
|
if len == buf_len - 1 && buf[len - 1] != 10 {
|
||||||
buf_len *= 2
|
buf_len *= 2
|
||||||
buf = C.realloc(buf, buf_len)
|
buf = C.realloc(buf, buf_len)
|
||||||
|
@ -307,7 +307,7 @@ pub fn exec(cmd string) ?Result {
|
||||||
buf := [1000]byte
|
buf := [1000]byte
|
||||||
mut res := ''
|
mut res := ''
|
||||||
for C.fgets(buf, 1000, f) != 0 {
|
for C.fgets(buf, 1000, f) != 0 {
|
||||||
res += tos(buf, strlen(buf))
|
res += tos(buf, vstrlen(buf))
|
||||||
}
|
}
|
||||||
res = res.trim_space()
|
res = res.trim_space()
|
||||||
exit_code := pclose(f)
|
exit_code := pclose(f)
|
||||||
|
@ -709,7 +709,7 @@ pub fn realpath(fpath string) string {
|
||||||
res = int( C.realpath( fpath.str, fullpath ) )
|
res = int( C.realpath( fpath.str, fullpath ) )
|
||||||
}
|
}
|
||||||
if res != 0 {
|
if res != 0 {
|
||||||
return string(fullpath, strlen(fullpath))
|
return string(fullpath, vstrlen(fullpath))
|
||||||
}
|
}
|
||||||
return fpath
|
return fpath
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn get_error_msg(code int) string {
|
||||||
if _ptr_text == 0 {
|
if _ptr_text == 0 {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return tos(_ptr_text, C.strlen(_ptr_text))
|
return tos(_ptr_text, vstrlen(_ptr_text))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ls(path string) []string {
|
pub fn ls(path string) []string {
|
||||||
|
|
|
@ -186,5 +186,5 @@ pub fn get_error_msg(code int) string {
|
||||||
if _ptr_text == 0 { // compare with null
|
if _ptr_text == 0 { // compare with null
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return tos(_ptr_text, C.strlen(_ptr_text))
|
return tos(_ptr_text, vstrlen(_ptr_text))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue