You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 97b5b79
Browse filesBrowse the repository at this point in the historyBrowse files
autoload: Add subshell scoping to loop detection (re: a410bc4)
@perette reports:
> Korn Shell erroneously reports there is an autoload loop when:
>
> * I have a main program that autoloads a helper function. That
> function is only called during shell captures.
> * That function autoloads a third function.
>
> The first invocation doing a shell capture succeeds. Successive
> ones report "autoload loop" in the helper function.
Analysis: In the referenced commit, I failed to account for loading
functions in virtual (non-forking) subshells, such as command
substitutions ('shell captures'), without them being loaded in the
parent shell envioronment. The loop detection state leaks out of
those subshells, whereas the functions themselves do not.
src/cmd/ksh93/sh/path.c,
src/cmd/ksh93/sh/subshell.c,
src/cmd/ksh93/include/defs.h,
src/cmd/ksh93/include/shell.h:
- Implements subshell scoping for the Cdt tree that keeps track of
the names of functions that are currently being autoloaded. This
works analogously to the subshell scoping for the variable,
function, and hash table trees, but is much simpler, because the
autoload loop detection tree only has nodes without values. The
sh_subloopdetecttree function is used to create a new subshell
tree. The sfaldt field of the subshell data is used to save it
and clean it up when the subshell exits. In funload(), when
adding a note, we now also need to pass the NV_NOSCOPE flag to
nv_search to add it to the subshell tree (if any) and not the
parent tree.
- Fix another problem that I discovered while fixing this. When the
script invoked by autoload contains an error that causes the
shell context to exit, such as an error in a special builtin, the
shell longjmps away from funload(), the state never gets
restored, and there is a memory leak as free() is not called. Fix
this by adding a sh_pushcontext/sigsetjmp procedure of its own so
the shell longjmps back to the correct point in funload() to
restore state correctly before continuing down the longjmp chain.
src/cmd/ksh93/data/msg.c,
src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/sh/xec.c:
- Improve the error message given when an autoloadable function is
not found, by including the name of the not-found function in it.
This fix is by Perette Barella (thanks!).
Resolves: #971
Co-authored-by: Perette Barella <perette@barella.org>
0 commit comments