From 37583b04b49046d5c2683adc4de72cdff993ea74 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 14 Nov 2022 17:25:39 +0300 Subject: [PATCH] gg: make create_image's receiver immutable --- vlib/gg/gg.c.v | 3 +-- vlib/gg/image.c.v | 16 +++++++++++----- vlib/pg/pg.v | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 863ea0445b..ad8f05870e 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -295,8 +295,7 @@ fn gg_init_sokol_window(user_data voidptr) { } } -fn gg_frame_fn(user_data voidptr) { - mut ctx := unsafe { &Context(user_data) } +fn gg_frame_fn(mut ctx Context) { ctx.frame++ if ctx.config.frame_fn == unsafe { nil } { return diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index a62e24310f..39db8f0b6b 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -25,8 +25,8 @@ pub mut: } // create_image creates an `Image` from `file`. -// TODO return ?Image -pub fn (mut ctx Context) create_image(file string) Image { +// TODO return !Image +pub fn (ctx &Context) create_image(file string) Image { // println('\ncreate_image("$file")') if !os.exists(file) { return Image{} @@ -38,7 +38,9 @@ pub fn (mut ctx Context) create_image(file string) Image { // println('created macos image: $img.path w=$img.width') // C.printf('p = %p\n', img.data) img.id = ctx.image_cache.len - ctx.image_cache << img + unsafe { + ctx.image_cache << img + } return img } } @@ -56,12 +58,16 @@ pub fn (mut ctx Context) create_image(file string) Image { path: file id: ctx.image_cache.len } - ctx.image_cache << img + unsafe { + ctx.image_cache << img + } return img } mut img := create_image(file) img.id = ctx.image_cache.len - ctx.image_cache << img + unsafe { + ctx.image_cache << img + } return img } diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index 30944913e1..5645126f2e 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -31,8 +31,8 @@ struct C.PGResult { pub struct Config { pub: - host string - port int = 5432 + host string = 'localhost' + port int = 5432 user string password string dbname string