Skip to content

Commit ddbe812

Browse files
author
fleur
authored
cgen: add callconv support for fns from ptr (#14151)
1 parent 11ee2b6 commit ddbe812

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

vlib/v/gen/c/assign.v

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,32 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
314314
}
315315
func := right_sym.info as ast.FnType
316316
ret_styp := g.typ(func.func.return_type)
317-
g.write('$ret_styp (*${g.get_ternary_name(ident.name)}) (')
317+
318+
mut call_conv := ''
319+
mut msvc_call_conv := ''
320+
for attr in func.func.attrs {
321+
match attr.name {
322+
'callconv' {
323+
if g.is_cc_msvc {
324+
msvc_call_conv = '__$attr.arg '
325+
} else {
326+
call_conv = '$attr.arg'
327+
}
328+
}
329+
else {}
330+
}
331+
}
332+
call_conv_attribute_suffix := if call_conv.len != 0 {
333+
'__attribute__(($call_conv))'
334+
} else {
335+
''
336+
}
337+
338+
g.write('$ret_styp ($msvc_call_conv*${g.get_ternary_name(ident.name)}) (')
318339
def_pos := g.definitions.len
319340
g.fn_decl_params(func.func.params, voidptr(0), false)
320341
g.definitions.go_back(g.definitions.len - def_pos)
321-
g.write(')')
342+
g.write(')$call_conv_attribute_suffix')
322343
} else {
323344
if is_decl {
324345
if is_inside_ternary {

0 commit comments

Comments
 (0)