Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 21, 2024
1 parent 8ae627f commit 0d1ca3e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,8 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
return
} else if arg.expr is ast.Ident && arg.expr.language == .c {
g.write('(voidptr)')
} else {
} else if !(!arg.is_mut && arg_sym.kind == .alias
&& g.table.unaliased_type(arg_typ).is_any_kind_of_pointer()) {
g.write('(voidptr)&/*qq*/')
}
} else {
Expand All @@ -2731,7 +2732,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
atype = g.unwrap_generic(atype)
}
if atype.has_flag(.generic) || arg.expr is ast.StructInit {
g.write('(voidptr)&/*qq*/')
g.write('(voidptr)&/*qq2*/')
} else if arg.expr is ast.None {
g.expr_with_opt(arg.expr, arg_typ, expected_type)
return
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/gen/c/testdata/alias_char_ptr_to_ptr.c.must_have
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VV_LOCAL_SYMBOL string main__get_two(void) {
char* s = main__return_text_two();
string _t1 = cstring_to_vstring(s);
return _t1;
}
VV_LOCAL_SYMBOL string main__get_one(void) {
main__ALcharptr s = main__return_text_one();
string _t1 = cstring_to_vstring(s);
return _t1;
}
17 changes: 17 additions & 0 deletions vlib/v/gen/c/testdata/alias_char_ptr_to_ptr.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type ALcharptr = &char
fn return_text_one() ALcharptr {
return ALcharptr(''.str)
}
fn return_text_two() &char {
return ''.str
}

fn get_one() string {
s := return_text_one()
return unsafe { cstring_to_vstring(s) }
}

fn get_two() string {
s := return_text_two()
return unsafe { cstring_to_vstring(s) }
}

0 comments on commit 0d1ca3e

Please sign in to comment.