diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-09-07 18:01:49 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-09-07 18:01:49 +0200 |
commit | d6c9cbc0727cc3875672ae280ec129514a9d8594 (patch) | |
tree | d402b52d331c23cf41b43e628b3ac59e742a7ff0 | |
parent | 0d7dfa9012d01159c371bf041bf53afe0780df9f (diff) | |
download | busybox-w32-d6c9cbc0727cc3875672ae280ec129514a9d8594.tar.gz busybox-w32-d6c9cbc0727cc3875672ae280ec129514a9d8594.tar.bz2 busybox-w32-d6c9cbc0727cc3875672ae280ec129514a9d8594.zip |
ash: fix LINENO in functions
From larger patch by Roberto A. Foglietta <roberto.foglietta@gmail.com>
function old new delta
evalfun 348 369 +21
ash_main 1202 1218 +16
setinputstring 65 73 +8
lookupvar 116 106 -10
evaltree 772 753 -19
evalsubshell 192 173 -19
evalfor 175 156 -19
evalcase 273 254 -19
evalcommand 1560 1536 -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 45/-110) Total: -65 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 18 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_LINENO2.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_LINENO2.tests | 8 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var_LINENO2.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var_LINENO2.tests | 8 |
5 files changed, 28 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index c65f09782..79fa3adba 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2357,7 +2357,7 @@ lookupvar(const char *name) | |||
2357 | v->var_func(NULL); | 2357 | v->var_func(NULL); |
2358 | #endif | 2358 | #endif |
2359 | if (!(v->flags & VUNSET)) { | 2359 | if (!(v->flags & VUNSET)) { |
2360 | if (v == &vlineno && v->var_text == linenovar) { | 2360 | if (v->var_text == linenovar) { |
2361 | fmtstr(linenovar+7, sizeof(linenovar)-7, "%d", lineno); | 2361 | fmtstr(linenovar+7, sizeof(linenovar)-7, "%d", lineno); |
2362 | } | 2362 | } |
2363 | return var_end(v->var_text); | 2363 | return var_end(v->var_text); |
@@ -9322,8 +9322,6 @@ evaltree(union node *n, int flags) | |||
9322 | goto setstatus; | 9322 | goto setstatus; |
9323 | case NREDIR: | 9323 | case NREDIR: |
9324 | errlinno = lineno = n->nredir.linno; | 9324 | errlinno = lineno = n->nredir.linno; |
9325 | if (funcline) | ||
9326 | lineno -= funcline - 1; | ||
9327 | expredir(n->nredir.redirect); | 9325 | expredir(n->nredir.redirect); |
9328 | pushredir(n->nredir.redirect); | 9326 | pushredir(n->nredir.redirect); |
9329 | status = redirectsafe(n->nredir.redirect, REDIR_PUSH); | 9327 | status = redirectsafe(n->nredir.redirect, REDIR_PUSH); |
@@ -9502,8 +9500,6 @@ evalfor(union node *n, int flags) | |||
9502 | int status = 0; | 9500 | int status = 0; |
9503 | 9501 | ||
9504 | errlinno = lineno = n->ncase.linno; | 9502 | errlinno = lineno = n->ncase.linno; |
9505 | if (funcline) | ||
9506 | lineno -= funcline - 1; | ||
9507 | 9503 | ||
9508 | arglist.list = NULL; | 9504 | arglist.list = NULL; |
9509 | arglist.lastp = &arglist.list; | 9505 | arglist.lastp = &arglist.list; |
@@ -9534,8 +9530,6 @@ evalcase(union node *n, int flags) | |||
9534 | int status = 0; | 9530 | int status = 0; |
9535 | 9531 | ||
9536 | errlinno = lineno = n->ncase.linno; | 9532 | errlinno = lineno = n->ncase.linno; |
9537 | if (funcline) | ||
9538 | lineno -= funcline - 1; | ||
9539 | 9533 | ||
9540 | arglist.list = NULL; | 9534 | arglist.list = NULL; |
9541 | arglist.lastp = &arglist.list; | 9535 | arglist.lastp = &arglist.list; |
@@ -9569,8 +9563,6 @@ evalsubshell(union node *n, int flags) | |||
9569 | int status; | 9563 | int status; |
9570 | 9564 | ||
9571 | errlinno = lineno = n->nredir.linno; | 9565 | errlinno = lineno = n->nredir.linno; |
9572 | if (funcline) | ||
9573 | lineno -= funcline - 1; | ||
9574 | 9566 | ||
9575 | expredir(n->nredir.redirect); | 9567 | expredir(n->nredir.redirect); |
9576 | if (!backgnd && (flags & EV_EXIT) && !may_have_traps) | 9568 | if (!backgnd && (flags & EV_EXIT) && !may_have_traps) |
@@ -9898,6 +9890,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
9898 | struct jmploc *volatile savehandler; | 9890 | struct jmploc *volatile savehandler; |
9899 | struct jmploc jmploc; | 9891 | struct jmploc jmploc; |
9900 | int e; | 9892 | int e; |
9893 | int savelineno; | ||
9901 | int savefuncline; | 9894 | int savefuncline; |
9902 | char *savetrap = NULL; | 9895 | char *savetrap = NULL; |
9903 | 9896 | ||
@@ -9905,6 +9898,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
9905 | savetrap = trap[NTRAP_ERR]; | 9898 | savetrap = trap[NTRAP_ERR]; |
9906 | trap[NTRAP_ERR] = NULL; | 9899 | trap[NTRAP_ERR] = NULL; |
9907 | } | 9900 | } |
9901 | savelineno = lineno; | ||
9908 | saveparam = shellparam; | 9902 | saveparam = shellparam; |
9909 | savefuncline = funcline; | 9903 | savefuncline = funcline; |
9910 | savehandler = exception_handler; | 9904 | savehandler = exception_handler; |
@@ -9934,6 +9928,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
9934 | free(savetrap); | 9928 | free(savetrap); |
9935 | } | 9929 | } |
9936 | funcline = savefuncline; | 9930 | funcline = savefuncline; |
9931 | lineno = savelineno; | ||
9937 | freefunc(func); | 9932 | freefunc(func); |
9938 | freeparam(&shellparam); | 9933 | freeparam(&shellparam); |
9939 | shellparam = saveparam; | 9934 | shellparam = saveparam; |
@@ -10322,8 +10317,6 @@ evalcommand(union node *cmd, int flags) | |||
10322 | int vlocal; | 10317 | int vlocal; |
10323 | 10318 | ||
10324 | errlinno = lineno = cmd->ncmd.linno; | 10319 | errlinno = lineno = cmd->ncmd.linno; |
10325 | if (funcline) | ||
10326 | lineno -= funcline - 1; | ||
10327 | 10320 | ||
10328 | /* First expand the arguments. */ | 10321 | /* First expand the arguments. */ |
10329 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); | 10322 | TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); |
@@ -11201,7 +11194,7 @@ setinputstring(char *string) | |||
11201 | g_parsefile->next_to_pgetc = string; | 11194 | g_parsefile->next_to_pgetc = string; |
11202 | g_parsefile->left_in_line = strlen(string); | 11195 | g_parsefile->left_in_line = strlen(string); |
11203 | g_parsefile->buf = NULL; | 11196 | g_parsefile->buf = NULL; |
11204 | g_parsefile->linno = 1; | 11197 | g_parsefile->linno = lineno; |
11205 | INT_ON; | 11198 | INT_ON; |
11206 | } | 11199 | } |
11207 | 11200 | ||
@@ -14705,6 +14698,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
14705 | // ^^ not necessary since now we special-case fd 0 | 14698 | // ^^ not necessary since now we special-case fd 0 |
14706 | // in save_fd_on_redirect() | 14699 | // in save_fd_on_redirect() |
14707 | 14700 | ||
14701 | lineno = 1; | ||
14708 | // dash: evalstring(minusc, sflag ? 0 : EV_EXIT); | 14702 | // dash: evalstring(minusc, sflag ? 0 : EV_EXIT); |
14709 | // The above makes | 14703 | // The above makes |
14710 | // ash -sc 'echo $-' | 14704 | // ash -sc 'echo $-' |
diff --git a/shell/ash_test/ash-vars/var_LINENO2.right b/shell/ash_test/ash-vars/var_LINENO2.right new file mode 100644 index 000000000..73656647c --- /dev/null +++ b/shell/ash_test/ash-vars/var_LINENO2.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Start LINENO=6, calling function | ||
2 | In function: LINENO=4 | ||
3 | After function: LINENO=8 | ||
diff --git a/shell/ash_test/ash-vars/var_LINENO2.tests b/shell/ash_test/ash-vars/var_LINENO2.tests new file mode 100755 index 000000000..7036dbdc8 --- /dev/null +++ b/shell/ash_test/ash-vars/var_LINENO2.tests | |||
@@ -0,0 +1,8 @@ | |||
1 | #skip lines: make "line number within function" differ from overall line number | ||
2 | #skip lines | ||
3 | f() { | ||
4 | echo "In function: LINENO=$LINENO" | ||
5 | } | ||
6 | echo "Start LINENO=$LINENO, calling function" | ||
7 | f | ||
8 | echo "After function: LINENO=$LINENO" | ||
diff --git a/shell/hush_test/hush-vars/var_LINENO2.right b/shell/hush_test/hush-vars/var_LINENO2.right new file mode 100644 index 000000000..73656647c --- /dev/null +++ b/shell/hush_test/hush-vars/var_LINENO2.right | |||
@@ -0,0 +1,3 @@ | |||
1 | Start LINENO=6, calling function | ||
2 | In function: LINENO=4 | ||
3 | After function: LINENO=8 | ||
diff --git a/shell/hush_test/hush-vars/var_LINENO2.tests b/shell/hush_test/hush-vars/var_LINENO2.tests new file mode 100755 index 000000000..7036dbdc8 --- /dev/null +++ b/shell/hush_test/hush-vars/var_LINENO2.tests | |||
@@ -0,0 +1,8 @@ | |||
1 | #skip lines: make "line number within function" differ from overall line number | ||
2 | #skip lines | ||
3 | f() { | ||
4 | echo "In function: LINENO=$LINENO" | ||
5 | } | ||
6 | echo "Start LINENO=$LINENO, calling function" | ||
7 | f | ||
8 | echo "After function: LINENO=$LINENO" | ||