• fix an inverted logic bug in the test I wrote
• only trigger deleting an alias in favour of a function for “()”, not just the opening parenthesis: “stop( )” is not a function definition (well, actually it seems to be, but… not according to POSIX, anyway) • defer dropping the alias until the function is actually defined (õÕ)
This commit is contained in:
parent
c38dfbf51a
commit
40e914e8a5
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.452 2011/05/07 00:02:26 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.453 2011/05/07 00:51:09 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
@ -6046,7 +6046,7 @@ description:
|
||||
Functions should only take over if actually being defined
|
||||
stdin:
|
||||
alias local
|
||||
false || local() { :; }
|
||||
:|| local() { :; }
|
||||
alias local
|
||||
expected-stdout:
|
||||
local=typeset
|
||||
|
13
exec.c
13
exec.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.90 2011/04/17 15:40:35 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.91 2011/05/07 00:51:11 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||
@ -962,11 +962,20 @@ findfunc(const char *name, uint32_t h, bool create)
|
||||
int
|
||||
define(const char *name, struct op *t)
|
||||
{
|
||||
uint32_t nhash;
|
||||
struct tbl *tp;
|
||||
bool was_set = false;
|
||||
|
||||
nhash = hash(name);
|
||||
|
||||
if (t != NULL && !tobool(t->u.ksh_func)) {
|
||||
/* drop same-name aliases for POSIX functions */
|
||||
if ((tp = ktsearch(&aliases, name, nhash)))
|
||||
ktdelete(tp);
|
||||
}
|
||||
|
||||
while (/* CONSTCOND */ 1) {
|
||||
tp = findfunc(name, hash(name), true);
|
||||
tp = findfunc(name, nhash, true);
|
||||
|
||||
if (tp->flag & ISSET)
|
||||
was_set = true;
|
||||
|
10
lex.c
10
lex.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.149 2011/05/07 00:24:34 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.150 2011/05/07 00:51:12 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -1101,13 +1101,7 @@ yylex(int cf)
|
||||
*/
|
||||
++cp;
|
||||
/* prefer functions over aliases */
|
||||
if (*cp == '(' /*)*/)
|
||||
/*
|
||||
* delete alias upon encountering function
|
||||
* definition
|
||||
*/
|
||||
ktdelete(p);
|
||||
else {
|
||||
if (cp[0] != '(' || cp[1] != ')') {
|
||||
Source *s = source;
|
||||
|
||||
while (s && (s->flags & SF_HASALIAS))
|
||||
|
6
syn.c
6
syn.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.63 2011/05/05 00:05:01 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.64 2011/05/07 00:51:12 tg Exp $");
|
||||
|
||||
extern short subshell_nesting_level;
|
||||
|
||||
@ -652,15 +652,11 @@ function_body(char *name,
|
||||
*/
|
||||
if (ksh_func) {
|
||||
if (tpeek(CONTIN|KEYWORD|ALIAS) == '(' /*)*/) {
|
||||
struct tbl *tp;
|
||||
|
||||
/* function foo () { */
|
||||
ACCEPT;
|
||||
musthave(')', 0);
|
||||
/* degrade to POSIX function */
|
||||
ksh_func = false;
|
||||
if ((tp = ktsearch(&aliases, sname, hash(sname))))
|
||||
ktdelete(tp);
|
||||
}
|
||||
musthave('{' /*}*/, CONTIN|KEYWORD|ALIAS);
|
||||
REJECT;
|
||||
|
Loading…
Reference in New Issue
Block a user