From d3ffd983c88a115446472207a4967c1dd5025ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Sun, 22 May 2022 13:52:38 +0200 Subject: [PATCH] markused: add _result_ok (#14495) --- vlib/builtin/option.v | 16 ++++++++-------- vlib/v/gen/c/cgen.v | 2 +- vlib/v/markused/markused.v | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index 6f97ee977b..02e8235a8a 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -113,14 +113,6 @@ struct Option { // derived Option_xxx types } -fn opt_ok(data voidptr, mut option Option, size int) { - unsafe { - *option = Option{} - // use err to get the end of OptionBase and then memcpy into it - vmemcpy(&u8(&option.err) + sizeof(IError), data, size) - } -} - // option is the base of V's internal optional return system. struct _option { state u8 @@ -130,6 +122,14 @@ struct _option { // derived _option_xxx types } +fn _option_ok(data voidptr, mut option _option, size int) { + unsafe { + *option = _option{} + // use err to get the end of OptionBase and then memcpy into it + vmemcpy(&u8(&option.err) + sizeof(IError), data, size) + } +} + fn opt_ok2(data voidptr, mut option _option, size int) { unsafe { *option = _option{} diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index ab50eadbf3..ab9e2604d3 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5237,7 +5237,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty styp := g.typ(g.fn_decl.return_type) err_obj := g.new_tmp_var() g.writeln('\t$styp $err_obj;') - g.writeln('\tmemcpy(&$err_obj, &$cvar_name, sizeof(Option));') + g.writeln('\tmemcpy(&$err_obj, &$cvar_name, sizeof(_option));') g.writeln('\treturn $err_obj;') } } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index a7688aabbe..2329590854 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -35,8 +35,9 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F 'tos2', 'tos3', 'isnil', - 'opt_ok', 'opt_ok2', + '_option_ok', + '_result_ok', 'error', // utf8_str_visible_length is used by c/str.v 'utf8_str_visible_length',