zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: Bug: bracketed-paste-magic + ztcp causes wrong pasted contents for CJK payloads
Date: Thu, 29 Oct 2015 16:56:25 +0000	[thread overview]
Message-ID: <20151029165625.67eb2e43@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <0D7C93CF-C84C-43BF-B7ED-4A868F04D401@kba.biglobe.ne.jp>

On Fri, 30 Oct 2015 01:25:49 +0900
Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
> E01options.ztst also need be updated; otherwise it fails as follows:
> 
> *** /tmp/zsh.ztst.err.65239	Fri Oct 30 00:54:52 2015
> --- /tmp/zsh.ztst.terr.65239	Fri Oct 30 00:54:52 2015
> ***************
> *** 1,3 ****
> --- 1,4 ----
>   fn:3: scalar parameter foo1 created globally in function
>   fn:5: scalar parameter foo1 created globally in function
>   fn:15: math parameter foo5 created globally in function fn
> + fn:15: numeric parameter foo5 created globally in function

Hmmm... I must have been asleep when the math test was added, since
there's no reason at all why it should be inconsistent with the others.
Either report the function or not.

This ports the code to report the function.  The math-specific code is
no longer needed now we have a check in setnparam().  I've been
overcautious since I can't see why we'd fail to find a function
on the trace stack if locallevel is non-zero.

pws

diff --git a/Src/math.c b/Src/math.c
index eee21e1..37981cf 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -893,25 +893,6 @@ getcvar(char *s)
     return mn;
 }
 
-
-/* If script execution is inside a function call that hasn't returned,
- * return the name of that function.  Else return NULL.
- */
-
-/**/
-static const char *
-in_function_call(void)
-{
-    Funcstack i;
-    for (i = funcstack; i; i = i->prev)
-	if (i->tp == FS_FUNC) {
-	    DPUTS(!i->name, "funcstack entry with no name");
-	    return i->name;
-	}
-
-    return NULL;
-}
-
 /**/
 static mnumber
 setmathvar(struct mathvalue *mvp, mnumber v)
@@ -947,13 +928,6 @@ setmathvar(struct mathvalue *mvp, mnumber v)
     if (noeval)
 	return v;
     untokenize(mvp->lval);
-    if (isset(WARNCREATEGLOBAL)) {
-	const char *function_name;
-	if (!paramtab->getnode(paramtab, mvp->lval) &&
-	    (function_name = in_function_call()))
-	    zwarn("math parameter %s created globally in function %s",
-		  mvp->lval, function_name);
-    }
     pm = setnparam(mvp->lval, v);
     if (pm) {
 	/*
diff --git a/Src/params.c b/Src/params.c
index 4d33660..5058695 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2695,6 +2695,37 @@ gethkparam(char *s)
 }
 
 /**/
+static void
+check_warn_create(Param pm, const char *pmtype)
+{
+    Funcstack i;
+    const char *name;
+
+    if (pm->level != 0)
+	return;
+
+    name = NULL;
+    for (i = funcstack; i; i = i->prev) {
+	if (i->tp == FS_FUNC) {
+	    DPUTS(!i->name, "funcstack entry with no name");
+	    name = i->name;
+	    break;
+	}
+    }
+
+    if (name)
+    {
+	zwarn("%s parameter %s created globally in function %s",
+	      pmtype, pm->node.nam, name);
+    }
+    else
+    {
+	zwarn("%s parameter %s created globally in function",
+	      pmtype, pm->node.nam);
+    }
+}
+
+/**/
 mod_export Param
 assignsparam(char *s, char *val, int flags)
 {
@@ -2747,9 +2778,8 @@ assignsparam(char *s, char *val, int flags)
 	zsfree(val);
 	return NULL;
     }
-    if ((flags & ASSPM_WARN_CREATE) && v->pm->level == 0)
-	zwarn("scalar parameter %s created globally in function",
-	      v->pm->node.nam);
+    if (flags & ASSPM_WARN_CREATE)
+	check_warn_create(v->pm, "scalar");
     if (flags & ASSPM_AUGMENT) {
 	if (v->start == 0 && v->end == -1) {
 	    switch (PM_TYPE(v->pm->node.flags)) {
@@ -2898,9 +2928,8 @@ assignaparam(char *s, char **val, int flags)
 	    return NULL;
 	}
 
-    if ((flags & ASSPM_WARN_CREATE) && v->pm->level == 0)
-	zwarn("array parameter %s created globally in function",
-	      v->pm->node.nam);
+    if (flags & ASSPM_WARN_CREATE)
+	check_warn_create(v->pm, "array");
     if (flags & ASSPM_AUGMENT) {
     	if (v->start == 0 && v->end == -1) {
 	    if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {
@@ -2958,9 +2987,8 @@ sethparam(char *s, char **val)
     queue_signals();
     if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) {
 	createparam(t, PM_HASHED);
-	if (isset(WARNCREATEGLOBAL) && locallevel > 0 && v->pm->level == 0)
-	    zwarn("associative array parameter %s created globally in function",
-		  v->pm->node.nam);
+	if (isset(WARNCREATEGLOBAL) && locallevel > 0)
+	    check_warn_create(v->pm, "associative array");
     } else if (!(PM_TYPE(v->pm->node.flags) & PM_HASHED) &&
 	     !(v->pm->node.flags & PM_SPECIAL)) {
 	unsetparam(t);
@@ -3032,10 +3060,8 @@ 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);
+	if (!was_unset && isset(WARNCREATEGLOBAL) && locallevel > 0)
+	    check_warn_create(v->pm, "numeric parameter");
     }
     setnumvalue(v, val);
     unqueue_signals();
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 1caee8d..15468e8 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1116,9 +1116,9 @@
   }
   fn
 0:WARN_CREATE_GLOBAL option
-?fn:3: scalar parameter foo1 created globally in function
-?fn:5: scalar parameter foo1 created globally in function
-?fn:15: math parameter foo5 created globally in function fn
+?fn:3: scalar parameter foo1 created globally in function fn
+?fn:5: scalar parameter foo1 created globally in function fn
+?fn:15: numeric parameter parameter foo5 created globally in function fn
 
 # This really just tests if XTRACE is egregiously broken.
 # To test it properly would need a full set of its own.


  reply	other threads:[~2015-10-29 16:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15 13:54 Chi Hsuan Yen
2015-10-15 20:54 ` Bart Schaefer
2015-10-16  0:25   ` Bart Schaefer
2015-10-16 19:40     ` Chi Hsuan Yen
2015-10-18 15:52       ` Bart Schaefer
2015-10-18 16:19         ` Chi Hsuan Yen
2015-10-28  2:43     ` Bart Schaefer
2015-10-28  3:23       ` Bart Schaefer
2015-10-28  9:35         ` Peter Stephenson
2015-10-28 17:07           ` Bart Schaefer
2015-10-28 17:44             ` Peter Stephenson
2015-10-28 23:38               ` Bart Schaefer
2015-10-29  9:31                 ` Peter Stephenson
2015-10-29 14:51                   ` Peter Stephenson
2015-10-29 15:00                     ` Bart Schaefer
2015-10-29 15:10                       ` Peter Stephenson
2015-10-29 16:25                     ` Jun T.
2015-10-29 16:56                       ` Peter Stephenson [this message]
2015-10-30 15:02                         ` Daniel Shahaf
2015-11-03 16:31                           ` Chi Hsuan Yen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151029165625.67eb2e43@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).