mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-02 22:21:15 -03:00
Teach fish how to push and pop blocks even in the face of no_exec. All tests finally pass.
https://github.com/fish-shell/fish-shell/issues/624
This commit is contained in:
36
exec.cpp
36
exec.cpp
@@ -538,6 +538,37 @@ static bool can_use_posix_spawn_for_job(const job_t *job, const process_t *proce
|
||||
return result;
|
||||
}
|
||||
|
||||
/* What exec does if no_exec is set. This only has to handle block pushing and popping. See #624. */
|
||||
static void exec_no_exec(parser_t &parser, const job_t *job)
|
||||
{
|
||||
/* Hack hack hack. If this is an 'end' job, then trigger a pop. If this is a job that would create a block, trigger a push. See #624 */
|
||||
const process_t *p = job->first_process;
|
||||
if (p && p->type == INTERNAL_BUILTIN)
|
||||
{
|
||||
const wchar_t *builtin_name_cstr = p->argv0();
|
||||
if (builtin_name_cstr != NULL)
|
||||
{
|
||||
const wcstring builtin_name = builtin_name_cstr;
|
||||
if (contains(builtin_name, L"for", L"function", L"begin", L"switch"))
|
||||
{
|
||||
// The above builtins are the ones that produce an unbalanced block from within their function implementation
|
||||
// This list should be maintained somewhere else
|
||||
parser.push_block(new fake_block_t());
|
||||
}
|
||||
else if (builtin_name == L"end")
|
||||
{
|
||||
if (parser.current_block == NULL || parser.current_block->type() == TOP)
|
||||
{
|
||||
fprintf(stderr, "Warning: not popping the root block\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.pop_block();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void exec(parser_t &parser, job_t *j)
|
||||
{
|
||||
@@ -559,8 +590,10 @@ void exec(parser_t &parser, job_t *j)
|
||||
CHECK(j,);
|
||||
CHECK_BLOCK();
|
||||
|
||||
if (no_exec)
|
||||
if (no_exec) {
|
||||
exec_no_exec(parser, j);
|
||||
return;
|
||||
}
|
||||
|
||||
sigemptyset(&chldset);
|
||||
sigaddset(&chldset, SIGCHLD);
|
||||
@@ -1269,7 +1302,6 @@ void exec(parser_t &parser, job_t *j)
|
||||
p->pid = pid;
|
||||
|
||||
set_child_group(j, p, 0);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user