commit bash-20141031 snapshot

This commit is contained in:
Chet Ramey
2014-11-03 14:32:12 -05:00
parent e0722a04ec
commit f3aad56dce
52 changed files with 55059 additions and 2492 deletions
+29 -1
View File
@@ -83,6 +83,8 @@ extern int errno;
#include "builtins/common.h"
#include "builtins/builtext.h" /* list of builtins */
#include "builtins/getopt.h"
#include <glob/strmatch.h>
#include <tilde/tilde.h>
@@ -4443,6 +4445,22 @@ execute_builtin (builtin, words, flags, subshell)
return (result);
}
static void
maybe_restore_getopt_state (gs)
sh_getopt_state_t *gs;
{
SHELL_VAR *v;
/* If we have a local copy of OPTIND and it's at the right (current)
context, then we restore getopt's internal state. If not, we just
let it go. We know there is a local OPTIND if gs->gs_flags & 1.
This is set below in execute_function() before the context is run. */
if (gs->gs_flags & 1)
sh_getopt_restore_istate (gs);
else
free (gs);
}
static int
execute_function (var, words, flags, fds_to_close, async, subshell)
SHELL_VAR *var;
@@ -4462,6 +4480,7 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
#endif
FUNCTION_DEF *shell_fn;
char *sfile, *t;
sh_getopt_state_t *gs;
USE_VAR(fc);
@@ -4482,17 +4501,21 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
if (tc && (flags & CMD_IGNORE_RETURN))
tc->flags |= CMD_IGNORE_RETURN;
gs = sh_getopt_save_istate ();
if (subshell == 0)
{
begin_unwind_frame ("function_calling");
push_context (var->name, subshell, temporary_env);
/* This has to be before the pop_context(), because the unwinding of
local variables may cause the restore of a local declaration of
OPTIND to force a getopts state reset. */
add_unwind_protect (maybe_restore_getopt_state, gs);
add_unwind_protect (pop_context, (char *)NULL);
unwind_protect_int (line_number);
unwind_protect_int (return_catch_flag);
unwind_protect_jmp_buf (return_catch);
add_unwind_protect (dispose_command, (char *)tc);
unwind_protect_pointer (this_shell_function);
unwind_protect_int (loop_level);
unwind_protect_int (funcnest);
unwind_protect_int (loop_level);
}
@@ -4638,6 +4661,11 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
if (debugging_mode)
pop_args ();
/* If we have a local copy of OPTIND, note it in the saved getopts state. */
nfv = find_variable ("OPTIND");
if (nfv && nfv->context == variable_context)
gs->gs_flags |= 1;
if (subshell == 0)
run_unwind_frame ("function_calling");