Skip to content

Commit 0e4ae76

Browse files
authored
wasm: fix size of pointers in structs (#26357)
1 parent adcd421 commit 0e4ae76

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎vlib/v/gen/wasm/serialise/serialise.v‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ pub fn (mut p Pool) type_struct_info(typ ast.Type) ?StructInfo {
5858
}
5959

6060
pub fn (mut p Pool) type_size(typ ast.Type) (int, int) {
61+
if typ.nr_muls() > 0 {
62+
return p.table.pointer_size, p.table.pointer_size
63+
}
64+
6165
ts := p.table.sym(typ)
6266
if ts.size != -1 && typ.idx() in p.structs {
6367
return ts.size, ts.align

‎vlib/v/gen/wasm/tests/misc.vv‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,24 @@ fn run_defer() {
8282
defer_if(false)
8383
}
8484

85+
struct HasPointers {
86+
a int
87+
msg &string
88+
pub mut:
89+
same &HasPointers
90+
}
91+
92+
fn ptr_in_struct() {
93+
msg := 'pointer in struct'
94+
mut s := HasPointers{1234, &msg, unsafe { nil }}
95+
println(*s.msg)
96+
s.same = &s
97+
println(*&int(voidptr(s.same.a))) // FIXME: wont work without casts
98+
}
99+
85100
fn main() {
101+
println('ptr_in_struct')
102+
ptr_in_struct()
86103
println('ptr_arith')
87104
ptr_arith()
88105
run_defer()

‎vlib/v/gen/wasm/tests/misc.vv.out‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ptr_in_struct
2+
pointer in struct
3+
1234
14
ptr_arith
25
12
36
14

0 commit comments

Comments
 (0)