optimise away code for a case that’s almost unlikely to happen; fix pasto(?)

This commit is contained in:
tg 2016-07-24 23:07:19 +00:00
parent e0e63c65e6
commit 5401a55a98
2 changed files with 14 additions and 20 deletions

30
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.175 2016/06/26 00:44:58 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.176 2016/07/24 23:07:19 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -715,39 +715,33 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
struct tbl *ftp; struct tbl *ftp;
if (!tp->u.fpath) { if (!tp->u.fpath) {
fpath_error:
rv = (tp->u2.errnov == ENOENT) ? 127 : 126; rv = (tp->u2.errnov == ENOENT) ? 127 : 126;
warningf(true, "%s: %s %s: %s", cp, warningf(true, "%s: %s %s: %s", cp,
"can't find", "function definition file", "can't find", "function definition file",
cstrerror(tp->u2.errnov)); cstrerror(tp->u2.errnov));
break; break;
} }
if (include(tp->u.fpath, 0, NULL, false) < 0) { errno = 0;
if (include(tp->u.fpath, 0, NULL, false) < 0 ||
!(ftp = findfunc(cp, hash(cp), false)) ||
!(ftp->flag & ISSET)) {
rv = errno;
if (!strcmp(cp, Tcat)) { if (!strcmp(cp, Tcat)) {
no_cat_in_FPATH:
tp = findcom(Tcat, FC_BI); tp = findcom(Tcat, FC_BI);
goto do_call_builtin; goto do_call_builtin;
} }
#ifdef MKSH_PRINTF_BUILTIN #ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf)) { if (!strcmp(cp, Tprintf)) {
no_printf_in_FPATH:
tp = findcom(Tprintf, FC_BI); tp = findcom(Tprintf, FC_BI);
goto do_call_builtin; goto do_call_builtin;
} }
#endif #endif
warningf(true, "%s: %s %s %s: %s", cp, if (rv) {
"can't open", "function definition file", tp->u2.errnov = rv;
tp->u.fpath, cstrerror(errno)); cp = tp->u.fpath;
rv = 127; goto fpath_error;
break; }
}
if (!(ftp = findfunc(cp, hash(cp), false)) ||
!(ftp->flag & ISSET)) {
if (!strcmp(cp, Tcat))
goto no_cat_in_FPATH;
#ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf))
goto no_printf_in_FPATH;
#endif
warningf(true, "%s: %s %s", cp, warningf(true, "%s: %s %s", cp,
"function not defined by", tp->u.fpath); "function not defined by", tp->u.fpath);
rv = 127; rv = 127;

4
shf.c
View File

@ -25,7 +25,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.74 2016/05/17 15:36:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.75 2016/07/24 23:07:19 tg Exp $");
/* flags to shf_emptybuf() */ /* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */ #define EB_READSW 0x01 /* about to switch to reading */
@ -457,7 +457,7 @@ shf_read(char *buf, ssize_t bsize, struct shf *shf)
(unsigned int)shf->flags); (unsigned int)shf->flags);
if (bsize <= 0) if (bsize <= 0)
internal_errorf("%s: %s %zd", "shf_write", "bsize", bsize); internal_errorf("%s: %s %zd", "shf_read", "bsize", bsize);
while (bsize > 0) { while (bsize > 0) {
if (shf->rnleft == 0 && if (shf->rnleft == 0 &&