From 31bee986074c46112097542170f3506f1d3e5cc3 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 28 Apr 2022 11:30:36 +0300 Subject: [PATCH] eval: add support for C.read/3, C.malloc/1, `$if openbsd {` --- vlib/builtin/cfns.c.v | 6 +++--- vlib/v/eval/expr.v | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 31e49c7cac..aab55f2e6c 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -10,11 +10,11 @@ fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr fn C.memset(str voidptr, c int, n usize) voidptr [trusted] -fn C.calloc(int, int) &byte +fn C.calloc(int, int) &u8 -fn C.malloc(int) &byte +fn C.malloc(int) &u8 -fn C.realloc(a &byte, b int) &byte +fn C.realloc(a &u8, b int) &u8 fn C.free(ptr voidptr) diff --git a/vlib/v/eval/expr.v b/vlib/v/eval/expr.v index a30af29838..2e78ec5f0a 100644 --- a/vlib/v/eval/expr.v +++ b/vlib/v/eval/expr.v @@ -24,13 +24,21 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object { e.error('c does not have methods') } match expr.name.all_after('C.') { + 'read' { + return Int{C.read(args[0].int_val(), args[1] as voidptr, args[2].int_val()), 64} + } 'write' { return Int{C.write(args[0].int_val(), args[1] as voidptr, - args[2].int_val()), 32} + args[2].int_val()), 64} + } + 'malloc' { + return Ptr{ + val: unsafe { C.malloc(args[0].int_val()) } + } } 'calloc' { return Ptr{ - val: vcalloc(int(args[0].int_val() * args[1].int_val())) + val: unsafe { C.calloc(args[0].int_val(), args[1].int_val()) } } } 'getcwd' { @@ -142,6 +150,9 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object { 'freebsd' { do_if = e.pref.os == .freebsd } + 'openbsd' { + do_if = e.pref.os == .openbsd + } 'prealloc' { do_if = e.pref.prealloc }