Skip to content

Commit

Permalink
cgen: fix code for C ident when ptr is expected (#22259)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 20, 2024
1 parent 9a0f4d8 commit c866e37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,8 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if expected_type.has_flag(.option) {
g.expr_with_opt(arg.expr, arg_typ, expected_type)
return
} else if arg.expr is ast.Ident && arg.expr.language == .c {
g.write('(voidptr)')
} else {
g.write('(voidptr)&/*qq*/')
}
Expand Down
1 change: 1 addition & 0 deletions vlib/v/gen/c/testdata/c_ident_for_ptr_arg.c.must_have
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int (*real_open) (charptr , int , int ) = ((main__RealOpen)((dl__sym((voidptr)RTLD_NEXT, _SLIT("open")))));
13 changes: 13 additions & 0 deletions vlib/v/gen/c/testdata/c_ident_for_ptr_arg.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module main

import dl

#flag -D_GNU_SOURCE

type RealOpen = fn(charptr, int, int) int

@[export: open]
fn open(filename charptr, oflag int, mode int) int {
real_open := RealOpen((dl.sym(C.RTLD_NEXT, "open")))
return real_open(filename, oflag, mode)
}

0 comments on commit c866e37

Please sign in to comment.