live: fix -live compilation && make live_test.v not swallow segfault errors

pull/5086/head
Delyan Angelov 2020-05-28 03:20:55 +03:00
parent 9cbd9db4e7
commit ae8cc2f433
3 changed files with 18 additions and 18 deletions

View File

@ -20,13 +20,13 @@ pub mut:
reload_time_ms int // how much time the last reload took (compilation + loading) 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 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 recheck_period_ms int = 100 // how often do you want to check for changes
cb_recheck FNLiveReloadCB = 0 // executed periodically cb_recheck FNLiveReloadCB = voidptr(0) // executed periodically
cb_compile_failed FNLiveReloadCB = 0 // executed when a reload compilation failed cb_compile_failed FNLiveReloadCB = voidptr(0) // executed when a reload compilation failed
cb_before FNLiveReloadCB = 0 // executed before a reload try happens cb_before FNLiveReloadCB = voidptr(0) // executed before a reload try happens
cb_after FNLiveReloadCB = 0 // executed after a reload try happened, even if failed cb_after FNLiveReloadCB = voidptr(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_before FNLiveReloadCB = voidptr(0) // executed before lib reload, in the mutex section
cb_locked_after FNLiveReloadCB = 0 // executed after lib reload, in the mutex section cb_locked_after FNLiveReloadCB = voidptr(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 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 // 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. // started, and the structure LiveReloadInfo will not get updated.
// All its fields will be 0, but still safe to access. // All its fields will be 0, but still safe to access.
mut x := &LiveReloadInfo{} mut x := &LiveReloadInfo{}
C.g_live_info = voidptr(x) p := &u64(&C.g_live_info)
unsafe { *p = &u64(x) }
return x return x
} }

View File

@ -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}') elog(r,'> compile_and_reload_shared_lib compiled: ${new_lib_path}')
load_lib(r, 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 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) C.pthread_mutex_lock(r.live_fn_mutex)
elog(r,'live mutex locked') elog(r,'live mutex locked')
// //
if r.cb_locked_before != 0 { if r.cb_locked_before != voidptr(0) {
r.cb_locked_before( r ) r.cb_locked_before( r )
} }
// //
protected_load_lib(r, new_lib_path) protected_load_lib(r, new_lib_path)
// //
r.reloads_ok++ r.reloads_ok++
if r.cb_locked_after != 0 { if r.cb_locked_after != voidptr(0) {
r.cb_locked_after( r ) r.cb_locked_after( r )
} }
// //
@ -130,7 +130,7 @@ fn reloader(r mut live.LiveReloadInfo) {
// elog(r,'reloader, r: $r') // elog(r,'reloader, r: $r')
mut last_ts := os.file_last_mod_unix( r.original ) mut last_ts := os.file_last_mod_unix( r.original )
for { for {
if r.cb_recheck != 0 { if r.cb_recheck != voidptr(0) {
r.cb_recheck( r ) r.cb_recheck( r )
} }
now_ts := os.file_last_mod_unix( r.original ) now_ts := os.file_last_mod_unix( r.original )
@ -138,19 +138,19 @@ fn reloader(r mut live.LiveReloadInfo) {
r.reloads++ r.reloads++
last_ts = now_ts last_ts = now_ts
r.last_mod_ts = last_ts r.last_mod_ts = last_ts
if r.cb_before != 0 { if r.cb_before != voidptr(0) {
r.cb_before( r ) r.cb_before( r )
} }
compile_and_reload_shared_lib(r) or { 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 ) r.cb_compile_failed( r )
} }
if r.cb_after != 0 { if r.cb_after != voidptr(0) {
r.cb_after( r ) r.cb_after( r )
} }
continue continue
} }
if r.cb_after != 0 { if r.cb_after != voidptr(0) {
r.cb_after( r ) r.cb_after( r )
} }
} }

View File

@ -130,8 +130,7 @@ fn testsuite_end() {
vprintln('output: $output_file') vprintln('output: $output_file')
vprintln('---------------------------------------------------------------------------') vprintln('---------------------------------------------------------------------------')
output_lines := os.read_lines(output_file) or { output_lines := os.read_lines(output_file) or {
eprintln('could not read $output_file, error: $err') panic('could not read $output_file, error: $err')
return
} }
mut histogram := map[string]int mut histogram := map[string]int
for line in output_lines { for line in output_lines {