From 2134fb3e3e63b699c46041181e80bcf0555325d5 Mon Sep 17 00:00:00 2001 From: fleur Date: Mon, 25 Apr 2022 07:51:03 +0200 Subject: [PATCH] cgen: add callconv support for fns from ptr (#14151) --- vlib/v/gen/c/assign.v | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index a167ffbbc1..97e3caffa3 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -314,11 +314,32 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) { } func := right_sym.info as ast.FnType ret_styp := g.typ(func.func.return_type) - g.write('$ret_styp (*${g.get_ternary_name(ident.name)}) (') + + mut call_conv := '' + mut msvc_call_conv := '' + for attr in func.func.attrs { + match attr.name { + 'callconv' { + if g.is_cc_msvc { + msvc_call_conv = '__$attr.arg ' + } else { + call_conv = '$attr.arg' + } + } + else {} + } + } + call_conv_attribute_suffix := if call_conv.len != 0 { + '__attribute__(($call_conv))' + } else { + '' + } + + g.write('$ret_styp ($msvc_call_conv*${g.get_ternary_name(ident.name)}) (') def_pos := g.definitions.len g.fn_decl_params(func.func.params, voidptr(0), false) g.definitions.go_back(g.definitions.len - def_pos) - g.write(')') + g.write(')$call_conv_attribute_suffix') } else { if is_decl { if is_inside_ternary {