mirror of
https://github.com/vlang/v.git
synced 2025-09-08 06:41:58 -04:00
cgen,checker: allow for pub type C.HINSTANCE = voidptr
, being used in @[export: "wWinMain"] fn mymain(x C.HINSTANCE, xprev C.HINSTANCE, lpcmdline &C.WCHAR, cmdshow int) int {
in module no_main
programs (#23812)
This commit is contained in:
parent
c826923b16
commit
94f0f6d93b
@ -550,8 +550,10 @@ fn (mut c Checker) alias_type_decl(mut node ast.AliasTypeDecl) {
|
||||
}
|
||||
.alias {
|
||||
orig_sym := c.table.sym((parent_typ_sym.info as ast.Alias).parent_type)
|
||||
c.error('type `${parent_typ_sym.str()}` is an alias, use the original alias type `${orig_sym.name}` instead',
|
||||
node.type_pos)
|
||||
if !node.name.starts_with('C.') {
|
||||
c.error('type `${parent_typ_sym.str()}` is an alias, use the original alias type `${orig_sym.name}` instead',
|
||||
node.type_pos)
|
||||
}
|
||||
}
|
||||
.chan {
|
||||
c.error('aliases of `chan` types are not allowed', node.type_pos)
|
||||
|
@ -1815,6 +1815,12 @@ pub fn (mut g Gen) write_alias_typesymbol_declaration(sym ast.TypeSymbol) {
|
||||
// TODO: remove this check; it is here just to fix V rebuilding in -cstrict mode with clang-12
|
||||
return
|
||||
}
|
||||
if sym.name.starts_with('C.') {
|
||||
// `pub type C.HINSTANCE = voidptr` means that `HINSTANCE` should be treated as a voidptr by V.
|
||||
// The C type itself however already exists on the C side, so just treat C__HINSTANCE as a macro for it:
|
||||
g.type_definitions.writeln('#define ${sym.cname} ${sym.cname#[3..]}')
|
||||
return
|
||||
}
|
||||
if is_fixed_array_of_non_builtin && levels == 0 {
|
||||
g.alias_definitions.writeln('typedef ${parent_styp} ${sym.cname};')
|
||||
} else {
|
||||
|
1
vlib/v/gen/c/testdata/multiple_c_cources/file3.c
vendored
Normal file
1
vlib/v/gen/c/testdata/multiple_c_cources/file3.c
vendored
Normal file
@ -0,0 +1 @@
|
||||
typedef struct { int i; float f; char c; } CStruct, *PCStruct;
|
39
vlib/v/tests/builtin_arrays/array_fixed_c_test.c.v
Normal file
39
vlib/v/tests/builtin_arrays/array_fixed_c_test.c.v
Normal file
@ -0,0 +1,39 @@
|
||||
#include "@VMODROOT/vlib/v/gen/c/testdata/multiple_c_cources/file3.c"
|
||||
|
||||
@[typedef]
|
||||
struct C.CStruct {
|
||||
mut:
|
||||
c char
|
||||
i int
|
||||
f f32
|
||||
}
|
||||
|
||||
type C.PCStruct = &C.CStruct
|
||||
|
||||
struct WrapperStruct {
|
||||
mut:
|
||||
arr_fixed_c_type [2]C.PCStruct
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
s1 := &C.CStruct{
|
||||
c: char(`A`)
|
||||
f: 3.14
|
||||
i: 42
|
||||
}
|
||||
s2 := &C.CStruct{
|
||||
c: char(`B`)
|
||||
f: 1.4142
|
||||
i: 2
|
||||
}
|
||||
mut w := WrapperStruct{}
|
||||
w.arr_fixed_c_type[0] = s1
|
||||
w.arr_fixed_c_type[1] = s2
|
||||
dump(w)
|
||||
assert w.arr_fixed_c_type[0].c == char(`A`)
|
||||
assert w.arr_fixed_c_type[1].c == char(`B`)
|
||||
assert w.arr_fixed_c_type[0].f == 3.14
|
||||
assert w.arr_fixed_c_type[1].f == 1.4142
|
||||
assert w.arr_fixed_c_type[0].i == 42
|
||||
assert w.arr_fixed_c_type[1].i == 2
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
type C.ArrFixedCTestType = voidptr
|
||||
|
||||
struct WrapperStruct {
|
||||
mut:
|
||||
arr_fixed_c_type [1]C.ArrFixedCTestType
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user