Skip to content

Commit

Permalink
cgen: add callconv support for fns from ptr (#14151)
Browse files Browse the repository at this point in the history
  • Loading branch information
fleur committed Apr 25, 2022
1 parent 11ee2b6 commit ddbe812
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions vlib/v/gen/c/assign.v
Expand Up @@ -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 {
Expand Down

0 comments on commit ddbe812

Please sign in to comment.