Re: Bash-4.4-beta2 available for download
On 12 Jul 2016 21:38, Chet Ramey wrote: > +== CHANGES ==+ > This document details the changes between this version, bash-4.4-beta2, and > the previous version, bash-4.4-rc1. why back to beta ? generally "rc" is considered newer than "beta", and the previous bash-4.4 releases were following that: readline-7.0-beta.tar.gz Mon, 12 Oct 2015 13:37:21 GMT readline-7.0-rc1.tar.gz Tue, 23 Feb 2016 19:02:49 GMT bash-4.4-beta.tar.gz Mon, 12 Oct 2015 13:39:30 GMT bash-4.4-rc1.tar.gz Tue, 23 Feb 2016 19:02:26 GMT bash-4.4-beta2.tar.gz Mon, 11 Jul 2016 14:11:37 GMT -mike signature.asc Description: Digital signature
Re: bash: remove the format string "%q" in the unicode3.sub
1. My target was x86-64, using the master 4.3.30 version of bash (Sorry for lacking the information) 2. I used the master version of bash on the unicode3.sub before I will test it for the devel version of bash as soon as. //dengke On 2016年08月10日 19:10, Chet Ramey wrote: On 8/10/16 2:42 AM, dengke...@windriver.com wrote: Hi chet Thanks for you help. 1. This file: http://git.savannah.gnu.org/cgit/bash.git/tree/tests/unicode3.sub?h=devel&id=74b8cbb41398b4453d8ba04d0cdd1b25f9dcb9e3 When executed to the 3 line: "$payload" On my target the output was: unicode3.sub: line 3: 5�@3�+�S8: command not found You don't give any information about your target, but using the devel version of bash on that file produces output using $'...' quoting on all the systems I have tested, since the string contains an invalid multibyte sequence.
[PATCH] include ctype.h for isdigit usage
--- lib/readline/histexpand.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/readline/histexpand.c b/lib/readline/histexpand.c index 46a99aa62e30..13248db83048 100644 --- a/lib/readline/histexpand.c +++ b/lib/readline/histexpand.c @@ -26,6 +26,7 @@ #endif #include +#include #if defined (HAVE_STDLIB_H) # include -- 2.9.0
Re: Bash-4.4-beta2 available for download
On 8/11/16 4:54 AM, Mike Frysinger wrote: > On 12 Jul 2016 21:38, Chet Ramey wrote: >> +== CHANGES ==+ >> This document details the changes between this version, bash-4.4-beta2, and >> the previous version, bash-4.4-rc1. > > why back to beta ? generally "rc" is considered newer than "beta", > and the previous bash-4.4 releases were following that: I went `back' from rc1 to beta2 because of the six weeks of discussion this sprint over the minutiae of nameref variables, and the changes that inspired. The next test release will be rc2. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ signature.asc Description: OpenPGP digital signature
Re: a patch to fix sh_stat on SunOS
On 8/10/16 5:38 PM, Dmitry Goncharov wrote: >> > does "If any file argument to one of the primaries is of the form > >> > /dev/fd/n, then file descriptor n is checked.". > > >> It seems like a documentation error. > > What should the man page say instead? Probably something close to what the current text about using /dev/fd in redirections says, maybe: \fBBash\fP handles filenames of the form \fI/dev/fd\fP specially when they are used as arguments to unary operators. If the operating system on which \fBbash\fP is running provides these special files, bash will use them; otherwise if any \fIfile\fP argument to one of the primaries is of the form \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: [PATCH] include ctype.h for isdigit usage
On 8/11/16 5:52 AM, Mike Frysinger wrote: > --- > lib/readline/histexpand.c | 1 + > 1 file changed, 1 insertion(+) Thanks for the fix. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
segfault w/bash-4.4-beta2 and assigning empty $*
simple code to reproduce: bash -c 'v=$*' gdb backtrace: Program received signal SIGSEGV, Segmentation fault. quote_string (string=0x0) at subst.c:3940 3940 if (*string == 0) #0 quote_string (string=0x0) at subst.c:3940 #1 0x0045c052 in param_expand (string=string@entry=0x7237c0 "$*", sindex=sindex@entry=0x7fffc43c, quoted=quoted@entry=0x0, expanded_something=expanded_something@entry=0x0, contains_dollar_at=contains_dollar_at@entry=0x7fffc448, quoted_dollar_at_p=quoted_dollar_at_p@entry=0x7fffc440, had_quoted_null_p=0x7fffc444, pflags=0x8) at subst.c:8570 #2 0x0045ca34 in expand_word_internal (word=word@entry=0x7fffc4e0, quoted=quoted@entry=0x0, isexp=isexp@entry=0x0, contains_dollar_at=contains_dollar_at@entry=0x0, expanded_something=expanded_something@entry=0x0) at subst.c:9194 #3 0x0045e3ac in call_expand_word_internal (w=w@entry=0x7fffc4e0, q=q@entry=0x0, i=i@entry=0x0, c=c@entry=0x0, e=0x0) at subst.c:3555 #4 0x0045e50a in expand_string_assignment (string=string@entry=0x7237a2 "$*", quoted=quoted@entry=0x0) at subst.c:3643 #5 0x004577de in expand_string_if_necessary (string=string@entry=0x7237a2 "$*", quoted=quoted@entry=0x0, func=func@entry=0x45e4a0 ) at subst.c:3345 #6 0x00457c8f in do_assignment_internal (word=0x723740, expand=expand@entry=0x1) at subst.c:3073 #7 0x00460265 in do_word_assignment (flags=0x0, word=) at subst.c:3162 #8 expand_word_list_internal (list=, eflags=eflags@entry=0x1f) at subst.c:10543 #9 0x0046056a in expand_words (list=) at subst.c:10098 #10 0x004381cf in execute_simple_command (simple_command=, pipe_in=, pipe_in@entry=0x, pipe_out=pipe_out@entry=0x, async=async@entry=0x0, fds_to_close=fds_to_close@entry=0x7235f0) at execute_cmd.c:4132 #11 0x0043a24a in execute_command_internal (command=0x723580, asynchronous=asynchronous@entry=0x0, pipe_in=pipe_in@entry=0x, pipe_out=pipe_out@entry=0x, fds_to_close=fds_to_close@entry=0x7235f0) at execute_cmd.c:802 #12 0x0048190f in parse_and_execute (string=, from_file=from_file@entry=0x4c1d69 "-c", flags=flags@entry=0x4) at evalstring.c:424 #13 0x0041f60e in run_one_command (command=) at shell.c:1399 #14 0x0042111f in main (argc=0x3, argv=0x7fffcbc8, env=0x7fffcbe8) at shell.c:724 -mike signature.asc Description: Digital signature
[PATCH 5/5] evalstring: drop volatile on sigset
These variables are located on the stack and are never read/written directly by bash. Instead, they're all accessed indirectly via the POSIX signal API. Since POSIX does not require volatile, and bash itself doesn't require volatile, drop the volatile markings. If we don't, you get a lot of warnings at build time as the POSIX API does not declare the prototypes with a volatile type. --- builtins/evalstring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtins/evalstring.c b/builtins/evalstring.c index 66926e9228d6..5c62a584fafa 100644 --- a/builtins/evalstring.c +++ b/builtins/evalstring.c @@ -231,7 +231,7 @@ parse_and_execute (string, from_file, flags) int code, lreset; volatile int should_jump_to_top_level, last_result; COMMAND *volatile command; - volatile sigset_t pe_sigmask; + sigset_t pe_sigmask; parse_prologue (string, flags, PE_TAG); @@ -488,7 +488,7 @@ parse_string (string, from_file, flags, endp) volatile int should_jump_to_top_level; COMMAND *volatile command, *oglobal; char *ostring; - volatile sigset_t ps_sigmask; + sigset_t ps_sigmask; parse_prologue (string, flags, PS_TAG); -- 2.9.0
[PATCH 3/5] arrayfunc: constify array names
Noticed when looking into segfault. The "discarding const qualifier" warning always makes me worried as it tends to come from bad code. --- arrayfunc.c | 18 ++ arrayfunc.h | 12 ++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/arrayfunc.c b/arrayfunc.c index fb87112281d8..eca6e03a642e 100644 --- a/arrayfunc.c +++ b/arrayfunc.c @@ -48,7 +48,7 @@ static SHELL_VAR *assign_array_element_internal __P((SHELL_VAR *, char *, char * static char *quote_assign __P((const char *)); static void quote_array_assignment_chars __P((WORD_LIST *)); -static char *array_value_internal __P((char *, int, int, int *, arrayind_t *)); +static char *array_value_internal __P((const char *, int, int, int *, arrayind_t *)); /* Standard error message to use when encountering an invalid array subscript */ const char * const bash_badsub_errmsg = N_("bad array subscript"); @@ -881,7 +881,7 @@ print_assoc_assignment (var, quoted) /* Return 1 if NAME is a properly-formed array reference v[sub]. */ int valid_array_reference (name, flags) - char *name; + const char *name; int flags; { char *t; @@ -948,7 +948,8 @@ array_expand_index (var, s, len) in *LENP. This returns newly-allocated memory. */ char * array_variable_name (s, subp, lenp) - char *s, **subp; + const char *s; + char **subp; int *lenp; { char *t, *ret; @@ -992,7 +993,8 @@ array_variable_name (s, subp, lenp) If LENP is non-null, the length of the subscript is returned in *LENP. */ SHELL_VAR * array_variable_part (s, subp, lenp) - char *s, **subp; + const char *s; + char **subp; int *lenp; { char *t; @@ -1029,7 +1031,7 @@ array_variable_part (s, subp, lenp) reference is name[@], and 0 otherwise. */ static char * array_value_internal (s, quoted, flags, rtype, indp) - char *s; + const char *s; int quoted, flags, *rtype; arrayind_t *indp; { @@ -1149,7 +1151,7 @@ array_value_internal (s, quoted, flags, rtype, indp) subscript contained in S, obeying quoting for subscripts * and @. */ char * array_value (s, quoted, flags, rtype, indp) - char *s; + const char *s; int quoted, flags, *rtype; arrayind_t *indp; { @@ -1162,7 +1164,7 @@ array_value (s, quoted, flags, rtype, indp) evaluator in expr.c. */ char * get_array_value (s, flags, rtype, indp) - char *s; + const char *s; int flags, *rtype; arrayind_t *indp; { @@ -1171,7 +1173,7 @@ get_array_value (s, flags, rtype, indp) char * array_keys (s, quoted) - char *s; + const char *s; int quoted; { int len; diff --git a/arrayfunc.h b/arrayfunc.h index 3a29a594e98e..46bf2c70f024 100644 --- a/arrayfunc.h +++ b/arrayfunc.h @@ -58,14 +58,14 @@ extern void print_array_assignment __P((SHELL_VAR *, int)); extern void print_assoc_assignment __P((SHELL_VAR *, int)); extern arrayind_t array_expand_index __P((SHELL_VAR *, char *, int)); -extern int valid_array_reference __P((char *, int)); -extern char *array_value __P((char *, int, int, int *, arrayind_t *)); -extern char *get_array_value __P((char *, int, int *, arrayind_t *)); +extern int valid_array_reference __P((const char *, int)); +extern char *array_value __P((const char *, int, int, int *, arrayind_t *)); +extern char *get_array_value __P((const char *, int, int *, arrayind_t *)); -extern char *array_keys __P((char *, int)); +extern char *array_keys __P((const char *, int)); -extern char *array_variable_name __P((char *, char **, int *)); -extern SHELL_VAR *array_variable_part __P((char *, char **, int *)); +extern char *array_variable_name __P((const char *, char **, int *)); +extern SHELL_VAR *array_variable_part __P((const char *, char **, int *)); #else -- 2.9.0
[PATCH 4/5] tmpfile: fix pointer cast warning
On systems where sizeof(void*) != sizeof(unsigned int) (e.g. on most 64-bit platforms), we get a warning like so: tmpfile.c: In function 'sh_seedrand': tmpfile.c:128:61: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] srandom (tv.tv_sec ^ tv.tv_usec ^ (getpid () << 16) ^ (unsigned int)&d); Use the standard uintptr_t to turn the pointer into an integer. --- lib/sh/tmpfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index 7c2fbf22fbe6..e41e45bd7cac 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -125,7 +125,7 @@ sh_seedrand () struct timeval tv; gettimeofday (&tv, NULL); - srandom (tv.tv_sec ^ tv.tv_usec ^ (getpid () << 16) ^ (unsigned int)&d); + srandom (tv.tv_sec ^ tv.tv_usec ^ (getpid () << 16) ^ (uintptr_t)&d); seeded = 1; } #endif -- 2.9.0
[PATCH 2/5] general: constify name/file funcs
Noticed when looking into segfault. The "discarding const qualifier" warning always makes me worried as it tends to come from bad code. --- general.c | 26 +- general.h | 18 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/general.c b/general.c index 75dda55c3371..d1d37299f8d7 100644 --- a/general.c +++ b/general.c @@ -154,9 +154,9 @@ print_rlimtype (n, addnl) /* Return non-zero if all of the characters in STRING are digits. */ int all_digits (string) - char *string; + const char *string; { - register char *s; + register const char *s; for (s = string; *s; s++) if (DIGIT (*s) == 0) @@ -211,9 +211,9 @@ legal_number (string, result) digit. */ int legal_identifier (name) - char *name; + const char *name; { - register char *s; + register const char *s; unsigned char c; if (!name || !(c = *name) || (legal_variable_starter (c) == 0)) @@ -234,7 +234,7 @@ legal_identifier (name) not used in assignments. */ int valid_nameref_value (name, flags) - char *name; + const char *name; int flags; { if (name == 0 || *name == 0) @@ -265,7 +265,7 @@ check_selfref (name, value, flags) #if defined (ARRAY_VARS) if (valid_array_reference (value, 0)) { - t = array_variable_name (value, (int *)NULL, (int *)NULL); + t = array_variable_name (value, NULL, NULL); if (t && STREQ (name, t)) { free (t); @@ -309,7 +309,7 @@ check_identifier (word, check_word) used yet. */ int importable_function_name (string, len) - char *string; + const char *string; size_t len; { if (absolute_program (string)) /* don't allow slash */ @@ -323,7 +323,7 @@ importable_function_name (string, len) int exportable_function_name (string) - char *string; + const char *string; { if (absolute_program (string)) return 0; @@ -337,10 +337,10 @@ exportable_function_name (string) parser (which disqualifies them from alias expansion anyway) and `/'. */ int legal_alias_name (string, flags) - char *string; + const char *string; int flags; { - register char *s; + register const char *s; for (s = string; *s; s++) if (shellbreak (*s) || shellxquote (*s) || shellexp (*s) || (*s == '/')) @@ -627,7 +627,7 @@ sh_closepipe (pv) int file_exists (fn) - char *fn; + const char *fn; { struct stat sb; @@ -636,7 +636,7 @@ file_exists (fn) int file_isdir (fn) - char *fn; + const char *fn; { struct stat sb; @@ -645,7 +645,7 @@ file_isdir (fn) int file_iswdir (fn) - char *fn; + const char *fn; { return (file_isdir (fn) && sh_eaccess (fn, W_OK) == 0); } diff --git a/general.h b/general.h index ba7e96878e57..645c8402772f 100644 --- a/general.h +++ b/general.h @@ -283,15 +283,15 @@ extern RLIMTYPE string_to_rlimtype __P((char *)); extern void print_rlimtype __P((RLIMTYPE, int)); #endif -extern int all_digits __P((char *)); +extern int all_digits __P((const char *)); extern int legal_number __P((const char *, intmax_t *)); -extern int legal_identifier __P((char *)); -extern int importable_function_name __P((char *, size_t)); -extern int exportable_function_name __P((char *)); +extern int legal_identifier __P((const char *)); +extern int importable_function_name __P((const char *, size_t)); +extern int exportable_function_name __P((const char *)); extern int check_identifier __P((WORD_DESC *, int)); -extern int valid_nameref_value __P((char *, int)); +extern int valid_nameref_value __P((const char *, int)); extern int check_selfref __P((const char *, const char *, int)); -extern int legal_alias_name __P((char *, int)); +extern int legal_alias_name __P((const char *, int)); extern int assignment __P((const char *, int)); extern int sh_unset_nodelay_mode __P((int)); @@ -308,9 +308,9 @@ extern int same_file __P((char *, char *, struct stat *, struct stat *)); extern int sh_openpipe __P((int *)); extern int sh_closepipe __P((int *)); -extern int file_exists __P((char *)); -extern int file_isdir __P((char *)); -extern int file_iswdir __P((char *)); +extern int file_exists __P((const char *)); +extern int file_isdir __P((const char *)); +extern int file_iswdir __P((const char *)); extern int path_dot_or_dotdot __P((const char *)); extern int absolute_pathname __P((const char *)); extern int absolute_program __P((const char *)); -- 2.9.0
[PATCH 1/5] eaccess: constify path arguments
Noticed when looking into segfault. The "discarding const qualifier" warning always makes me worried as it tends to come from bad code. --- externs.h| 2 +- lib/glob/glob.c | 2 +- lib/sh/eaccess.c | 10 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/externs.h b/externs.h index f2b43c415200..fa0603d34657 100644 --- a/externs.h +++ b/externs.h @@ -305,7 +305,7 @@ extern int sh_setlinebuf __P((FILE *)); #endif /* declarations for functions defined in lib/sh/shaccess.c */ -extern int sh_eaccess __P((char *, int)); +extern int sh_eaccess __P((const char *, int)); /* declarations for functions defined in lib/sh/shmatch.c */ extern int sh_regmatch __P((const char *, const char *, int)); diff --git a/lib/glob/glob.c b/lib/glob/glob.c index c6d7c05dca23..7f6eafe7d2eb 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -84,7 +84,7 @@ struct globval }; extern void throw_to_top_level __P((void)); -extern int sh_eaccess __P((char *, int)); +extern int sh_eaccess __P((const char *, int)); extern char *sh_makepath __P((const char *, const char *, int)); extern int signal_is_pending __P((int)); extern void run_pending_traps __P((void)); diff --git a/lib/sh/eaccess.c b/lib/sh/eaccess.c index 8132a9ab50de..8fd8a43e780d 100644 --- a/lib/sh/eaccess.c +++ b/lib/sh/eaccess.c @@ -53,9 +53,9 @@ extern int errno; #endif /* R_OK */ static int path_is_devfd __P((const char *)); -static int sh_stataccess __P((char *, int)); +static int sh_stataccess __P((const char *, int)); #if HAVE_DECL_SETREGID -static int sh_euidaccess __P((char *, int)); +static int sh_euidaccess __P((const char *, int)); #endif static int @@ -135,7 +135,7 @@ sh_stat (path, finfo) executable. This version uses stat(2). */ static int sh_stataccess (path, mode) - char *path; + const char *path; int mode; { struct stat st; @@ -172,7 +172,7 @@ sh_stataccess (path, mode) the effective and real uid and gid as appropriate. */ static int sh_euidaccess (path, mode) - char *path; + const char *path; int mode; { int r, e; @@ -197,7 +197,7 @@ sh_euidaccess (path, mode) int sh_eaccess (path, mode) - char *path; + const char *path; int mode; { int ret; -- 2.9.0
Re: segfault w/bash-4.4-beta2 and assigning empty $*
On 8/11/16 8:29 AM, Mike Frysinger wrote: > simple code to reproduce: > bash -c 'v=$*' http://lists.gnu.org/archive/html/bug-bash/2016-07/msg00066.html -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ signature.asc Description: OpenPGP digital signature
Re: segfault w/bash-4.4-beta2 and assigning empty $*
On 11 Aug 2016 08:32, Chet Ramey wrote: > On 8/11/16 8:29 AM, Mike Frysinger wrote: > > simple code to reproduce: > > bash -c 'v=$*' > > http://lists.gnu.org/archive/html/bug-bash/2016-07/msg00066.html thanks ... still catching up after vacation and hadn't made it that far yet ;) -mike signature.asc Description: Digital signature
Re: [PATCH 5/5] evalstring: drop volatile on sigset
On 8/11/16 8:30 AM, Mike Frysinger wrote: > These variables are located on the stack and are never read/written > directly by bash. Instead, they're all accessed indirectly via the > POSIX signal API. Since POSIX does not require volatile, and bash > itself doesn't require volatile, drop the volatile markings. If we > don't, you get a lot of warnings at build time as the POSIX API does > not declare the prototypes with a volatile type. I want the values usable across a potential longjmp() regardless of what the compiler does and regardless of the underlying sigset_t type. ISO C says the value is technically undefined after a longjmp, however unlikely it is that it will be modified. volatile is the easiest way to accomplish that. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: [PATCH 5/5] evalstring: drop volatile on sigset
On 11 Aug 2016 11:45, Chet Ramey wrote: > On 8/11/16 8:30 AM, Mike Frysinger wrote: > > These variables are located on the stack and are never read/written > > directly by bash. Instead, they're all accessed indirectly via the > > POSIX signal API. Since POSIX does not require volatile, and bash > > itself doesn't require volatile, drop the volatile markings. If we > > don't, you get a lot of warnings at build time as the POSIX API does > > not declare the prototypes with a volatile type. > > I want the values usable across a potential longjmp() regardless of what > the compiler does and regardless of the underlying sigset_t type. ISO C > says the value is technically undefined after a longjmp, however unlikely > it is that it will be modified. volatile is the easiest way to accomplish > that. then can casts be added ? building the code w/warnings is fairly verbose due to this issue (generates like ~30 lines of warnings iirc). -mike signature.asc Description: Digital signature
Re: [PATCH 5/5] evalstring: drop volatile on sigset
On 8/11/16 12:12 PM, Mike Frysinger wrote: > On 11 Aug 2016 11:45, Chet Ramey wrote: >> On 8/11/16 8:30 AM, Mike Frysinger wrote: >>> These variables are located on the stack and are never read/written >>> directly by bash. Instead, they're all accessed indirectly via the >>> POSIX signal API. Since POSIX does not require volatile, and bash >>> itself doesn't require volatile, drop the volatile markings. If we >>> don't, you get a lot of warnings at build time as the POSIX API does >>> not declare the prototypes with a volatile type. >> >> I want the values usable across a potential longjmp() regardless of what >> the compiler does and regardless of the underlying sigset_t type. ISO C >> says the value is technically undefined after a longjmp, however unlikely >> it is that it will be modified. volatile is the easiest way to accomplish >> that. > > then can casts be added ? building the code w/warnings is fairly verbose > due to this issue (generates like ~30 lines of warnings iirc). Sure, we'll try that. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ signature.asc Description: OpenPGP digital signature
Re: Unable to dereference function-local nameref to global variable of same name
Hi, since we already allow circular refs in the variable_context, the below answers your request. It means: in the function scope the name references to existing global variables will be correctly resolved. Please note that using find_global_variable in global_variable=find_global_variable(newname); results in breaking of the test suite (infinite recursion I think). As it is now, I am sure, it will result in Grisha's report with the chain of global namerefs, that is, currently it works like this: # declare -n ref="HOME"; declare -n ref2=ref; f() { declare -n ref2="$1"; echo $ref2; }; f ref2; bash: declare: warning: ref2: circular name reference bash: warning: ref2: circular name reference ref and with find_global_variable: # declare -n ref="HOME"; declare -n ref2=ref; f() { declare -n ref2="$1"; echo $ref2; }; f ref2; bash: declare: warning: ref2: circular name reference bash: warning: ref2: circular name reference /Users/merlin I personally believe that we should make this change (of course not before 4.4 ;-)), and that it should follow the global nameref chain. The patch (not breaking the test suite) follows. diff --git a/variables.c b/variables.c index be2446e..14f1be7 100644 --- a/variables.c +++ b/variables.c @@ -1906,6 +1906,7 @@ find_variable_nameref (v) int level, flags; char *newname, *t; SHELL_VAR *orig, *oldv; + SHELL_VAR *global_variable; level = 0; orig = v; @@ -1925,6 +1926,11 @@ find_variable_nameref (v) v = find_variable_internal (newname, flags); if (v == orig || v == oldv) { + global_variable=find_global_variable_noref(newname); + if (global_variable&&variable_context) + { + return global_variable; + } internal_warning (_("%s: circular name reference"), orig->name); return ((SHELL_VAR *)0); } cheers, pg On 10 Aug 2016, at 18:06, Andreas Kusalananda Kähäri wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: openbsd6.0 > Compiler: cc > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' > -DCONF_OSTYPE='openbsd6.0' -DCONF_MACHTYPE='x86_64-unknown-openbsd6.0' > -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' > -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib > -DUSE_MKTEMP -DUSE_MKSTEMP -I/usr/local/include -O2 -pipe > uname output: OpenBSD uerfale 6.0 GENERIC.MP#38 amd64 > Machine Type: x86_64-unknown-openbsd6.0 > > Bash Version: 4.3 > Patch Level: 46 > Release Status: release > > Description: >When declaring a variable in a function as a nameref, it can not >be dereferenced if the variable it's a nameref to happen to have >the same name as the nameref itself. This imposes unnecessary >restrictions on the caller. > >Also seen in GNU bash, version 4.3.39(1)-release (x86_64-apple-darwin15). > > Repeat-By: >function bug { >typeset -n var="$1" >printf "%s\n" "$var" >} > >var="hello" >bug var > >Result: >bash: warning: var: circular name reference > >Expected result: The string "hello" outputted with a terminating >newline (as with ksh93). >
Re: Unable to dereference function-local nameref to global variable of same name
Hi, amending the previous approach; please find the attached patch: the global namerefs are followed, and resolved in the function scope. It works as follows: bash-4.4$ typeset -n v=w; typeset -n w=x; typeset -n x=v; x=4 bash: warning: x: circular name reference. bash-4.4$ declare -n ref="HOME"; declare -n ref2=ref; f() { declare -n ref2="$1"; echo $ref2; }; f ref2; bash: declare: warning: ref2: circular name reference bash: warning: ref2: circular name reference /Users/merlin bash-4.4$ function bug { typeset -n var="$1"; printf "%s\n" "$var"; }; var="hello"; bug var; bash: typeset: warning: var: circular name reference bash: warning: var: circular name reference hello I have no idea what it breaks, I know it does not break the tests, and tries to address the reported issue. Please review. cheers, pg find_variable_nameref_follows_global_nameref_patch.diff Description: Binary data On 10 Aug 2016, at 18:06, Andreas Kusalananda Kähäri wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: openbsd6.0 > Compiler: cc > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' > -DCONF_OSTYPE='openbsd6.0' -DCONF_MACHTYPE='x86_64-unknown-openbsd6.0' > -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' > -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib > -DUSE_MKTEMP -DUSE_MKSTEMP -I/usr/local/include -O2 -pipe > uname output: OpenBSD uerfale 6.0 GENERIC.MP#38 amd64 > Machine Type: x86_64-unknown-openbsd6.0 > > Bash Version: 4.3 > Patch Level: 46 > Release Status: release > > Description: >When declaring a variable in a function as a nameref, it can not >be dereferenced if the variable it's a nameref to happen to have >the same name as the nameref itself. This imposes unnecessary >restrictions on the caller. > >Also seen in GNU bash, version 4.3.39(1)-release (x86_64-apple-darwin15). > > Repeat-By: >function bug { >typeset -n var="$1" >printf "%s\n" "$var" >} > >var="hello" >bug var > >Result: >bash: warning: var: circular name reference > >Expected result: The string "hello" outputted with a terminating >newline (as with ksh93). >
Re: Unable to dereference function-local nameref to global variable of same name
On 8/11/16 5:10 PM, Piotr Grzybowski wrote: > I personally believe that we should make this change (of course not before > 4.4 ;-)), and that it should follow the global nameref chain. > The patch (not breaking the test suite) follows. The problem with this fix, and part of what makes the situation complex, is that bash uses dynamic variable scoping. This solution would work if bash had static scoping. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/