Skip to content

Commit

Permalink
term.ui: fix notices about uninitialized pointers (#19528)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertzui123 authored Oct 8, 2023
1 parent 4f85b49 commit 7535539
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
35 changes: 15 additions & 20 deletions vlib/term/ui/input.v
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ pub mut:

pub struct Config {
user_data voidptr
init_fn fn (voidptr)
frame_fn fn (voidptr)
cleanup_fn fn (voidptr)
event_fn fn (&Event, voidptr)
fail_fn fn (string)
init_fn ?fn (voidptr)
frame_fn ?fn (voidptr)
cleanup_fn ?fn (voidptr)
event_fn ?fn (&Event, voidptr)
fail_fn ?fn (string)

buffer_size int = 256
frame_rate int = 30
Expand All @@ -206,35 +206,30 @@ pub struct Config {

[inline]
fn (ctx &Context) init() {
if ctx.cfg.init_fn != unsafe { nil } {
ctx.cfg.init_fn(ctx.cfg.user_data)
}
f := ctx.cfg.init_fn or { return }
f(ctx.cfg.user_data)
}

[inline]
fn (ctx &Context) frame() {
if ctx.cfg.frame_fn != unsafe { nil } {
ctx.cfg.frame_fn(ctx.cfg.user_data)
}
f := ctx.cfg.frame_fn or { return }
f(ctx.cfg.user_data)
}

[inline]
fn (ctx &Context) cleanup() {
if ctx.cfg.cleanup_fn != unsafe { nil } {
ctx.cfg.cleanup_fn(ctx.cfg.user_data)
}
f := ctx.cfg.cleanup_fn or { return }
f(ctx.cfg.user_data)
}

[inline]
fn (ctx &Context) fail(error string) {
if ctx.cfg.fail_fn != unsafe { nil } {
ctx.cfg.fail_fn(error)
}
f := ctx.cfg.fail_fn or { return }
f(error)
}

[inline]
fn (ctx &Context) event(event &Event) {
if ctx.cfg.event_fn != unsafe { nil } {
ctx.cfg.event_fn(event, ctx.cfg.user_data)
}
f := ctx.cfg.event_fn or { return }
f(event, ctx.cfg.user_data)
}
2 changes: 1 addition & 1 deletion vlib/term/ui/input_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn (mut ctx Context) run() ! {
}
if !ctx.paused {
sw.restart()
if ctx.cfg.event_fn != unsafe { nil } {
if ctx.cfg.event_fn != none {
ctx.parse_events()
}
ctx.frame()
Expand Down
2 changes: 1 addition & 1 deletion vlib/term/ui/termios_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ fn (mut ctx Context) termios_loop() {
}
if !ctx.paused {
sw.restart()
if ctx.cfg.event_fn != unsafe { nil } {
if ctx.cfg.event_fn != none {
unsafe {
len := C.read(C.STDIN_FILENO, &u8(ctx.read_buf.data) + ctx.read_buf.len,
ctx.read_buf.cap - ctx.read_buf.len)
Expand Down

0 comments on commit 7535539

Please sign in to comment.