From ae8cc2f433a9fb7b01687d43535c31aecd1d1e57 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 28 May 2020 03:20:55 +0300 Subject: [PATCH] live: fix -live compilation && make live_test.v not swallow segfault errors --- vlib/live/common.v | 17 +++++++++-------- vlib/live/executable/reloader.v | 16 ++++++++-------- vlib/v/tests/live_test.v | 3 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vlib/live/common.v b/vlib/live/common.v index 374d8d78e8..828cf7e607 100644 --- a/vlib/live/common.v +++ b/vlib/live/common.v @@ -20,13 +20,13 @@ pub mut: reload_time_ms int // how much time the last reload took (compilation + loading) last_mod_ts int // a timestamp for when the original was last changed recheck_period_ms int = 100 // how often do you want to check for changes - cb_recheck FNLiveReloadCB = 0 // executed periodically - cb_compile_failed FNLiveReloadCB = 0 // executed when a reload compilation failed - cb_before FNLiveReloadCB = 0 // executed before a reload try happens - cb_after FNLiveReloadCB = 0 // executed after a reload try happened, even if failed - cb_locked_before FNLiveReloadCB = 0 // executed before lib reload, in the mutex section - cb_locked_after FNLiveReloadCB = 0 // executed after lib reload, in the mutex section - user_ptr voidptr = 0 // you can set it to anything, then retrieve it in the cb_ fns + cb_recheck FNLiveReloadCB = voidptr(0) // executed periodically + cb_compile_failed FNLiveReloadCB = voidptr(0) // executed when a reload compilation failed + cb_before FNLiveReloadCB = voidptr(0) // executed before a reload try happens + cb_after FNLiveReloadCB = voidptr(0) // executed after a reload try happened, even if failed + cb_locked_before FNLiveReloadCB = voidptr(0) // executed before lib reload, in the mutex section + cb_locked_after FNLiveReloadCB = voidptr(0) // executed after lib reload, in the mutex section + user_ptr voidptr = voidptr(0) // you can set it to anything, then retrieve it in the cb_ fns } // LiveReloadInfo.live_linkfn should be called by the reloader @@ -56,6 +56,7 @@ pub fn info() &LiveReloadInfo { // started, and the structure LiveReloadInfo will not get updated. // All its fields will be 0, but still safe to access. mut x := &LiveReloadInfo{} - C.g_live_info = voidptr(x) + p := &u64(&C.g_live_info) + unsafe { *p = &u64(x) } return x } diff --git a/vlib/live/executable/reloader.v b/vlib/live/executable/reloader.v index af16eb52d2..53858ae068 100644 --- a/vlib/live/executable/reloader.v +++ b/vlib/live/executable/reloader.v @@ -55,7 +55,7 @@ fn compile_and_reload_shared_lib(r mut live.LiveReloadInfo) ?bool { } elog(r,'> compile_and_reload_shared_lib compiled: ${new_lib_path}') load_lib(r, new_lib_path ) - r.reload_time_ms = sw.elapsed().milliseconds() + r.reload_time_ms = int(sw.elapsed().milliseconds()) return true } @@ -92,14 +92,14 @@ fn load_lib(r mut live.LiveReloadInfo, new_lib_path string) { C.pthread_mutex_lock(r.live_fn_mutex) elog(r,'live mutex locked') // - if r.cb_locked_before != 0 { + if r.cb_locked_before != voidptr(0) { r.cb_locked_before( r ) } // protected_load_lib(r, new_lib_path) // r.reloads_ok++ - if r.cb_locked_after != 0 { + if r.cb_locked_after != voidptr(0) { r.cb_locked_after( r ) } // @@ -130,7 +130,7 @@ fn reloader(r mut live.LiveReloadInfo) { // elog(r,'reloader, r: $r') mut last_ts := os.file_last_mod_unix( r.original ) for { - if r.cb_recheck != 0 { + if r.cb_recheck != voidptr(0) { r.cb_recheck( r ) } now_ts := os.file_last_mod_unix( r.original ) @@ -138,19 +138,19 @@ fn reloader(r mut live.LiveReloadInfo) { r.reloads++ last_ts = now_ts r.last_mod_ts = last_ts - if r.cb_before != 0 { + if r.cb_before != voidptr(0) { r.cb_before( r ) } compile_and_reload_shared_lib(r) or { - if r.cb_compile_failed != 0 { + if r.cb_compile_failed != voidptr(0) { r.cb_compile_failed( r ) } - if r.cb_after != 0 { + if r.cb_after != voidptr(0) { r.cb_after( r ) } continue } - if r.cb_after != 0 { + if r.cb_after != voidptr(0) { r.cb_after( r ) } } diff --git a/vlib/v/tests/live_test.v b/vlib/v/tests/live_test.v index 23230200d3..b7debc74c7 100755 --- a/vlib/v/tests/live_test.v +++ b/vlib/v/tests/live_test.v @@ -130,8 +130,7 @@ fn testsuite_end() { vprintln('output: $output_file') vprintln('---------------------------------------------------------------------------') output_lines := os.read_lines(output_file) or { - eprintln('could not read $output_file, error: $err') - return + panic('could not read $output_file, error: $err') } mut histogram := map[string]int for line in output_lines {