about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2020-05-26 22:06:39 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2020-05-28 19:40:40 +0000
commitfb1aa3fe1e78ee1f521b64db062addf74ea9d263 (patch)
tree8a4a198511dad6099320b66ebb6a3139c3da48da /Src/exec.c
parent40723b3991557d0f5db66cbde9feb5cbc33bce78 (diff)
downloadzsh-fb1aa3fe1e78ee1f521b64db062addf74ea9d263.tar.gz
zsh-fb1aa3fe1e78ee1f521b64db062addf74ea9d263.tar.xz
zsh-fb1aa3fe1e78ee1f521b64db062addf74ea9d263.zip
45923 (with memory leak fixed, cf. 45924): zprof: Don't tally all anonymous functions as though they were a single function named "(anon)".
Before:

    % zmodload zsh/zprof
    % () :
    % () :
    % zprof
    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1)    2           0.08     0.04  100.00%      0.08     0.04  100.00%  (anon)

After:

    % zmodload zsh/zprof
    % () :
    % () :
    % zprof
    num  calls                time                       self            name
    -----------------------------------------------------------------------------------
     1)    1           0.04     0.04   50.45%      0.04     0.04   50.45%  (anon) [:3]
     2)    1           0.04     0.04   49.55%      0.04     0.04   49.55%  (anon) [:2]
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 2b8e2167f..29f4fc5ca 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5147,10 +5147,26 @@ exectime(Estate state, UNUSED(int do_exec))
     return lastval;
 }
 
-/* Define a shell function */
-
+/* The string displayed in lieu of the name of an anonymous function (in PS4,
+ * zprof output, etc)
+ */
 static const char *const ANONYMOUS_FUNCTION_NAME = "(anon)";
 
+/* 
+ * Take a function name argument and return true iff it is equal to the string
+ * used for the names of anonymous functions, "(anon)".
+ *
+ * Note that it's possible to define a named function literally called "(anon)"
+ * (though I doubt anyone would ever do that).
+ */
+/**/
+int is_anonymous_function_name(const char *name)
+{
+    return !strcmp(name, ANONYMOUS_FUNCTION_NAME);
+}
+
+/* Define a shell function */
+
 /**/
 static int
 execfuncdef(Estate state, Eprog redir_prog)