v2 / vlib / v / tests / c_function / pass_ref_test.c.v
58 lines · 45 sloc · 907 bytes · 657770e6c176ef9dc24ea25b771ba8c8795c08cf
Raw
1module main
2
3#include "@VMODROOT/array.c"
4
5enum Flag_bits {
6 aaa = 0
7 bbb = 1
8 ccc = 2
9}
10
11pub type Array_t = C.array_t
12
13@[typedef]
14struct C.array_t {
15pub mut:
16 array_ptr &&char
17 array_len int
18 string_len int
19}
20
21pub type Struct_array = C.struct_array
22
23@[typedef]
24struct C.struct_array {
25pub mut:
26 arr [4]Array_t
27 enu [2]Flag_bits
28}
29
30fn C.get_string_array() &&char
31@[inline]
32pub fn get_string_array() &&char {
33 return C.get_string_array()
34}
35
36fn C.get_struct_array() Struct_array
37@[inline]
38pub fn get_struct_array() Struct_array {
39 return C.get_struct_array()
40}
41
42fn C.array_string_free(&Array_t)
43
44@[keep_args_alive]
45fn C.set_struct_array(&Struct_array)
46@[inline]
47pub fn set_struct_array(param &Struct_array) {
48 C.set_struct_array(param)
49}
50
51fn test_main() {
52 struct_array := get_struct_array()
53
54 set_struct_array(&Struct_array{})
55 set_struct_array(&struct_array)
56
57 C.array_string_free(&struct_array.arr[0])
58}
59