From 26785668c0aedc48821dfc01b46845f1b8aae487 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 15 Nov 2020 15:09:35 +0100 Subject: [PATCH] autofree: more tests; gg: fix draw_circle with hidpi --- .github/workflows/ci.yml | 2 -- vlib/gg/gg.v | 10 ++++++++-- vlib/gg/text_rendering.v | 5 +++++ vlib/v/gen/cgen.v | 5 +++++ vlib/v/tests/valgrind/1.strings_and_arrays.v | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7d6063314..51277c7390 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -211,8 +211,6 @@ jobs: # run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd .. # - name: Build vpm # run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd .. -# - name: Build V UI examples -# run: ./v install ui && git clone --depth 1 https://github.com/vlang/ui && cd ui && ../v examples/calculator.v && cd .. # - name: Freestanding # run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v - name: v self compilation diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 6e97ade4f1..37cbedade3 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -308,10 +308,16 @@ pub fn (ctx &Context) draw_circle_line(x f32, y f32, r int, segments int, c gx.C sgl.end() } -pub fn (ctx &Context) draw_circle(x f32, y f32, r int, c gx.Color) { +pub fn (ctx &Context) draw_circle(x f32, y f32, r f32, c gx.Color) { + if ctx.scale == 1 { ctx.draw_circle_with_segments(x,y,r,10, c) + } + else { + ctx.draw_circle_with_segments(x*f32(ctx.scale),y*f32(ctx.scale),r*ctx.scale,10, c) + + } } -pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r int, segments int, c gx.Color) { +pub fn (ctx &Context) draw_circle_with_segments(x f32, y f32, r f32, segments int, c gx.Color) { if c.a != 255 { sgl.load_pipeline(ctx.timage_pip) } diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 500d7bcad4..6f866b29c5 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -217,6 +217,11 @@ fn get_font_path_variant(font_path string, variant FontVariant) string { } else { fpath += '-bold' } + $if macos { + if os.exists('SFNS-bold') { + fpath = 'SFNS-bold' + } + } } .italic { if fpath.ends_with('-Regular') { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 2c9419db26..9a73b6fc22 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1025,6 +1025,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { // g.autofree_call_pregen(node.exprs[0] as ast.CallExpr) } // g.autofree_scope_vars(node.pos.pos - 1) + g.writeln('// ast.Return free_end') // g.write_autofree_stmts_when_needed(node) } g.return_statement(node, af) @@ -3785,6 +3786,10 @@ fn (mut g Gen) return_statement(node ast.Return, af bool) { defer { g.inside_return = false } + if af { + tmp := g.new_tmp_var() + g.writeln('// $tmp = ...') + } // got to do a correct check for multireturn sym := g.table.get_type_symbol(g.fn_decl.return_type) fn_return_is_multi := sym.kind == .multi_return diff --git a/vlib/v/tests/valgrind/1.strings_and_arrays.v b/vlib/v/tests/valgrind/1.strings_and_arrays.v index f49d885546..6e89ed5664 100644 --- a/vlib/v/tests/valgrind/1.strings_and_arrays.v +++ b/vlib/v/tests/valgrind/1.strings_and_arrays.v @@ -240,6 +240,22 @@ fn free_before_return_bool() bool { return true } +struct User { + name string + age int +} + +fn free_array_except_returned_element() { + user := get_user() + println(user) +} + +fn get_user() User { + users := [User{'Peter', 25}, User{'Alice', 21}] + user := users[0] // has to be cloned, since `users` are going to be freed at the end of the function + return user +} + fn main() { println('start') simple() @@ -262,6 +278,7 @@ fn main() { // free_before_return_bool() // free_map() // loop_map() + // free_array_except_returned_element() println('end') }