From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5717 invoked by alias); 2 Jan 2016 20:36:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37493 Received: (qmail 6825 invoked from network); 2 Jan 2016 20:36:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=jcVt420gGvCsctKdsnBUwIxIvgdaGbfgpmEETTcuz8o=; b=uFpw+zr+LNsbUq6YTHA3e7btivUG9xwIbl1ZxA0ekQuLzM9PBsuRzXX3cxA5BvDrAI uaCP0dFRs0hbbihoCPLzNmnYwtiNAwtsw999Dhv0yz/ndLM1SKa1eS3O/vFqZBLP5fQK CVHD4xwqZGhmQ0Bm+UZsEhypwhBxk1vbltg4e/9yx4T8/3wqyA6vUbbo6FU7it7s7Tjr 2VnxWB6WlLy0k+lsf37gMn5zHdrm1FgWH01XY7peSeSElPJ2HauxSqsjFJNLeYXNfUyc ylAMyhwwe8yYqpvJdjMN+QxqjwtBgNbrL18GxxEOzB47JN/wEG3S+aHDt2uDOuWS46kI ixBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=jcVt420gGvCsctKdsnBUwIxIvgdaGbfgpmEETTcuz8o=; b=Q5sW6ptEpRgwrLMKfPWdieBbIAt4mxttv35gkhcsh7bYoVdtOOqCCeQyqhglxmlSKt rOeUItApYaZOfBHuQoKU9EGMZfKk1OZHONZ+HpkPc6cHv4mYUtbvn+RMy8O5/J2d2q2d B+xA3UXompYR7pYK8rnAM8x8zCKGvc8xMd2GwK0xbKy0sG/1GZrPS1IS8mPckh0XE5bA UwxMgiIh6UWg70s1RrFc++Woc8SXqza5/Oywbkj6tJV+OhydgLujSyae0+YK7YQJLYM6 SCeLQMdxtK4hDy1b2+8dAs04fdPmKb+WwRTc5l1xa+PPHEDTIMsUEmciRipD6EUtsQqv YEKQ== X-Gm-Message-State: ALoCoQn8OtdRMEkjndb8N0GzdcPiRKFivBZ+RbX1V4EY9fjfn1QJkNq9i/7jje73gf5uc/GMcuP93llpBMnpYzxVrVKQdG73QA== X-Received: by 10.66.234.8 with SMTP id ua8mr116499062pac.45.1451766994758; Sat, 02 Jan 2016 12:36:34 -0800 (PST) From: Bart Schaefer Message-Id: <160102123639.ZM16270@torch.brasslantern.com> Date: Sat, 2 Jan 2016 12:36:39 -0800 In-Reply-To: <20160102181814.3ac8d578@ntlworld.com> Comments: In reply to Peter Stephenson "Re: [BUG] functions can't create global readonly variables" (Jan 2, 6:18pm) References: <56874393.1010001@inlv.org> <160101202710.ZM1896@torch.brasslantern.com> <20160102181814.3ac8d578@ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: [BUG] functions can't create global readonly variables MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 2, 6:18pm, Peter Stephenson wrote: } } I think readonly is equivalent to "typeset -rg", so it stomps } on any existing global, too (unless it was already readonly). } } We could make this optional behaviour for compatibility, possibly with } POSIX_BUILTINS which is a real ragbag of POSIX funnies. Yes, this seems like a job for POSIX_BUILTINS. I would note that even with -g there is no way to create an actual global variable in the event that some intervening function has declared a name to be local. BIN_EXPORT was defined but never used, so ... What additional test case should we have? diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index dc0b947..fb630a7 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1465,7 +1465,10 @@ cancels both tt(-p) and tt(-u). The tt(-c) or tt(-l) flags cancel any and all of tt(-kpquz). ) cindex(parameters, marking readonly) -alias(readonly)(typeset -r) +item(tt(readonly))( +Same as tt(typeset -r). With the tt(POSIX_BUILTINS) option set, same +as tt(typeset -gr). +) alias(rehash)(hash -r) findex(return) cindex(functions, returning from) diff --git a/Src/builtin.c b/Src/builtin.c index 05907f1..557487c 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -62,7 +62,7 @@ static struct builtin builtins[] = BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmprs", NULL), BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL), BUILTIN("exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL), - BUILTIN("export", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, BIN_EXPORT, "E:%F:%HL:%R:%TUZ:%afhi:%lprtu", "xg"), + BUILTIN("export", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "E:%F:%HL:%R:%TUZ:%afhi:%lprtu", "xg"), BUILTIN("false", 0, bin_false, 0, -1, 0, NULL, NULL), /* * We used to behave as if the argument to -e was optional. @@ -106,7 +106,7 @@ static struct builtin builtins[] = BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL), BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "IlLnr", NULL), BUILTIN("read", 0, bin_read, 0, -1, 0, "cd:ek:%lnpqrst:%zu:AE", NULL), - BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%lptux", "r"), + BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, BIN_READONLY, "AE:%F:%HL:%R:%TUZ:%afghi:%lptux", "r"), BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"), BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL), BUILTIN("set", BINF_PSPECIAL | BINF_HANDLES_OPTS, bin_set, 0, -1, 0, NULL, NULL), @@ -2533,6 +2533,10 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) if (OPT_ISSET(ops,'f')) return bin_functions(name, argv, ops, func); + /* POSIX handles "readonly" specially */ + if (func == BIN_READONLY && isset(POSIXBUILTINS) && !OPT_PLUS(ops, 'g')) + ops->ind['g'] = 1; + /* Translate the options into PM_* flags. * * Unfortunately, this depends on the order * * these flags are defined in zsh.h */ diff --git a/Src/hashtable.h b/Src/hashtable.h index b6346bb..3606e97 100644 --- a/Src/hashtable.h +++ b/Src/hashtable.h @@ -53,7 +53,7 @@ #define BIN_LOGOUT 19 #define BIN_TEST 20 #define BIN_BRACKET 21 -#define BIN_EXPORT 22 +#define BIN_READONLY 22 #define BIN_ECHO 23 #define BIN_DISABLE 24 #define BIN_ENABLE 25 diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 7d65cc8..681fe73 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -479,12 +479,12 @@ setopt POSIXBUILTINS readonly pbro print ${+pbro} >&2 - (typeset pbro=3) + (typeset -g pbro=3) (pbro=4) - readonly -p | grep pbro >&2 # shows up as "readonly" although unset - typeset -r pbro # idempotent (no error)... + readonly -p pbro >&2 # shows up as "readonly" although unset + typeset -gr pbro # idempotent (no error)... print ${+pbro} >&2 # ...so still readonly... - typeset +r pbro # ...can't turn it off + typeset -g +r pbro # ...can't turn it off ) 1:readonly with POSIX_BUILTINS ?0