From d048bf66b09bb310424d4e943e3daa8bbf4ebdf5 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Wed, 1 Apr 2020 00:18:25 +1100 Subject: [PATCH] cgen: optimize/generalize typ method --- vlib/time/time.v | 5 +++-- vlib/v/gen/cgen.v | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vlib/time/time.v b/vlib/time/time.v index b4287d61e6..afad392ab6 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -61,7 +61,8 @@ pub enum FormatDelimiter { space } -pub struct C.time_t {} +// TODO: C.time_t. works in v2 +type time_t voidptr pub struct C.timeval { tv_sec u64 @@ -70,7 +71,7 @@ pub struct C.timeval { fn C.localtime(int) &C.tm -fn C.time(int) C.time_t +fn C.time(int) time_t // now returns current local time. pub fn now() Time { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 646899e055..988f3ca0dc 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -148,10 +148,9 @@ pub fn (g mut Gen) typ(t table.Type) string { } if styp.starts_with('C__') { styp = styp[3..] - } - if styp in ['stat', 'dirent*', 'tm', 'tm*', 'winsize', 'sigaction', 'timeval'] { - // TODO perf and other C structs - styp = 'struct $styp' + if sym.kind == .struct_ { + styp = 'struct $styp' + } } if table.type_is_optional(t) { styp = 'Option_' + styp