From eed94c727caf15c9fc74a02b8d38a0d8fded0bd1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 22 Oct 2021 17:08:08 +0300 Subject: [PATCH] os: move C struct declarations in their own _default.c.v files (#12268) --- cmd/tools/vast/vast.v | 2 +- cmd/tools/vwatch.v | 2 +- vlib/builtin/cfns.c.v | 6 +++- vlib/os/os.c.v | 38 ++---------------------- vlib/os/os_nix.c.v | 14 --------- vlib/os/os_structs_dirent_default.c.v | 5 ++++ vlib/os/os_structs_sigaction_default.c.v | 11 +++++++ vlib/os/os_structs_stat_default.c.v | 13 ++++++++ vlib/os/os_structs_stat_linux.c.v | 23 ++++++++++++++ vlib/os/os_structs_utsname_default.c.v | 15 ++++++++++ vlib/v/live/common.v | 2 +- vlib/v/util/util.v | 2 +- 12 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 vlib/os/os_structs_dirent_default.c.v create mode 100644 vlib/os/os_structs_sigaction_default.c.v create mode 100644 vlib/os/os_structs_stat_default.c.v create mode 100644 vlib/os/os_structs_stat_linux.c.v create mode 100644 vlib/os/os_structs_utsname_default.c.v diff --git a/cmd/tools/vast/vast.v b/cmd/tools/vast/vast.v index a889585bb..8b8b88f29 100644 --- a/cmd/tools/vast/vast.v +++ b/cmd/tools/vast/vast.v @@ -70,7 +70,7 @@ fn (ctx Context) write_file_or_print(file string) { // generate ast json file and c source code file fn (ctx Context) watch_for_changes(file string) { println('start watching...') - mut timestamp := 0 + mut timestamp := i64(0) for { new_timestamp := os.file_last_mod_unix(file) if timestamp != new_timestamp { diff --git a/cmd/tools/vwatch.v b/cmd/tools/vwatch.v index e718ea5a5..a7c55a1fc 100644 --- a/cmd/tools/vwatch.v +++ b/cmd/tools/vwatch.v @@ -61,7 +61,7 @@ fn get_scan_timeout_seconds() int { struct VFileStat { path string - mtime int + mtime i64 } [unsafe] diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 07ac6651f..c2bb9a31f 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -144,7 +144,11 @@ fn C.sleep(seconds u32) u32 [trusted] fn C.usleep(usec u32) int -fn C.opendir(&char) voidptr +[typedef] +struct C.DIR { +} + +fn C.opendir(&char) &C.DIR fn C.closedir(dirp &C.DIR) int diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index 0c06bec90..79c886c1d 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -7,10 +7,6 @@ pub const ( args = []string{} ) -struct C.dirent { - d_name [256]char -} - fn C.readdir(voidptr) &C.dirent fn C.readlink(pathname &char, buf &char, bufsiz usize) int @@ -41,36 +37,6 @@ fn C.ftruncate(voidptr, u64) int fn C._chsize_s(voidptr, u64) int -// fn C.proc_pidpath(int, byteptr, int) int -struct C.stat { - st_size u64 - st_mode u32 - st_mtime int -} - -struct C.__stat64 { - st_size u64 - st_mode u32 - st_mtime int -} - -struct C.DIR { -} - -type FN_SA_Handler = fn (sig int) - -struct C.sigaction { -mut: - sa_mask int - sa_sigaction int - sa_flags int - sa_handler FN_SA_Handler -} - -struct C.dirent { - d_name &byte -} - // read_bytes returns all bytes read from file in `path`. [manualfree] pub fn read_bytes(path string) ?[]byte { @@ -890,12 +856,12 @@ pub fn wait() int { } // file_last_mod_unix returns the "last modified" time stamp of file in `path`. -pub fn file_last_mod_unix(path string) int { +pub fn file_last_mod_unix(path string) i64 { attr := C.stat{} // # struct stat attr; unsafe { C.stat(&char(path.str), &attr) } // # stat(path.str, &attr); - return attr.st_mtime + return i64(attr.st_mtime) // # return attr.st_mtime ; } diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 6640ec8d9..da4878caf 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -43,20 +43,6 @@ pub const ( s_ixoth = 0o0001 // Execute by others ) -struct C.utsname { -mut: - sysname &char - nodename &char - release &char - version &char - machine &char -} - -struct C.utimbuf { - actime int - modtime int -} - fn C.utime(&char, voidptr) int fn C.uname(name voidptr) int diff --git a/vlib/os/os_structs_dirent_default.c.v b/vlib/os/os_structs_dirent_default.c.v new file mode 100644 index 000000000..6fd387552 --- /dev/null +++ b/vlib/os/os_structs_dirent_default.c.v @@ -0,0 +1,5 @@ +module os + +struct C.dirent { + d_name [256]char +} diff --git a/vlib/os/os_structs_sigaction_default.c.v b/vlib/os/os_structs_sigaction_default.c.v new file mode 100644 index 000000000..ba5a773c2 --- /dev/null +++ b/vlib/os/os_structs_sigaction_default.c.v @@ -0,0 +1,11 @@ +module os + +pub type FN_SA_Handler = fn (sig int) + +struct C.sigaction { +mut: + sa_mask int + sa_sigaction int + sa_flags int + sa_handler FN_SA_Handler +} diff --git a/vlib/os/os_structs_stat_default.c.v b/vlib/os/os_structs_stat_default.c.v new file mode 100644 index 000000000..0cace6814 --- /dev/null +++ b/vlib/os/os_structs_stat_default.c.v @@ -0,0 +1,13 @@ +module os + +struct C.stat { + st_size u64 + st_mode u32 + st_mtime int +} + +struct C.__stat64 { + st_size u64 + st_mode u32 + st_mtime int +} diff --git a/vlib/os/os_structs_stat_linux.c.v b/vlib/os/os_structs_stat_linux.c.v new file mode 100644 index 000000000..9cf61ff21 --- /dev/null +++ b/vlib/os/os_structs_stat_linux.c.v @@ -0,0 +1,23 @@ +module os + +struct C.stat { + st_dev u64 // 8 + st_ino u64 // 8 + st_nlink u64 // 8 + st_mode u32 // 4 + st_uid u32 // 4 + st_gid u32 // 4 + st_rdev u64 // 8 + st_size u64 // 8 + st_blksize u64 // 8 + st_blocks u64 // 8 + st_atime i64 // 8 + st_mtime i64 // 8 + st_ctime i64 // 8 +} + +struct C.__stat64 { + st_mode u32 + st_size u64 + st_mtime u64 +} diff --git a/vlib/os/os_structs_utsname_default.c.v b/vlib/os/os_structs_utsname_default.c.v new file mode 100644 index 000000000..5441d4d5b --- /dev/null +++ b/vlib/os/os_structs_utsname_default.c.v @@ -0,0 +1,15 @@ +module os + +struct C.utsname { +mut: + sysname &char + nodename &char + release &char + version &char + machine &char +} + +struct C.utimbuf { + actime int + modtime int +} diff --git a/vlib/v/live/common.v b/vlib/v/live/common.v index bd29a905e..1da31a05d 100644 --- a/vlib/v/live/common.v +++ b/vlib/v/live/common.v @@ -22,7 +22,7 @@ pub mut: reloads int // how many times a reloading was tried reloads_ok int // how many times the reloads succeeded reload_time_ms int // how much time the last reload took (compilation + loading) - last_mod_ts int // a timestamp for when the original was last changed + last_mod_ts i64 // a timestamp for when the original was last changed recheck_period_ms int = 100 // how often do you want to check for changes cb_recheck FNLiveReloadCB = voidptr(0) // executed periodically cb_compile_failed FNLiveReloadCB = voidptr(0) // executed when a reload compilation failed diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index fd918ab19..9a9c0b231 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -186,7 +186,7 @@ pub fn should_recompile_tool(vexe string, tool_source string, tool_name string, if os.is_dir(tool_source) { source_files := os.walk_ext(tool_source, '.v') mut newest_sfile := '' - mut newest_sfile_mtime := 0 + mut newest_sfile_mtime := i64(0) for sfile in source_files { mtime := os.file_last_mod_unix(sfile) if mtime > newest_sfile_mtime { -- 2.30.2