From cbd3c14e83bb5f61b5567b6216be6e70566ed2af Mon Sep 17 00:00:00 2001 From: crthpl <56052645+crthpl@users.noreply.github.com> Date: Fri, 21 Jan 2022 07:08:19 -0800 Subject: [PATCH] cgen: fix codegen for struct field with a shared array of points (#13222) --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/tests/shared_array_ptr_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/shared_array_ptr_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 490943bc51..981f3cbda4 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6160,7 +6160,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { noscan := g.check_noscan(elem_typ) init_str := '__new_array${noscan}(0, 0, sizeof($elem_type_str))' if typ.has_flag(.shared_f) { - atyp := '__shared__Array_${g.table.sym(elem_typ).cname}' + atyp := '__shared__$sym.cname' return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))' } else { return init_str diff --git a/vlib/v/tests/shared_array_ptr_test.v b/vlib/v/tests/shared_array_ptr_test.v new file mode 100644 index 0000000000..27f11f4635 --- /dev/null +++ b/vlib/v/tests/shared_array_ptr_test.v @@ -0,0 +1,12 @@ +struct AA { +mut: + a shared []&int +} + +fn test_shared_array_ptr() { + mut a := AA{} + b := 3 + lock a.a { + a.a << &b + } +}