ash: [EVAL] Let funcnode refer to a function definition, not its first command
Upstream patch: Date: Tue, 15 Mar 2011 15:44:47 +0800 [EVAL] Let funcnode refer to a function definition, not its first command It is not unrelated: I changed the meaning of struct funcnode's field n to refer to the function definition, rather than the list of the function's commands, because I needed to refer to the function definition node from evalfun, which only gets passed a funcnode. But it is something that could be applied independently (without being useful by itself), so I've attached it as a separate patch for easier review. Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -8449,14 +8449,14 @@ copyfunc(union node *n)
|
|||||||
* Define a shell function.
|
* Define a shell function.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
defun(char *name, union node *func)
|
defun(union node *func)
|
||||||
{
|
{
|
||||||
struct cmdentry entry;
|
struct cmdentry entry;
|
||||||
|
|
||||||
INT_OFF;
|
INT_OFF;
|
||||||
entry.cmdtype = CMDFUNCTION;
|
entry.cmdtype = CMDFUNCTION;
|
||||||
entry.u.func = copyfunc(func);
|
entry.u.func = copyfunc(func);
|
||||||
addcmdentry(name, &entry);
|
addcmdentry(func->narg.text, &entry);
|
||||||
INT_ON;
|
INT_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8654,7 +8654,7 @@ evaltree(union node *n, int flags)
|
|||||||
status = 0;
|
status = 0;
|
||||||
goto setstatus;
|
goto setstatus;
|
||||||
case NDEFUN:
|
case NDEFUN:
|
||||||
defun(n->narg.text, n->narg.next);
|
defun(n);
|
||||||
/* Not necessary. To test it:
|
/* Not necessary. To test it:
|
||||||
* "false; f() { qwerty; }; echo $?" should print 0.
|
* "false; f() { qwerty; }; echo $?" should print 0.
|
||||||
*/
|
*/
|
||||||
@@ -9079,7 +9079,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
|
|||||||
shellparam.optind = 1;
|
shellparam.optind = 1;
|
||||||
shellparam.optoff = -1;
|
shellparam.optoff = -1;
|
||||||
#endif
|
#endif
|
||||||
evaltree(&func->n, flags & EV_TESTED);
|
evaltree(func->n.narg.next, flags & EV_TESTED);
|
||||||
funcdone:
|
funcdone:
|
||||||
INT_OFF;
|
INT_OFF;
|
||||||
funcnest--;
|
funcnest--;
|
||||||
|
Reference in New Issue
Block a user