1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix dumping shared variable (#15615)

This commit is contained in:
yuyi 2022-08-31 15:42:28 +08:00 committed by GitHub
parent 56135dbdbc
commit 64f403e997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -14,7 +14,13 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
} }
dump_fn_name := '_v_dump_expr_$node.cname' + (if node.expr_type.is_ptr() { '_ptr' } else { '' }) dump_fn_name := '_v_dump_expr_$node.cname' + (if node.expr_type.is_ptr() { '_ptr' } else { '' })
g.write(' ${dump_fn_name}(${ctoslit(fpath)}, $line, $sexpr, ') g.write(' ${dump_fn_name}(${ctoslit(fpath)}, $line, $sexpr, ')
g.expr(node.expr) if node.expr_type.has_flag(.shared_f) {
g.write('&')
g.expr(node.expr)
g.write('->val')
} else {
g.expr(node.expr)
}
g.write(' )') g.write(' )')
} }
@ -27,7 +33,7 @@ fn (mut g Gen) dump_expr_definitions() {
_, str_method_expects_ptr, _ := dump_sym.str_method_info() _, str_method_expects_ptr, _ := dump_sym.str_method_info()
is_ptr := ast.Type(dump_type).is_ptr() is_ptr := ast.Type(dump_type).is_ptr()
deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type) deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type)
to_string_fn_name := g.get_str_fn(dump_type) to_string_fn_name := g.get_str_fn(ast.Type(dump_type).clear_flag(.shared_f))
ptr_asterisk := if is_ptr { '*' } else { '' } ptr_asterisk := if is_ptr { '*' } else { '' }
mut str_dumparg_type := '$cname$ptr_asterisk' mut str_dumparg_type := '$cname$ptr_asterisk'
if dump_sym.kind == .function { if dump_sym.kind == .function {

View File

@ -0,0 +1,3 @@
[vlib/v/tests/inout/dump_shared_arg.vv:12] inst: &AtomicStruct{
a: 1
}

View File

@ -0,0 +1,14 @@
module main
struct AtomicStruct {
a int
}
fn main() {
shared inst := AtomicStruct{
a: 1
}
lock inst {
dump(inst)
}
}