From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28979 invoked by alias); 29 Oct 2015 14:52:01 -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: 37014 Received: (qmail 11434 invoked from network); 29 Oct 2015 14:51:57 -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 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-26-5632328ae01b Date: Thu, 29 Oct 2015 14:51:43 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: Bug: bracketed-paste-magic + ztcp causes wrong pasted contents for CJK payloads Message-id: <20151029145143.6b3830a7@pwslap01u.europe.root.pri> In-reply-to: <20151029093131.49241bde@pwslap01u.europe.root.pri> References: <151015172503.ZM30721@torch.brasslantern.com> <151027194317.ZM17099@torch.brasslantern.com> <151027202340.ZM17146@torch.brasslantern.com> <20151028093504.756c22b1@pwslap01u.europe.root.pri> <151028100744.ZM18361@torch.brasslantern.com> <20151028174448.70594180@pwslap01u.europe.root.pri> <151028163814.ZM1379@torch.brasslantern.com> <20151029093131.49241bde@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKLMWRmVeSWpSXmKPExsVy+t/xK7pdRkZhBvcaBS0ONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxs0XhxgLNsdUzF83ibWB8bt7FyMnh4SAicT1CfuZIGwxiQv3 1rN1MXJxCAksZZQ4sPQTK4Qzg0ni2Z0+dghnG6PEmxMT2UFaWARUJfasXQjWziZgKDF102xG EFtEQEtix8mTYHFhgTiJy8u/M4PYvAL2El/uN4DZnAIOEu93L2aEGLqKRaJl5VywZn4BfYmr fz9B3WQvMfPKGUaIZkGJH5PvsYDYzEALNm9rYoWw5SU2r3kLNlRIQF3ixt3d7BMYhWYhaZmF pGUWkpYFjMyrGEVTS5MLipPScw31ihNzi0vz0vWS83M3MUIC98sOxsXHrA4xCnAwKvHwLjAy DBNiTSwrrsw9xCjBwawkwtthaBQmxJuSWFmVWpQfX1Sak1p8iFGag0VJnHfurvchQgLpiSWp 2ampBalFMFkmDk6pBsbcbZ3Lpb3EL03rD71nlODUM9XHYLP/n7NrXs5/4NO5X72o8L8uz9fi 7YnR0Rw/lj4yVY76Ehuc/ITjdGvmva+SKrsiHl0z4VWXK/zG3uh7dCZ7soLTa2W+uUuPOvfx ub6U+HJEc91Upzhxsyn/wrT2Xo+fK9U1Y4fvv39zGZ8Z7s0OYzJtuK3EUpyRaKjFXFScCABW zWFNWAIAAA== On Thu, 29 Oct 2015 09:31:31 +0000 Peter Stephenson wrote: > On Wed, 28 Oct 2015 16:38:13 -0700 > Bart Schaefer wrote: > > On Oct 28, 5:44pm, Peter Stephenson wrote: > > } > > } I wonder if the existing setsparam() etc. functions, which are currently > > } just aliases or front-ends for assignsparam() etc. with no warnings, > > } could be modified to add the flag based on the option? > > > > You mean modify the implementations, not the call signature, correct? > > Yes. The key thing to get this not to be completely broken appears to be updating the typeset code to call the assign functions with flags set to 0, i.e. what the replaced functions used to do. As they were #define'd this is exactly equivalent there. Then other set*params() that aren't within typeset will warn. This is looking reasonably plausible --- a couple of bits of fallout in add-zsh-hook and zsh-mime-setup already. No doubt there will be more, but probably I'll need to commit it to track them down. Includes the effect of the change not to integerise REPLY unnecessarily. diff --git a/Functions/MIME/zsh-mime-setup b/Functions/MIME/zsh-mime-setup index 23e44fd..35f6e6b 100644 --- a/Functions/MIME/zsh-mime-setup +++ b/Functions/MIME/zsh-mime-setup @@ -1,7 +1,7 @@ emulate -L zsh setopt extendedglob cbases -local opt o_verbose o_list +local opt o_verbose o_list i autoload -Uz zsh-mime-handler diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook index ee37d67..fc39659 100644 --- a/Functions/Misc/add-zsh-hook +++ b/Functions/Misc/add-zsh-hook @@ -82,9 +82,11 @@ if (( del )); then else if (( ${(P)+hook} )); then if (( ${${(P)hook}[(I)$fn]} == 0 )); then + typeset -ga $hook set -A $hook ${(P)hook} $fn fi else + typeset -ga $hook set -A $hook $fn fi autoload $autoopts -- $fn diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c index f683496..7c3fb5e 100644 --- a/Src/Modules/socket.c +++ b/Src/Modules/socket.c @@ -132,7 +132,7 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) /* allow to be closed explicitly */ fdtable[sfd] = FDT_EXTERNAL; - setiparam("REPLY", sfd); + setiparam_no_convert("REPLY", (zlong)sfd); if (verbose) printf("%s listener is on fd %d\n", soun.sun_path, sfd); @@ -220,7 +220,7 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) sfd = rfd; } - setiparam("REPLY", sfd); + setiparam_no_convert("REPLY", (zlong)sfd); if (verbose) printf("new connection from %s is on fd %d\n", soun.sun_path, sfd); @@ -261,7 +261,7 @@ bin_zsocket(char *nam, char **args, Options ops, UNUSED(int func)) fdtable[sfd] = FDT_EXTERNAL; } - setiparam("REPLY", sfd); + setiparam_no_convert("REPLY", (zlong)sfd); if (verbose) printf("%s is now on fd %d\n", soun.sun_path, sfd); diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c index 7b0dcc7..9fc1b29 100644 --- a/Src/Modules/tcp.c +++ b/Src/Modules/tcp.c @@ -461,7 +461,7 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func)) return 1; } - setiparam("REPLY", sess->fd); + setiparam_no_convert("REPLY", (zlong)sess->fd); if (verbose) printf("%d listener is on fd %d\n", ntohs(sess->sock.in.sin_port), sess->fd); @@ -562,7 +562,7 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func)) sess->fd = rfd; } - setiparam("REPLY", sess->fd); + setiparam_no_convert("REPLY", (zlong)sess->fd); if (verbose) printf("%d is on fd %d\n", ntohs(sess->peer.in.sin_port), sess->fd); @@ -681,7 +681,7 @@ bin_ztcp(char *nam, char **args, Options ops, UNUSED(int func)) } } - setiparam("REPLY", sess->fd); + setiparam_no_convert("REPLY", (zlong)sess->fd); if (verbose) printf("%s:%d is now on fd %d\n", diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 9741ee2..3b83660 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -464,7 +464,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) #endif errno == EINTR)); - setiparam("REPLY", master); + setiparam_no_convert("REPLY", (zlong)master); return 0; } diff --git a/Src/builtin.c b/Src/builtin.c index 97022ad..8045bc8 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2090,7 +2090,9 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), tc = 0; /* but don't do a normal conversion */ } } else if (!setsecondstype(pm, on, off)) { - if (asg->value.scalar && !(pm = setsparam(pname, ztrdup(asg->value.scalar)))) + if (asg->value.scalar && + !(pm = assignsparam( + pname, ztrdup(asg->value.scalar), 0))) return NULL; usepm = 1; err = 0; @@ -2202,12 +2204,13 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), } else if (pm->env && !(pm->node.flags & PM_HASHELEM)) delenv(pm); DPUTS(ASG_ARRAYP(asg), "BUG: typeset got array value where scalar expected"); - if (asg->value.scalar && !(pm = setsparam(pname, ztrdup(asg->value.scalar)))) + if (asg->value.scalar && + !(pm = assignsparam(pname, ztrdup(asg->value.scalar), 0))) return NULL; } else if (asg->is_array) { - if (!(pm = setaparam(pname, asg->value.array ? + if (!(pm = assignaparam(pname, asg->value.array ? zlinklist2array(asg->value.array) : - mkarray(NULL)))) + mkarray(NULL), 0))) return NULL; } pm->node.flags |= (on & PM_READONLY); @@ -2347,16 +2350,18 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), * creating a stray parameter along the way via createparam(), * now called below in the isident() branch. */ - if (!(pm = setsparam(pname, ztrdup(asg->value.scalar ? asg->value.scalar : "")))) + if (!(pm = assignsparam( + pname, + ztrdup(asg->value.scalar ? asg->value.scalar : ""), 0))) return NULL; dont_set = 1; asg->is_array = 0; keeplocal = 0; on = pm->node.flags; } else if (PM_TYPE(on) == PM_ARRAY && ASG_ARRAYP(asg)) { - if (!(pm = setaparam(pname, asg->value.array ? - zlinklist2array(asg->value.array) : - mkarray(NULL)))) + if (!(pm = assignaparam(pname, asg->value.array ? + zlinklist2array(asg->value.array) : + mkarray(NULL), 0))) return NULL; dont_set = 1; keeplocal = 0; @@ -2433,13 +2438,13 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), Param ipm = pm; if (pm->node.flags & (PM_ARRAY|PM_HASHED)) { DPUTS(!ASG_ARRAYP(asg), "BUG: inconsistent scalar value for array"); - if (!(pm=setaparam(pname, asg->value.array ? - zlinklist2array(asg->value.array) : - mkarray(NULL)))) + if (!(pm=assignaparam(pname, asg->value.array ? + zlinklist2array(asg->value.array) : + mkarray(NULL), 0))) return NULL; } else { DPUTS(ASG_ARRAYP(asg), "BUG: inconsistent array value for scalar"); - if (!(pm = setsparam(pname, ztrdup(asg->value.scalar)))) + if (!(pm = assignsparam(pname, ztrdup(asg->value.scalar), 0))) return NULL; } if (pm != ipm) { @@ -2687,9 +2692,10 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) /* Update join character */ tdp->joinchar = joinchar; if (asg0.value.scalar) - setsparam(asg0.name, ztrdup(asg0.value.scalar)); + assignsparam(asg0.name, ztrdup(asg0.value.scalar), 0); else if (asg->value.array) - setaparam(asg->name, zlinklist2array(asg->value.array)); + assignaparam( + asg->name, zlinklist2array(asg->value.array), 0); return 0; } else { zwarnnam(name, "can't tie already tied scalar: %s", @@ -2750,9 +2756,9 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) zsfree(apm->ename); apm->ename = ztrdup(asg0.name); if (asg->value.array) - setaparam(asg->name, zlinklist2array(asg->value.array)); + assignaparam(asg->name, zlinklist2array(asg->value.array), 0); else if (oldval) - setsparam(asg0.name, oldval); + assignsparam(asg0.name, oldval, 0); unqueue_signals(); return 0; diff --git a/Src/params.c b/Src/params.c index a8abb28..4d33660 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2828,6 +2828,15 @@ assignsparam(char *s, char *val, int flags) /**/ mod_export Param +setsparam(char *s, char *val) +{ + return assignsparam( + s, val, isset(WARNCREATEGLOBAL) && locallevel > 0 ? + ASSPM_WARN_CREATE : 0); +} + +/**/ +mod_export Param assignaparam(char *s, char **val, int flags) { struct value vbuf; @@ -2914,6 +2923,16 @@ assignaparam(char *s, char **val, int flags) return v->pm; } + +/**/ +mod_export Param +setaparam(char *s, char **aval) +{ + return assignaparam( + s, aval, isset(WARNCREATEGLOBAL) && locallevel >0 ? + ASSPM_WARN_CREATE : 0); +} + /**/ mod_export Param sethparam(char *s, char **val) @@ -2937,11 +2956,15 @@ sethparam(char *s, char **val) if (unset(EXECOPT)) return NULL; queue_signals(); - if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) + if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) { createparam(t, PM_HASHED); - else if (!(PM_TYPE(v->pm->node.flags) & PM_HASHED) && + if (isset(WARNCREATEGLOBAL) && locallevel > 0 && v->pm->level == 0) + zwarn("associative array parameter %s created globally in function", + v->pm->node.nam); + } else if (!(PM_TYPE(v->pm->node.flags) & PM_HASHED) && !(v->pm->node.flags & PM_SPECIAL)) { unsetparam(t); + /* no WARNCREATEGLOBAL check here as parameter already existed */ createparam(t, PM_HASHED); v = NULL; } @@ -2968,6 +2991,7 @@ setnparam(char *s, mnumber val) Value v; char *t = s, *ss; Param pm; + int was_unset = 0; if (!isident(s)) { zerr("not an identifier: %s", s); @@ -2987,6 +3011,7 @@ setnparam(char *s, mnumber val) */ unset(KSHARRAYS) && !ss) { unsetparam_pm(v->pm, 0, 1); + was_unset = 1; s = t; v = NULL; } @@ -3007,6 +3032,10 @@ setnparam(char *s, mnumber val) } v = getvalue(&vbuf, &t, 1); DPUTS(!v, "BUG: value not found for new parameter"); + if (!was_unset && isset(WARNCREATEGLOBAL) && locallevel > 0 && + v->pm->level == 0) + zwarn("numeric parameter %s created globally in function", + v->pm->node.nam); } setnumvalue(v, val); unqueue_signals(); @@ -3025,6 +3054,26 @@ setiparam(char *s, zlong val) return setnparam(s, mnval); } +/* + * Set an integer parameter without forcing creation of an integer type. + * This is useful if the integer is going to be set to a parmaeter which + * would usually be scalar but may not exist. + */ + +/**/ +mod_export Param +setiparam_no_convert(char *s, zlong val) +{ + /* + * If the target is already an integer, thisgets converted + * back. Low technology rules. + */ + char buf[BDIGBUFSIZE]; + convbase(buf, val, 10); + return assignsparam( + s, ztrdup(buf), + isset(WARNCREATEGLOBAL) && locallevel > 0 ? ASSPM_WARN_CREATE : 0); +} /* Unset a parameter */ diff --git a/Src/zsh.h b/Src/zsh.h index f819249..a6f0397 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1939,9 +1939,6 @@ struct paramdef { { name, flags | PM_SPECIAL | PM_HIDE | PM_HIDEVAL, \ NULL, gsufn, getfn, scanfn, NULL } -#define setsparam(S,V) assignsparam(S,V,0) -#define setaparam(S,V) assignaparam(S,V,0) - /* * Flags for assignsparam and assignaparam. */