mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix $LINENO corruption when autoloading functions
Autoloading a function caused the calling script's $LINENO to be off by the number of lines in the function definition file. In addition, while running autoloaded functions, errors/warnings were reported with wrong line numbers. src/cmd/ksh93/sh/path.c: - Save $LINENO (shp->inlineno) before autoloading a function, reset it to 1 so that the correct line number offset is remembered for the function definition, and restore it after. src/cmd/ksh93/tests/variables.sh: - Add regression test for $LINENO, directly and in error messages, within and outside a non-autoloaded and an autoloaded function. Fixes: https://github.com/ksh93/ksh/issues/116
This commit is contained in:
parent
be22f3759e
commit
d89ef0fafa
3 changed files with 54 additions and 1 deletions
|
|
@ -582,7 +582,7 @@ static void funload(Shell_t *shp,int fno, const char *name)
|
|||
char *pname,*oldname=shp->st.filename, buff[IOBSIZE+1];
|
||||
Namval_t *np;
|
||||
struct Ufunction *rp,*rpfirst;
|
||||
int savestates = sh_getstate(), oldload=shp->funload;
|
||||
int savestates = sh_getstate(), oldload=shp->funload, savelineno = shp->inlineno;
|
||||
pname = path_fullname(shp,stakptr(PATH_OFFSET));
|
||||
if(shp->fpathdict && (rp = dtmatch(shp->fpathdict,(void*)pname)))
|
||||
{
|
||||
|
|
@ -615,6 +615,7 @@ static void funload(Shell_t *shp,int fno, const char *name)
|
|||
shp->readscript = (char*)name;
|
||||
shp->st.filename = pname;
|
||||
shp->funload = 1;
|
||||
shp->inlineno = 1;
|
||||
error_info.line = 0;
|
||||
sh_eval(sfnew(NIL(Sfio_t*),buff,IOBSIZE,fno,SF_READ),SH_FUNEVAL);
|
||||
sh_close(fno);
|
||||
|
|
@ -631,6 +632,7 @@ static void funload(Shell_t *shp,int fno, const char *name)
|
|||
pname = 0;
|
||||
free((void*)shp->st.filename);
|
||||
shp->funload = oldload;
|
||||
shp->inlineno = savelineno;
|
||||
shp->st.filename = oldname;
|
||||
sh_setstate(savestates);
|
||||
if(pname)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue