zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Make a function that redefines itself preserve its tracedness.
@ 2019-12-22  4:52 Daniel Shahaf
  0 siblings, 0 replies; only message in thread
From: Daniel Shahaf @ 2019-12-22  4:52 UTC (permalink / raw)
  To: zsh-workers

This makes it easy to apply local tracing ('functions -T') to autoloadable
functions that redefines themselves when first loaded.
---

Given how late we are in the release cycle, should I wait until after 5.8 to
push this?

Cheers,

Daniel


 Src/exec.c          | 6 ++++++
 Test/E02xtrace.ztst | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/Src/exec.c b/Src/exec.c
index fac095d64..356e2974b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5320,6 +5320,12 @@ execfuncdef(Estate state, Eprog redir_prog)
 		 */
 		removetrapnode(signum);
 	    }
+	    /* Is this function traced and redefining itself? */
+	    if (funcstack && funcstack->tp == FS_FUNC &&
+		    !strcmp(s, funcstack->name)) {
+		Shfunc old = ((Shfunc)shfunctab->getnode(shfunctab, s));
+		shf->node.flags |= old->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL);
+	    }
 	    shfunctab->addnode(shfunctab, ztrdup(s), shf);
 	}
     }
diff --git a/Test/E02xtrace.ztst b/Test/E02xtrace.ztst
index da6191cd0..8d2c300cf 100644
--- a/Test/E02xtrace.ztst
+++ b/Test/E02xtrace.ztst
@@ -146,3 +146,12 @@
 ?+(anon):0> '(anon)'
 ?+(anon):0> true
 ?+fn:0> gn
+
+  f() {
+    f() { echo inner }
+  }
+  functions -T f
+  f
+  which f | grep '# traced'
+0:a function that redefines itself preserves tracing
+>	# traced

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-22  4:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-22  4:52 [PATCH] Make a function that redefines itself preserve its tracedness Daniel Shahaf

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).