mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 09:00:26 +00:00
Fix #638 - update fiber status in certain cases.
This fixes a regression from changes to janet_try. In some cases, we would not update the status of a fiber when signaling, which left the fiber's status as whatever it had previously. This could lead to strange control flow issues.
This commit is contained in:
parent
742469a8bc
commit
c68264802a
54
jpm
54
jpm
@ -23,12 +23,12 @@
|
|||||||
|
|
||||||
# Overriden on some installs.
|
# Overriden on some installs.
|
||||||
# To configure this script, replace the code between
|
# To configure this script, replace the code between
|
||||||
# the START and END comments and define a function
|
# the START and END comments and define a function
|
||||||
# (install-paths) that gives the the default paths
|
# (install-paths) that gives the the default paths
|
||||||
# to use. Trailing directory separator not expected.
|
# to use. Trailing directory separator not expected.
|
||||||
#
|
#
|
||||||
# Example.
|
# Example.
|
||||||
#
|
#
|
||||||
# (defn- install-paths []
|
# (defn- install-paths []
|
||||||
# {:headerpath "/usr/local/include/janet"
|
# {:headerpath "/usr/local/include/janet"
|
||||||
# :libpath "/usr/local/lib/janet"
|
# :libpath "/usr/local/lib/janet"
|
||||||
@ -169,9 +169,7 @@
|
|||||||
[& args]
|
[& args]
|
||||||
(if (dyn :verbose)
|
(if (dyn :verbose)
|
||||||
(print ;(interpose " " args)))
|
(print ;(interpose " " args)))
|
||||||
(def res (os/execute args :p))
|
(os/execute args :px))
|
||||||
(unless (zero? res)
|
|
||||||
(error (string "command exited with status " res))))
|
|
||||||
|
|
||||||
(defn copy
|
(defn copy
|
||||||
"Copy a file or directory recursively from one location to another."
|
"Copy a file or directory recursively from one location to another."
|
||||||
@ -1424,26 +1422,30 @@ Flags are:
|
|||||||
"load-lockfile" load-lockfile
|
"load-lockfile" load-lockfile
|
||||||
"quickbin" quickbin})
|
"quickbin" quickbin})
|
||||||
|
|
||||||
(def- args (tuple/slice (dyn :args) 1))
|
(defn- main
|
||||||
(def- len (length args))
|
"Script entry."
|
||||||
(var i :private 0)
|
[& argv]
|
||||||
|
|
||||||
# Get flags
|
(def- args (tuple/slice argv 1))
|
||||||
(while (< i len)
|
(def- len (length args))
|
||||||
(if-let [m (peg/match argpeg (args i))]
|
(var i :private 0)
|
||||||
(if (= 2 (length m))
|
|
||||||
(let [[key value] m]
|
|
||||||
(setdyn (keyword key) value))
|
|
||||||
(setdyn (keyword (m 0)) true))
|
|
||||||
(break))
|
|
||||||
(++ i))
|
|
||||||
|
|
||||||
# Run subcommand
|
# Get flags
|
||||||
(if (= i len)
|
(while (< i len)
|
||||||
(help)
|
(if-let [m (peg/match argpeg (args i))]
|
||||||
(do
|
(if (= 2 (length m))
|
||||||
(if-let [com (subcommands (args i))]
|
(let [[key value] m]
|
||||||
(com ;(tuple/slice args (+ i 1)))
|
(setdyn (keyword key) value))
|
||||||
(do
|
(setdyn (keyword (m 0)) true))
|
||||||
(print "invalid command " (args i))
|
(break))
|
||||||
(help)))))
|
(++ i))
|
||||||
|
|
||||||
|
# Run subcommand
|
||||||
|
(if (= i len)
|
||||||
|
(help)
|
||||||
|
(do
|
||||||
|
(if-let [com (subcommands (args i))]
|
||||||
|
(com ;(tuple/slice args (+ i 1)))
|
||||||
|
(do
|
||||||
|
(print "invalid command " (args i))
|
||||||
|
(help))))))
|
||||||
|
@ -1378,6 +1378,7 @@ static JanetSignal janet_continue_no_check(JanetFiber *fiber, Janet in, Janet *o
|
|||||||
if (janet_vm_root_fiber == fiber) janet_vm_root_fiber = NULL;
|
if (janet_vm_root_fiber == fiber) janet_vm_root_fiber = NULL;
|
||||||
if (sig != JANET_SIGNAL_OK && !(child->flags & (1 << sig))) {
|
if (sig != JANET_SIGNAL_OK && !(child->flags & (1 << sig))) {
|
||||||
*out = in;
|
*out = in;
|
||||||
|
janet_fiber_set_status(fiber, sig);
|
||||||
return sig;
|
return sig;
|
||||||
}
|
}
|
||||||
/* Check if we need any special handling for certain opcodes */
|
/* Check if we need any special handling for certain opcodes */
|
||||||
@ -1417,23 +1418,23 @@ static JanetSignal janet_continue_no_check(JanetFiber *fiber, Janet in, Janet *o
|
|||||||
|
|
||||||
/* Save global state */
|
/* Save global state */
|
||||||
JanetTryState tstate;
|
JanetTryState tstate;
|
||||||
JanetSignal signal = janet_try(&tstate);
|
JanetSignal sig = janet_try(&tstate);
|
||||||
if (!signal) {
|
if (!sig) {
|
||||||
/* Normal setup */
|
/* Normal setup */
|
||||||
if (janet_vm_root_fiber == NULL) janet_vm_root_fiber = fiber;
|
if (janet_vm_root_fiber == NULL) janet_vm_root_fiber = fiber;
|
||||||
janet_vm_fiber = fiber;
|
janet_vm_fiber = fiber;
|
||||||
janet_fiber_set_status(fiber, JANET_STATUS_ALIVE);
|
janet_fiber_set_status(fiber, JANET_STATUS_ALIVE);
|
||||||
signal = run_vm(fiber, in);
|
sig = run_vm(fiber, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore */
|
/* Restore */
|
||||||
if (janet_vm_root_fiber == fiber) janet_vm_root_fiber = NULL;
|
if (janet_vm_root_fiber == fiber) janet_vm_root_fiber = NULL;
|
||||||
janet_fiber_set_status(fiber, signal);
|
janet_fiber_set_status(fiber, sig);
|
||||||
janet_restore(&tstate);
|
janet_restore(&tstate);
|
||||||
fiber->last_value = tstate.payload;
|
fiber->last_value = tstate.payload;
|
||||||
*out = tstate.payload;
|
*out = tstate.payload;
|
||||||
|
|
||||||
return signal;
|
return sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enter the main vm loop */
|
/* Enter the main vm loop */
|
||||||
|
@ -146,4 +146,18 @@
|
|||||||
# os/execute with environment variables
|
# os/execute with environment variables
|
||||||
(assert (= 0 (os/execute [(dyn :executable) "-e" "(+ 1 2 3)"] :pe {"HELLO" "WORLD"})) "os/execute with env")
|
(assert (= 0 (os/execute [(dyn :executable) "-e" "(+ 1 2 3)"] :pe {"HELLO" "WORLD"})) "os/execute with env")
|
||||||
|
|
||||||
|
# Regression #638
|
||||||
|
(assert
|
||||||
|
(= [true :caught]
|
||||||
|
(protect
|
||||||
|
(try
|
||||||
|
(do
|
||||||
|
(ev/sleep 0)
|
||||||
|
(with-dyns []
|
||||||
|
(ev/sleep 0)
|
||||||
|
(error "oops")))
|
||||||
|
([err] :caught))))
|
||||||
|
"regression #638")
|
||||||
|
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user