cgen: fix warnings (#5820)

pull/5824/head
ka-weihe 2020-07-14 00:16:31 +02:00 committed by GitHub
parent 042add0e7f
commit df45488e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 59 additions and 55 deletions

View File

@ -94,7 +94,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
beforeaddr := sframe.all_before('[')
cmd := 'addr2line -e $executable $addr'
// taken from os, to avoid depending on the os module inside builtin.v
f := C.popen(cmd.str, 'r')
f := C.popen(charptr(cmd.str), 'r')
if isnil(f) {
eprintln(sframe)
continue

View File

@ -3,7 +3,7 @@ module builtin
// <string.h>
fn C.memcpy(byteptr, byteptr, int) voidptr
fn C.memcmp(byteptr, byteptr, int) int
fn C.memmove(byteptr, byteptr, int) voidptr
fn C.calloc(int) byteptr
fn C.malloc(int) byteptr
@ -18,13 +18,13 @@ fn C.qsort(voidptr, int, int, qsort_callback_func)
fn C.sprintf(a ...voidptr) int
fn C.strlen(s byteptr) int
fn C.strlen(s charptr) int
fn C.sscanf(byteptr, byteptr,...byteptr) int
fn C.isdigit(s byteptr) bool
// stdio.h
fn C.popen(c byteptr, t byteptr) voidptr
fn C.popen(c charptr, t charptr) voidptr
// <execinfo.h>
fn C.backtrace(a &voidptr, size int) int
@ -35,7 +35,7 @@ fn C.backtrace_symbols_fd(a &voidptr, size int, fd int)
pub fn proc_pidpath(int, voidptr, int) int
fn C.realpath(byteptr, byteptr) &char
fn C.realpath(charptr, charptr) &char
fn C.chmod(byteptr, int) int
@ -71,10 +71,10 @@ fn C.pclose() int
fn C.system() int
fn C.setenv() int
fn C.setenv(charptr) int
fn C.unsetenv() int
fn C.unsetenv(charptr) int
fn C.access() int
@ -95,7 +95,7 @@ fn C.fread() int
fn C.rewind() int
fn C.stat() int
fn C.stat(charptr) int
fn C.lstat() int

View File

@ -6,8 +6,6 @@ module builtin
import strings
import hash.wyhash
fn C.memcmp(byteptr, byteptr, int) int
/*
This is a highly optimized hashmap implementation. It has several traits that
in combination makes it very fast and memory efficient. Here is a short expl-

View File

@ -149,7 +149,7 @@ pub fn (s string) cstr() byteptr {
// cstring_to_vstring creates a copy of cstr and turns it into a v string
pub fn cstring_to_vstring(cstr byteptr) string {
slen := C.strlen(cstr)
slen := C.strlen(charptr(cstr))
mut s := byteptr(memdup(cstr, slen + 1))
s[slen] = `\0`
return tos(s, slen)

View File

@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
module os
fn C.getenv(byteptr) &char
fn C.getenv(charptr) &char
// C.GetEnvironmentStringsW & C.FreeEnvironmentStringsW are defined only on windows
fn C.GetEnvironmentStringsW() &u16
@ -18,7 +18,7 @@ pub fn getenv(key string) string {
}
return string_from_wide(s)
} $else {
s := C.getenv(key.str)
s := C.getenv(charptr(key.str))
if s == voidptr(0) {
return ''
}
@ -36,7 +36,7 @@ pub fn setenv(name string, value string, overwrite bool) int {
}
return -1
} $else {
return C.setenv(name.str, value.str, overwrite)
return C.setenv(charptr(name.str), charptr(value.str), overwrite)
}
}
@ -46,7 +46,7 @@ pub fn unsetenv(name string) int {
format := '${name}='
return C._putenv(format.str)
} $else {
return C.unsetenv(name.str)
return C.unsetenv(charptr(name.str))
}
}
@ -73,7 +73,7 @@ pub fn environ() map[string]string {
} $else {
e := &charptr(C.environ)
for i := 0; !isnil(e[i]); i++ {
eline := cstring_to_vstring(e[i])
eline := cstring_to_vstring(byteptr(e[i]))
eq_index := eline.index_byte(`=`)
if eq_index > 0 {
res[eline[0..eq_index]] = eline[eq_index + 1..]

View File

@ -32,7 +32,7 @@ pub:
// it supports windows for regular files but it doesn't matter if you use owner, group or others when checking permissions on windows
pub fn inode(path string) FileMode {
mut attr := C.stat{}
C.stat(path.str, &attr)
C.stat(charptr(path.str), &attr)
mut typ := FileType.regular
if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFDIR) {

View File

@ -170,11 +170,11 @@ pub fn cp(old, new string) ? {
return error_with_code('failed to copy $old to $new', int(result))
}
} $else {
fp_from := C.open(old.str, C.O_RDONLY)
fp_from := C.open(charptr(old.str), C.O_RDONLY)
if fp_from < 0 { // Check if file opened
return error_with_code('cp: failed to open $old', int(fp_from))
}
fp_to := C.open(new.str, C.O_WRONLY | C.O_CREAT | C.O_TRUNC, C.S_IWUSR | C.S_IRUSR)
fp_to := C.open(charptr(new.str), C.O_WRONLY | C.O_CREAT | C.O_TRUNC, C.S_IWUSR | C.S_IRUSR)
if fp_to < 0 { // Check if file opened (permissions problems ...)
C.close(fp_from)
return error_with_code('cp: failed to write to $new', int(fp_to))
@ -193,8 +193,8 @@ pub fn cp(old, new string) ? {
}
}
from_attr := C.stat{}
C.stat(old.str, &from_attr)
if C.chmod(new.str, from_attr.st_mode) < 0 {
C.stat(charptr(old.str), &from_attr)
if C.chmod(charptr(new.str), from_attr.st_mode) < 0 {
return error_with_code('failed to set permissions for $new', int(-1))
}
}
@ -387,7 +387,7 @@ fn vpopen(path string) voidptr {
return C._wpopen(wpath, mode.to_wide())
} $else {
cpath := path.str
return C.popen(cpath, 'r')
return C.popen(charptr(cpath), 'r')
}
}
@ -446,7 +446,7 @@ pub fn system(cmd string) int {
wcmd := if cmd.len > 1 && cmd[0] == `"` && cmd[1] != `"` { '"$cmd"' } else { cmd }
ret = C._wsystem(wcmd.to_wide())
} $else {
ret = C.system(cmd.str)
ret = C.system(charptr(cmd.str))
}
if ret == -1 {
print_c_errno()
@ -554,7 +554,7 @@ pub fn exists(path string) bool {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), f_ok) != -1
} $else {
return C.access(path.str, f_ok) != -1
return C.access(charptr(path.str), f_ok) != -1
}
}
@ -572,12 +572,12 @@ pub fn is_executable(path string) bool {
}
$if solaris {
statbuf := C.stat{}
if C.stat(path.str, &statbuf) != 0 {
if C.stat(charptr(path.str), &statbuf) != 0 {
return false
}
return (int(statbuf.st_mode) & ( s_ixusr | s_ixgrp | s_ixoth )) != 0
}
return C.access(path.str, x_ok) != -1
return C.access(charptr(path.str), x_ok) != -1
}
// `is_writable_folder` - `folder` exists and is writable to the process
@ -603,7 +603,7 @@ pub fn is_writable(path string) bool {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), w_ok) != -1
} $else {
return C.access(path.str, w_ok) != -1
return C.access(charptr(path.str), w_ok) != -1
}
}
@ -613,7 +613,7 @@ pub fn is_readable(path string) bool {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), r_ok) != -1
} $else {
return C.access(path.str, r_ok) != -1
return C.access(charptr(path.str), r_ok) != -1
}
}
@ -632,7 +632,7 @@ pub fn rm(path string) ? {
return error('Failed to remove "$path"')
}
} $else {
rc := C.remove(path.str)
rc := C.remove(charptr(path.str))
if rc == -1 {
return error(posix_get_error_msg(C.errno))
}
@ -648,7 +648,7 @@ pub fn rmdir(path string) ? {
return error('Failed to remove "$path"')
}
} $else {
rc := C.rmdir(path.str)
rc := C.rmdir(charptr(path.str))
if rc == -1 {
return error(posix_get_error_msg(C.errno))
}
@ -939,7 +939,7 @@ pub fn on_segfault(f voidptr) {
pub fn executable() string {
$if linux {
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/self/exe', result, max_path_len)
count := C.readlink('/proc/self/exe', charptr(result), max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/self/exe to get exe path')
return executable_fallback()
@ -975,7 +975,7 @@ pub fn executable() string {
$if haiku {}
$if netbsd {
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/curproc/exe', result, max_path_len)
count := C.readlink('/proc/curproc/exe', charptr(result), max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path')
return executable_fallback()
@ -984,7 +984,7 @@ pub fn executable() string {
}
$if dragonfly {
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/curproc/file', result, max_path_len)
count := C.readlink('/proc/curproc/file', charptr(result), max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/file to get exe path')
return executable_fallback()
@ -1068,7 +1068,7 @@ pub fn is_dir(path string) bool {
return false
} $else {
statbuf := C.stat{}
if C.stat(path.str, &statbuf) != 0 {
if C.stat(charptr(path.str), &statbuf) != 0 {
return false
}
// ref: https://code.woboq.org/gcc/include/sys/stat.h.html
@ -1083,7 +1083,7 @@ pub fn is_link(path string) bool {
return false // TODO
} $else {
statbuf := C.stat{}
if C.lstat(path.str, &statbuf) != 0 {
if C.lstat(charptr(path.str), &statbuf) != 0 {
return false
}
return int(statbuf.st_mode) & s_ifmt == s_iflnk
@ -1095,7 +1095,7 @@ pub fn chdir(path string) {
$if windows {
C._wchdir(path.to_wide())
} $else {
C.chdir(path.str)
C.chdir(charptr(path.str))
}
}
@ -1110,7 +1110,7 @@ pub fn getwd() string {
return string_from_wide(buf)
} $else {
buf := vcalloc(512)
if C.getcwd(buf, 512) == 0 {
if C.getcwd(charptr(buf), 512) == 0 {
return ''
}
return string(buf)
@ -1131,7 +1131,7 @@ pub fn real_path(fpath string) string {
return fpath
}
} $else {
ret = charptr(C.realpath(fpath.str, fullpath))
ret = charptr(C.realpath(charptr(fpath.str), charptr(fullpath)))
if ret == 0 {
return fpath
}
@ -1233,7 +1233,7 @@ pub fn wait() int {
pub fn file_last_mod_unix(path string) int {
attr := C.stat{}
// # struct stat attr;
C.stat(path.str, &attr)
C.stat(charptr(path.str), &attr)
// # stat(path.str, &attr);
return attr.st_mtime
// # return attr.st_mtime ;
@ -1318,7 +1318,7 @@ pub fn temp_dir() string {
}
pub fn chmod(path string, mode int) {
C.chmod(path.str, mode)
C.chmod(charptr(path.str), mode)
}
pub const (

View File

@ -34,11 +34,11 @@ pub fn uname() Uname {
mut u := Uname{}
d := &C.utsname( malloc(int(sizeof(C.utsname))) )
if C.uname(d) == 0 {
u.sysname = cstring_to_vstring(d.sysname)
u.nodename = cstring_to_vstring(d.nodename)
u.release = cstring_to_vstring(d.release)
u.version = cstring_to_vstring(d.version)
u.machine = cstring_to_vstring(d.machine)
u.sysname = cstring_to_vstring(byteptr(d.sysname))
u.nodename = cstring_to_vstring(byteptr(d.nodename))
u.release = cstring_to_vstring(byteptr(d.release))
u.version = cstring_to_vstring(byteptr(d.version))
u.machine = cstring_to_vstring(byteptr(d.machine))
}
free(d)
return u
@ -58,7 +58,7 @@ fn init_os_args(argc int, argv &&byte) []string {
pub fn ls(path string) ?[]string {
mut res := []string{}
dir := C.opendir(path.str)
dir := C.opendir(charptr(path.str))
if isnil(dir) {
return error('ls() couldnt open dir "$path"')
}
@ -121,7 +121,7 @@ pub fn mkdir(path string) ?bool {
}
}
*/
r := C.mkdir(apath.str, 511)
r := C.mkdir(charptr(apath.str), 511)
if r == -1 {
return error(posix_get_error_msg(C.errno))
}
@ -157,7 +157,7 @@ pub fn exec(cmd string) ?Result {
}
pub fn symlink(origin, target string) ?bool {
res := C.symlink(origin.str, target.str)
res := C.symlink(charptr(origin.str), charptr(target.str))
if res == 0 {
return true
}

View File

@ -241,7 +241,7 @@ extract_entry extracts the current zip entry into output file.
@return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (mut zentry zip_ptr) extract_entry(path string) /*?*/bool {
if C.access(path.str, 0) == -1 {
if C.access(charptr(path.str), 0) == -1 {
return false
//return error('Cannot open file for extracting, file not exists')
}

View File

@ -67,7 +67,7 @@ pub fn parse_iso8601(s string) ?Time {
mut offset_hour := 0
mut offset_min := 0
count := C.sscanf(s.str, "%4d-%2d-%2d%c%2d:%2d:%2d.%6d%c%2d:%2d", &year, &month, &day,
count := C.sscanf(charptr(s.str), "%4d-%2d-%2d%c%2d:%2d:%2d.%6d%c%2d:%2d", &year, &month, &day,
&time_char, &hour, &minute,
&second, &mic_second, &plus_min,
&offset_hour, &offset_min)

View File

@ -26,7 +26,7 @@ fn make_unix_time(t C.tm) int {
fn to_local_time(t Time) Time {
loc_tm := C.tm{}
C.localtime_r(&t.unix, &loc_tm)
C.localtime_r(time_t(&t.unix), &loc_tm)
return convert_ctime(loc_tm, t.microsecond)
}

View File

@ -3903,11 +3903,17 @@ fn (g Gen) type_default(typ table.Type) string {
}
*/
match sym.name {
'string' { return '(string){.str=""}' }
'string' { return '(string){.str=(byteptr)""}' }
'rune' { return '0' }
else {}
}
return '{0}'
return match sym.kind {
.sum_type { '{0}' }
.array_fixed { '{0}' }
else { '0' }
}
// TODO this results in
// error: expected a field designator, such as '.field = 4'
// - Empty ee= (Empty) { . = {0} } ;

View File

@ -212,7 +212,7 @@ static void* g_live_info = NULL;
//============================== HELPER C MACROS =============================*/
//#define tos4(s, slen) ((string){.str=(s), .len=(slen)})
#define _SLIT(s) ((string){.str=(s), .len=(strlen(s))})
#define _SLIT(s) ((string){.str=(byteptr)(s), .len=(strlen(s))})
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
#define _IN_MAP(val, m) map_exists(m, val)

View File

@ -620,7 +620,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
if word.len != 2 {
verror('opcodes format: xx xx xx xx')
}
b := C.strtol(word.str, 0, 16)
b := C.strtol(charptr(word.str), 0, 16)
// b := word.byte()
// println('"$word" $b')
g.write8(b)