mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This commit fixes at least three bugs:
1. When issuing 'typeset -p' for unset variables typeset as short
integer, a value of 0 was incorrectly diplayed.
2. ${x=y} and ${x:=y} were still broken for short integer types
(re: 9f2389ed). ${x+set} and ${x:+nonempty} were also broken.
3. A memory fault could occur if typeset -l followed a -s option
with integers. Additonally, now the last -s/-l wins out as the
option to utilize instead of it always being short.
src/cmd/ksh93/include/name.h:
- Fix the nv_isnull() macro by removing the direct exclusion of
short integers from this set/unset test. This breaks few things
(only ${.sh.subshell} and ${.sh.level}, as far as we can tell)
while potentially correcting many aspects of short integer use
(at least bugs 1 and 2 above), as this macro is widely used.
- union Value: add new pid_t *pidp pointer member for PID values
(see further below).
src/cmd/ksh93/bltins/typeset.c: b_typeset():
- To fix bug 3 above, unset the 'shortint' flag and NV_SHORT
attribute bit upon encountering the -l optiobn.
*** To fix ${.sh.subshell} to work with the new nv_isnull():
src/cmd/ksh93/sh/defs.h:
- Add new 'realsubshell' member to the shgd (aka shp->gd) struct
which will be the integer value for ${.sh.subshell}.
src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/data/variables.c:
- Initialize SH_SUBSHELLNOD as a pointer to shgd->realsubshell
instead of using a short value (.s) directly. Using a pointer
allows nv_isnull() to return a positive for ${.sh.subshell} as
a non-null pointer is what it checks for.
- While we're at it, initialize PPIDNOD ($PPID) and SH_PIDNOD
(${.sh.pid}) using the new pdip union member, which is more
correct as they are values of type pid_t.
src/cmd/ksh93/sh/subshell.c,
src/cmd/ksh93/sh/xec.c:
- Update the ${.sh.subshell} increases/decreases to refer to
shgd->realsubshell (a.k.a. shp->gd->realsubshell).
*** To fix ${.sh.level} after changing nv_isnull():
src/cmd/ksh93/sh/macro.c: varsub():
- Add a specific exception for SH_LEVLNOD to the nv_isnull() test,
so that ${.sh.level} is always considered to be set. Its handling
throughout the code is too complex/special for a simple fix, so
we have to special-case it, at least for now.
*** Regression test additions:
src/cmd/ksh93/tests/attributes.sh:
- Add in missing short integer tests and correct the one that
existed. The -si test now yields 'typeset -x -r -s -i foo'
instead of 'typeset -x -r -s -i foo=0' which brings it in line
with all the others.
- Add in some other -l attribute tests for floats. Note, -lX test
was not added as the size of long double is platform dependent.
src/cmd/ksh93/tests/variables.sh:
- Add tests for ${x=y} and ${x:=y} used on short int variables.
Co-authored-by: Martijn Dekker <martijn@inlv.org>
133 lines
4.5 KiB
C
133 lines
4.5 KiB
C
/***********************************************************************
|
|
* *
|
|
* This software is part of the ast package *
|
|
* Copyright (c) 1982-2012 AT&T Intellectual Property *
|
|
* and is licensed under the *
|
|
* Eclipse Public License, Version 1.0 *
|
|
* by AT&T Intellectual Property *
|
|
* *
|
|
* A copy of the License is available at *
|
|
* http://www.eclipse.org/org/documents/epl-v10.html *
|
|
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
|
* *
|
|
* Information and Software Systems Research *
|
|
* AT&T Research *
|
|
* Florham Park NJ *
|
|
* *
|
|
* David Korn <dgk@research.att.com> *
|
|
* *
|
|
***********************************************************************/
|
|
#pragma prototyped
|
|
|
|
#include <ast.h>
|
|
#include "FEATURE/options"
|
|
#include "FEATURE/dynamic"
|
|
#include <shell.h>
|
|
#include "shtable.h"
|
|
#include "name.h"
|
|
#include "defs.h"
|
|
#include "variables.h"
|
|
#include "builtins.h"
|
|
|
|
/*
|
|
* This is the list of built-in shell variables and default values
|
|
* and default attributes.
|
|
*
|
|
* The order must be kept synchronous with the defines in include/variables.h.
|
|
*/
|
|
|
|
const struct shtable2 shtab_variables[] =
|
|
{
|
|
"PATH", 0, (char*)0,
|
|
"PS1", 0, (char*)0,
|
|
"PS2", NV_NOFREE, "> ",
|
|
"IFS", NV_NOFREE, " \t\n",
|
|
"PWD", 0, (char*)0,
|
|
"HOME", 0, (char*)0,
|
|
"MAIL", 0, (char*)0,
|
|
"REPLY", 0, (char*)0,
|
|
"SHELL", NV_NOFREE, "/bin/" SH_STD,
|
|
"EDITOR", 0, (char*)0,
|
|
"MAILCHECK", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"RANDOM", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"ENV", NV_NOFREE, (char*)0,
|
|
"HISTFILE", 0, (char*)0,
|
|
"HISTSIZE", 0, (char*)0,
|
|
"HISTEDIT", NV_NOFREE, (char*)0,
|
|
"HISTCMD", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"FCEDIT", NV_NOFREE, &e_defedit[0],
|
|
"CDPATH", 0, (char*)0,
|
|
"MAILPATH", 0, (char*)0,
|
|
"PS3", NV_NOFREE, "#? ",
|
|
"OLDPWD", 0, (char*)0,
|
|
"VISUAL", 0, (char*)0,
|
|
"COLUMNS", 0, (char*)0,
|
|
"LINES", 0, (char*)0,
|
|
"PPID", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"_", NV_EXPORT, (char*)0,
|
|
"TMOUT", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"SECONDS", NV_NOFREE|NV_INTEGER|NV_DOUBLE, (char*)0,
|
|
"LINENO", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"OPTARG", 0, (char*)0,
|
|
"OPTIND", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
"PS4", 0, (char*)0,
|
|
"FPATH", 0, (char*)0,
|
|
"LANG", 0, (char*)0,
|
|
"LC_ALL", 0, (char*)0,
|
|
"LC_COLLATE", 0, (char*)0,
|
|
"LC_CTYPE", 0, (char*)0,
|
|
"LC_MESSAGES", 0, (char*)0,
|
|
"LC_NUMERIC", 0, (char*)0,
|
|
"FIGNORE", 0, (char*)0,
|
|
"KSH_VERSION", 0, (char*)0,
|
|
"JOBMAX", NV_NOFREE|NV_INTEGER, (char*)0,
|
|
".sh", NV_TABLE|NV_NOFREE|NV_NOPRINT, (char*)0,
|
|
".sh.edchar", 0, (char*)0,
|
|
".sh.edcol", 0, (char*)0,
|
|
".sh.edtext", 0, (char*)0,
|
|
".sh.edmode", 0, (char*)0,
|
|
".sh.name", 0, (char*)0,
|
|
".sh.subscript",0, (char*)0,
|
|
".sh.value", 0, (char*)0,
|
|
".sh.version", NV_NOFREE, (char*)(&e_version[10]),
|
|
".sh.dollar", 0, (char*)0,
|
|
".sh.match", 0, (char*)0,
|
|
".sh.command", 0, (char*)0,
|
|
".sh.file", 0, (char*)0,
|
|
".sh.fun", 0, (char*)0,
|
|
".sh.subshell", NV_INTEGER|NV_NOFREE, (char*)0,
|
|
".sh.level", 0, (char*)0,
|
|
".sh.lineno", NV_INTEGER|NV_NOFREE, (char*)0,
|
|
".sh.stats", 0, (char*)0,
|
|
".sh.math", 0, (char*)0,
|
|
".sh.pool", 0, (char*)0,
|
|
".sh.pid", NV_INTEGER|NV_NOFREE, (char*)0,
|
|
"SHLVL", NV_INTEGER|NV_NOFREE|NV_EXPORT, (char*)0,
|
|
#if SHOPT_MULTIBYTE
|
|
"CSWIDTH", 0, (char*)0,
|
|
#endif /* SHOPT_MULTIBYTE */
|
|
"", 0, (char*)0
|
|
};
|
|
|
|
const char *nv_discnames[] = { "get", "set", "append", "unset", "getn", 0 };
|
|
|
|
#if SHOPT_STATS
|
|
const Shtable_t shtab_stats[] =
|
|
{
|
|
"arg_cachehits", STAT_ARGHITS,
|
|
"arg_expands", STAT_ARGEXPAND,
|
|
"comsubs", STAT_COMSUB,
|
|
"forks", STAT_FORKS,
|
|
"funcalls", STAT_FUNCT,
|
|
"globs", STAT_GLOBS,
|
|
"linesread", STAT_READS,
|
|
"nv_cachehit", STAT_NVHITS,
|
|
"nv_opens", STAT_NVOPEN,
|
|
"pathsearch", STAT_PATHS,
|
|
"posixfuncall", STAT_SVFUNCT,
|
|
"simplecmds", STAT_SCMDS,
|
|
"spawns", STAT_SPAWN,
|
|
"subshell", STAT_SUBSHELL
|
|
};
|
|
#endif /* SHOPT_STATS */
|
|
|