From 033b027361e4a1ecd9e4d58ecba9ae0ad2c76c8e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 31 Jul 2021 08:42:40 +0300 Subject: [PATCH] v.gen.c: use `const type* const_x` for `const_x &type` fn args --- vlib/v/gen/c/fn.v | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index b09855e7bb..b0ed915c47 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -71,7 +71,7 @@ fn (mut g Gen) process_fn_decl(node ast.FnDecl) { unsafe { g.fn_decl = &node } - if node.name == 'main.main' { + if node.is_main { g.has_main = true } if node.name == 'backtrace' || node.name == 'backtrace_symbols' @@ -196,8 +196,8 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) { name = g.generic_fn_name(g.table.cur_concrete_types, name, true) - if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') - && name != 'main__main' && node.name != 'str' { + if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') && !node.is_main + && node.name != 'str' { mut key := node.name if node.is_method { sym := g.table.get_type_symbol(node.receiver.typ) @@ -435,7 +435,13 @@ fn (mut g Gen) fn_args(args []ast.Param, is_variadic bool, scope &ast.Scope) ([] } } var_name_prefix := if heap_prom { '_v_toheap_' } else { '' } - s := '$arg_type_name $var_name_prefix$caname' + const_prefix := if arg.typ.is_any_kind_of_pointer() && !arg.is_mut + && arg.name.starts_with('const_') { + 'const ' + } else { + '' + } + s := '$const_prefix$arg_type_name $var_name_prefix$caname' g.write(s) g.definitions.write_string(s) fargs << caname