commit bash-20160930 snapshot

This commit is contained in:
Chet Ramey
2016-10-19 15:13:16 -04:00
parent 61c476d20d
commit 64a7a6249f
21 changed files with 949 additions and 1633 deletions
+61
View File
@@ -11846,3 +11846,64 @@ jobs.c
SIGINT and sourcelevel != 0, act as if we received the SIGINT so the
file sourcing can be terminated. Reported by PePa
<peterkelly@passchier.net>
9/26
----
subst.c
- read_comsub: only warn once for null bytes in command substitution
output, instead of once for every null byte
arrayfunc.c
- array_variable_part: now takes a `flags' argument; changed all callers
to initially pass 0
- array_variable_name: now takes a `flags' argument; changed all callers
to initially pass 0
- array_variable_name: pass `flags' argument to skipsubscript instead
of just passing 0
arrayfunc.h
- array_variable_{name,part}: added new argument to prototypes
9/29
----
bashline.c
- bash_directory_completion_hook: don't bother to try and expand a
${ or $( that isn't complete; expand_prompt_string will complain.
Fixes reports from John Passaro <john.a.passaro@gmail.com> and
Valentin Bajrami <valentin.bajrami@gmail.com>
lib/readline/history.c
- _hs_append_history_line: use a strategy that attempts to avoid
realloc copying memory to a newly-allocated block if the history
line we're appending to gets `too long' (currently 256 bytes).
We reallocate in powers of 2 starting at 512, and rely on realloc
not allocating a new block and copying into it if the size is the
same as the last call to realloc. Addresses issue raised by
Hubert Schmid <h.schmid@gmx.de>
trap.h
- check_signals: new extern declaration
- trapped_signal_received: new extern declaration
builtins/read.def
- read_builtin: if one of the zread* functions returns < 0 (which
usually only happens in Posix mode), make sure we call check_signals()
before eventually calling run_pending_traps() because zread() isn't
going to call it
- include trap.h for correct extern functions and variable declarations
lib/sh/zread.c
- zread: if executing a builtin, call check_signals_and_traps() for
backwards compatibility. If not, call check_signals() only, because
we don't want to run traps during, for instance, reading command
substitution output. Fixes race condition bug reported by Luiz Angelo
Daros de Luca <luizluca@gmail.com>
9/30
----
subst.c
- command_substitute: reset parse_and_execute_level to 0 in the child
process, since it's independent of the other parse_and_execute
calls. Adds command substitution inside other parse_and_execute
calls optimizations to suppress forks, as suggested by
Martijn Dekker <martijn@inlv.org>
+9 -7
View File
@@ -282,7 +282,7 @@ assign_array_element (name, value, flags)
int sublen;
SHELL_VAR *entry, *nv;
vname = array_variable_name (name, &sub, &sublen);
vname = array_variable_name (name, 0, &sub, &sublen);
if (vname == 0)
return ((SHELL_VAR *)NULL);
@@ -949,8 +949,9 @@ array_expand_index (var, s, len)
in *SUBP. If LENP is non-null, the length of the subscript is returned
in *LENP. This returns newly-allocated memory. */
char *
array_variable_name (s, subp, lenp)
array_variable_name (s, flags, subp, lenp)
const char *s;
int flags;
char **subp;
int *lenp;
{
@@ -967,7 +968,7 @@ array_variable_name (s, subp, lenp)
return ((char *)NULL);
}
ind = t - s;
ni = skipsubscript (s, ind, 0);
ni = skipsubscript (s, ind, flags); /* XXX - was 0 not flags */
if (ni <= ind + 1 || s[ni] != ']')
{
err_badarraysub (s);
@@ -994,15 +995,16 @@ array_variable_name (s, subp, lenp)
non-null, return a pointer to the start of the subscript in *SUBP.
If LENP is non-null, the length of the subscript is returned in *LENP. */
SHELL_VAR *
array_variable_part (s, subp, lenp)
array_variable_part (s, flags, subp, lenp)
const char *s;
int flags;
char **subp;
int *lenp;
{
char *t;
SHELL_VAR *var;
t = array_variable_name (s, subp, lenp);
t = array_variable_name (s, flags, subp, lenp);
if (t == 0)
return ((SHELL_VAR *)NULL);
var = find_variable (t); /* XXX - handle namerefs here? */
@@ -1044,7 +1046,7 @@ array_value_internal (s, quoted, flags, rtype, indp)
WORD_LIST *l;
SHELL_VAR *var;
var = array_variable_part (s, &t, &len);
var = array_variable_part (s, 0, &t, &len);
/* Expand the index, even if the variable doesn't exist, in case side
effects are needed, like ${w[i++]} where w is unset. */
@@ -1184,7 +1186,7 @@ array_keys (s, quoted)
WORD_LIST *l;
SHELL_VAR *var;
var = array_variable_part (s, &t, &len);
var = array_variable_part (s, 0, &t, &len);
/* [ */
if (var == 0 || ALL_ELEMENT_SUB (t[0]) == 0 || t[1] != ']')
+2 -2
View File
@@ -65,8 +65,8 @@ extern char *get_array_value __P((const char *, int, int *, arrayind_t *));
extern char *array_keys __P((char *, int));
extern char *array_variable_name __P((const char *, char **, int *));
extern SHELL_VAR *array_variable_part __P((const char *, char **, int *));
extern char *array_variable_name __P((const char *, int, char **, int *));
extern SHELL_VAR *array_variable_part __P((const char *, int, char **, int *));
#else
+11
View File
@@ -3234,6 +3234,17 @@ bash_directory_completion_hook (dirname)
closer = '}';
else
nextch = 0;
if (closer)
{
int p;
char delims[2];
delims[0] = closer; delims[1] = 0;
p = skip_to_delim (t, t - local_dirname + 1, delims, SD_NOJMP|SD_COMPLETE);
if (t[p] != closer)
should_expand_dirname = 0;
}
}
else if (local_dirname[0] == '~')
should_expand_dirname = '~';
+3 -2
View File
@@ -260,7 +260,7 @@ show_desc (name, i)
char *name;
int i;
{
register int j;
register int j, r;
char **doc, *line;
int fd, usefile;
@@ -272,8 +272,9 @@ show_desc (name, i)
fd = open_helpfile (doc[0]);
if (fd < 0)
return;
zmapfd (fd, &line, doc[0]);
r = zmapfd (fd, &line, doc[0]);
close (fd);
/* XXX - handle errors if zmapfd returns < 0 */
}
else
line = doc ? doc[0] : (char *)NULL;
+4 -14
View File
@@ -93,6 +93,7 @@ $END
#include "../shell.h"
#include "common.h"
#include "bashgetopt.h"
#include "trap.h"
#include <shtty.h>
@@ -111,10 +112,7 @@ $END
extern int errno;
#endif
extern void run_pending_traps __P((void));
extern int posixly_correct;
extern int trapped_signal_received;
struct ttsave
{
@@ -152,9 +150,8 @@ static struct ttsave termsave;
avoids problems with the semi-tricky stuff we do with the xfree of
input_string at the top of the unwind-protect list (see below). */
/* Set a flag that CHECK_ALRM can check. This relies on zread calling
trap.c:check_signals_and_traps(), which knows about sigalrm_seen and
alrmbuf. */
/* Set a flag that CHECK_ALRM can check. This relies on zread or read_builtin
calling trap.c:check_signals(), which knows about sigalrm_seen and alrmbuf. */
static sighandler
sigalrm (s)
int s;
@@ -573,10 +570,6 @@ read_builtin (list)
print_ps2 = 0;
}
#if 0
if (posixly_correct == 0)
interrupt_immediately++;
#endif
reading = 1;
if (unbuffered_read == 2)
retval = posixly_correct ? zreadintr (fd, &c, 1) : zreadn (fd, &c, nchars - nr);
@@ -585,15 +578,12 @@ read_builtin (list)
else
retval = posixly_correct ? zreadcintr (fd, &c) : zreadc (fd, &c);
reading = 0;
#if 0
if (posixly_correct == 0)
interrupt_immediately--;
#endif
if (retval <= 0)
{
if (retval < 0 && errno == EINTR)
{
check_signals (); /* in case we didn't call zread via zreadc */
lastsig = LASTSIG();
if (lastsig == 0)
lastsig = trapped_signal_received;
+1 -1
View File
@@ -942,7 +942,7 @@ unset_builtin (list)
if (valid_array_reference (nameref_cell (var), 0))
{
tname = savestring (nameref_cell (var));
if (var = array_variable_part (tname, &t, (int *)0))
if (var = array_variable_part (tname, 0, &t, (int *)0))
#if 0
tem = unbind_array_element (var, t, 1); /* XXX new third arg */
#else
+16 -2
View File
@@ -5,12 +5,12 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Fri Aug 26 09:45:10 EDT 2016
.\" Last Change: Tue Sep 27 14:02:28 EDT 2016
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2016 August 26" "GNU Bash 4.4"
.TH BASH 1 "2016 September 27" "GNU Bash 4.4"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
@@ -3455,6 +3455,13 @@ at the start of a name or immediately following a slash
must be matched explicitly, unless the shell option
.B dotglob
is set.
The filenames
.B ``.''
and
.B ``..''
must always be matched explicitly, even if
.B dotglob
is set.
When matching a pathname, the slash character must always be
matched explicitly.
In other cases, the
@@ -9628,6 +9635,13 @@ If set,
.B bash
includes filenames beginning with a `.' in the results of pathname
expansion.
The filenames
.B ``.''
and
.B ``..''
must always be matched explicitly, even if
.B dotglob
is set.
.TP 8
.B execfail
If set, a non-interactive shell will not exit if
+4
View File
@@ -2410,6 +2410,8 @@ without regard to the case of alphabetic characters.
When a pattern is used for filename expansion, the character @samp{.}
at the start of a filename or immediately following a slash
must be matched explicitly, unless the shell option @code{dotglob} is set.
The filenames @samp{.} and @samp{..} must always be matched explicitly,
even if @code{dotglob} is set.
When matching a filename, the slash character must always be
matched explicitly.
In other cases, the @samp{.} character is not treated specially.
@@ -5138,6 +5140,8 @@ if the directory name initially supplied does not exist.
@item dotglob
If set, Bash includes filenames beginning with a `.' in
the results of filename expansion.
The filenames @samp{.} and @samp{..} must always be matched explicitly,
even if @code{dotglob} is set.
@item execfail
If this is set, a non-interactive shell will not exit if
+2 -2
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2016 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Wed Sep 7 17:12:22 EDT 2016
@set LASTCHANGE Tue Sep 27 14:02:09 EDT 2016
@set EDITION 4.4
@set VERSION 4.4
@set UPDATED 7 September 2016
@set UPDATED 27 September 2016
@set UPDATED-MONTH September 2016
+3 -3
View File
@@ -334,7 +334,7 @@ expr_bind_array_element (tok, ind, rhs)
char ibuf[INT_STRLEN_BOUND (arrayind_t) + 1], *istr;
istr = fmtumax (ind, 10, ibuf, sizeof (ibuf), 0);
vname = array_variable_name (tok, (char **)NULL, (int *)NULL);
vname = array_variable_name (tok, 0, (char **)NULL, (int *)NULL);
llen = strlen (vname) + sizeof (ibuf) + 3;
lhs = xmalloc (llen);
@@ -1102,7 +1102,7 @@ expr_streval (tok, e, lvalue)
/* [[[[[ */
#if defined (ARRAY_VARS)
v = (e == ']') ? array_variable_part (tok, (char **)0, (int *)0) : find_variable (tok);
v = (e == ']') ? array_variable_part (tok, 0, (char **)0, (int *)0) : find_variable (tok);
#else
v = find_variable (tok);
#endif
@@ -1110,7 +1110,7 @@ expr_streval (tok, e, lvalue)
if ((v == 0 || invisible_p (v)) && unbound_vars_is_error)
{
#if defined (ARRAY_VARS)
value = (e == ']') ? array_variable_name (tok, (char **)0, (int *)0) : tok;
value = (e == ']') ? array_variable_name (tok, 0, (char **)0, (int *)0) : tok;
#else
value = tok;
#endif
+1 -1
View File
@@ -265,7 +265,7 @@ check_selfref (name, value, flags)
#if defined (ARRAY_VARS)
if (valid_array_reference (value, 0))
{
t = array_variable_name (value, (char **)NULL, (int *)NULL);
t = array_variable_name (value, 0, (char **)NULL, (int *)NULL);
if (t && STREQ (name, t))
{
free (t);
+13 -2
View File
@@ -420,12 +420,23 @@ _hs_append_history_line (which, line)
const char *line;
{
HIST_ENTRY *hent;
size_t newlen, curlen;
size_t newlen, curlen, minlen;
char *newline;
hent = the_history[which];
curlen = strlen (hent->line);
newlen = curlen + strlen (line) + 2;
minlen = curlen + strlen (line) + 2; /* min space needed */
if (curlen > 256) /* XXX - for now */
{
newlen = 512; /* now realloc in powers of 2 */
/* we recalcluate every time; the operations are cheap */
while (newlen < minlen)
newlen <<= 1;
}
else
newlen = minlen;
/* Assume that realloc returns the same pointer and doesn't try a new
alloc/copy if the new size is the same as the one last passed. */
newline = realloc (hent->line, newlen);
if (newline)
{
+9 -14
View File
@@ -37,7 +37,10 @@ extern int errno;
# define SEEK_CUR 1
#endif
extern int executing_builtin;
extern void check_signals_and_traps (void);
extern void check_signals (void);
extern int signal_is_trapped (int);
/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
@@ -50,21 +53,13 @@ zread (fd, buf, len)
{
ssize_t r;
#if 0
#if defined (HAVE_SIGINTERRUPT)
if (signal_is_trapped (SIGCHLD))
siginterrupt (SIGCHLD, 1);
#endif
#endif
while ((r = read (fd, buf, len)) < 0 && errno == EINTR)
check_signals_and_traps (); /* XXX - should it be check_signals()? */
#if 0
#if defined (HAVE_SIGINTERRUPT)
siginterrupt (SIGCHLD, 0);
#endif
#endif
/* XXX - bash-5.0 */
/* We check executing_builtin and run traps here for backwards compatibility */
if (executing_builtin)
check_signals_and_traps (); /* XXX - should it be check_signals()? */
else
check_signals ();
return r;
}
+463 -939
View File
File diff suppressed because it is too large Load Diff
+323 -632
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1382,7 +1382,7 @@ redir_varvalue (redir)
#if defined (ARRAY_VARS)
if (vr = valid_array_reference (w, 0))
{
v = array_variable_part (w, &sub, &len);
v = array_variable_part (w, 0, &sub, &len);
}
else
#endif
@@ -1396,7 +1396,7 @@ redir_varvalue (redir)
{
w = nameref_cell (v);
if (vr = valid_array_reference (w, 0))
v = array_variable_part (w, &sub, &len);
v = array_variable_part (w, 0, &sub, &len);
else
v = find_variable (w);
}
+16 -7
View File
@@ -4931,7 +4931,7 @@ array_remove_pattern (var, pattern, patspec, varname, quoted)
SHELL_VAR *v;
/* compute itype from varname here */
v = array_variable_part (varname, &ret, 0);
v = array_variable_part (varname, 0, &ret, 0);
/* XXX */
if (v && invisible_p (v))
@@ -5198,7 +5198,7 @@ array_transform (xc, var, varname, quoted)
SHELL_VAR *v;
/* compute itype from varname here */
v = array_variable_part (varname, &ret, 0);
v = array_variable_part (varname, 0, &ret, 0);
/* XXX */
if (v && invisible_p (v))
@@ -5932,6 +5932,7 @@ read_comsub (fd, quoted, rflag)
char *istring, buf[128], *bufp, *s;
int istring_index, istring_size, c, tflag, skip_ctlesc, skip_ctlnul;
ssize_t bufn;
int nullbyte;
istring = (char *)NULL;
istring_index = istring_size = bufn = tflag = 0;
@@ -5939,6 +5940,8 @@ read_comsub (fd, quoted, rflag)
for (skip_ctlesc = skip_ctlnul = 0, s = ifs_value; s && *s; s++)
skip_ctlesc |= *s == CTLESC, skip_ctlnul |= *s == CTLNUL;
nullbyte = 0;
/* Read the output of the command through the pipe. This may need to be
changed to understand multibyte characters in the future. */
while (1)
@@ -5957,7 +5960,11 @@ read_comsub (fd, quoted, rflag)
if (c == 0)
{
#if 1
internal_warning ("%s", _("command substitution: ignored null byte in input"));
if (nullbyte == 0)
{
internal_warning ("%s", _("command substitution: ignored null byte in input"));
nullbyte = 1;
}
#endif
continue;
}
@@ -6208,6 +6215,8 @@ command_substitute (string, quoted)
remove_quoted_escapes (string);
startup_state = 2; /* see if we can avoid a fork */
parse_and_execute_level = 0;
/* Give command substitution a place to jump back to on failure,
so we don't go back up to main (). */
result = setjmp_nosigs (top_level);
@@ -6310,7 +6319,7 @@ array_length_reference (s)
HASH_TABLE *h;
SHELL_VAR *var;
var = array_variable_part (s, &t, &len);
var = array_variable_part (s, 0, &t, &len);
/* If unbound variables should generate an error, report one and return
failure. */
@@ -6511,7 +6520,7 @@ parameter_brace_expand_word (name, var_is_special, quoted, pflags, indp)
expand_arrayref:
if (pflags & PF_ASSIGNRHS)
{
var = array_variable_part (name, &tt, (int *)0);
var = array_variable_part (name, 0, &tt, (int *)0);
if (ALL_ELEMENT_SUB (tt[0]) && tt[1] == ']')
{
/* Only treat as double quoted if array variable */
@@ -7168,7 +7177,7 @@ get_var_and_type (varname, value, ind, quoted, flags, varp, valp)
#if defined (ARRAY_VARS)
if (valid_array_reference (vname, 0))
{
v = array_variable_part (vname, &temp, (int *)0);
v = array_variable_part (vname, 0, &temp, (int *)0);
/* If we want to signal array_value to use an already-computed index,
set LIND to that index */
lind = (ind != INTMAX_MIN && (flags & AV_USEIND)) ? ind : 0;
@@ -8149,7 +8158,7 @@ parameter_brace_expand (string, indexp, quoted, pflags, quoted_dollar_atp, conta
char *x, *x1;
temp1 = savestring (name + 1);
x = array_variable_name (temp1, &x1, (int *)0); /* [ */
x = array_variable_name (temp1, 0, &x1, (int *)0); /* [ */
FREE (x);
if (ALL_ELEMENT_SUB (x1[0]) && x1[1] == ']')
{
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/bash/bash-current
BUILD_DIR=/usr/local/build/chet/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+3
View File
@@ -60,6 +60,8 @@
extern char *trap_list[];
extern int trapped_signal_received;
/* Externally-visible functions declared in trap.c. */
extern void initialize_traps __P((void));
@@ -112,6 +114,7 @@ extern int signal_in_progress __P((int));
extern int first_pending_trap __P((void));
extern int any_signals_trapped __P((void));
extern void check_signals __P((void));
extern void check_signals_and_traps __P((void));
#endif /* _TRAP_H_ */
+2 -2
View File
@@ -2723,7 +2723,7 @@ bind_variable_internal (name, value, table, hflags, aflags)
/* declare -n foo=x[2] ; foo=bar */
if (valid_array_reference (newval, 0))
{
tname = array_variable_name (newval, (char **)0, (int *)0);
tname = array_variable_name (newval, 0, (char **)0, (int *)0);
if (tname && (tentry = find_variable_noref (tname)) && nameref_p (tentry))
{
/* nameref variables can't be arrays */
@@ -3007,7 +3007,7 @@ bind_int_variable (lhs, rhs)
if (valid_array_reference (lhs, 0))
{
isarr = 1;
v = array_variable_part (lhs, (char **)0, (int *)0);
v = array_variable_part (lhs, 0, (char **)0, (int *)0);
}
else
#endif