From cee00a3551eb9e0386cf01362393b0fe35badccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kr=C3=BCger?= <45282134+UweKrueger@users.noreply.github.com> Date: Wed, 3 Feb 2021 23:25:01 +0100 Subject: [PATCH] cgen: create enclosing block on C side for V `lock` blocks (#8538) --- vlib/v/gen/c/cgen.v | 4 +++- vlib/v/tests/shared_arg_test.v | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 3ddc927977..4616619c86 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3448,7 +3448,9 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) { g.writeln('\t\tsync__RwMutex_lock((sync__RwMutex*)_arr_$mtxs[$mtxs]);') g.writeln('}') } + g.writeln('/*lock*/ {') g.stmts(node.stmts) + g.writeln('}') if node.lockeds.len == 0 { // this should not happen } else if node.lockeds.len == 1 { @@ -3465,7 +3467,7 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) { g.writeln('\t\tsync__RwMutex_runlock((sync__RwMutex*)_arr_$mtxs[$mtxs]);') g.writeln('\telse') g.writeln('\t\tsync__RwMutex_unlock((sync__RwMutex*)_arr_$mtxs[$mtxs]);') - g.writeln('}') + g.write('}') } } diff --git a/vlib/v/tests/shared_arg_test.v b/vlib/v/tests/shared_arg_test.v index 43ffa513eb..e9a43fb817 100644 --- a/vlib/v/tests/shared_arg_test.v +++ b/vlib/v/tests/shared_arg_test.v @@ -48,12 +48,12 @@ fn test_shared_as_value() { assert v == 35 } rlock m { - w := m_val(m) - assert w == -3.125 + u := m_val(m) + assert u == -3.125 } lock a { - x := a_val(a) - assert x == 4 + u := a_val(a) + assert u == 4 } }