From aab0f6d763b0eb3eb964c576953c9dd0b90916ae Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 15 Dec 2017 08:56:19 +0000 Subject: 42123 (tweaked): take account of Dash in function names. Needed when comparing word code function name with autoload request. Add test. --- ChangeLog | 5 +++++ Src/exec.c | 22 ++++++++++++++++++++-- Test/C04funcdef.ztst | 9 +++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfd30ca9c..5613c8c72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-12-15 Peter Stephenson + + * 42123 (tweaked further): Src/exec.c: need to take account of + Dash when comparing functions names for autoloading. + 2017-12-14 Peter Stephenson * dana: 42119: Doc/zsh/params.yo, Src/jobs.c, diff --git a/Src/exec.c b/Src/exec.c index fc6d02dc3..664d79079 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -5932,6 +5932,7 @@ stripkshdef(Eprog prog, char *name) { Wordcode pc; wordcode code; + char *ptr1, *ptr2; if (!prog) return NULL; @@ -5942,8 +5943,25 @@ stripkshdef(Eprog prog, char *name) return prog; pc++; code = *pc++; - if (wc_code(code) != WC_FUNCDEF || - *pc != 1 || strcmp(name, ecrawstr(prog, pc + 1, NULL))) + if (wc_code(code) != WC_FUNCDEF || *pc != 1) + return prog; + + /* + * See if name of function requested (name) is same as + * name of function in word code. name may still have "-" + * tokenised. The word code shouldn't, as function names should be + * untokenised, but reports say it sometimes does. + */ + ptr1 = name; + ptr2 = ecrawstr(prog, pc + 1, NULL); + while (*ptr1 && *ptr2) { + if (*ptr1 != *ptr2 && *ptr1 != Dash && *ptr1 != '-' && + *ptr2 != Dash && *ptr2 != '-') + break; + ptr1++; + ptr2++; + } + if (*ptr1 || *ptr2) return prog; { diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 0c00a0477..5786018e0 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -523,6 +523,15 @@ 1: ?fn:4: maximum nested function level reached; increase FUNCNEST? + ( + fpath=(.) + print "foo-bar() { print this should run automatically; }" >foo-bar + autoload -Uz foo-bar + foo-bar + ) +0:autoload containing dash +>this should run automatically + %clean rm -f file.in file.out -- cgit 1.4.1