* readonly bug
@ 1997-01-07 13:56 Peter Stephenson
1997-01-07 17:09 ` Zoltan Hidvegi
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 1997-01-07 13:56 UTC (permalink / raw)
To: Zsh hackers list
haven't time to check this out further just now:
(there was some IFS stuff around to make this useful but it turns out that's
not necessary)
% readonly vers=foo
% vers=(${=ZSH_VERSION})
Segmentation fault (core dumped)
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: readonly bug
1997-01-07 13:56 readonly bug Peter Stephenson
@ 1997-01-07 17:09 ` Zoltan Hidvegi
1997-01-07 17:28 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Zoltan Hidvegi @ 1997-01-07 17:09 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
Peter Stephenson wrote:
> haven't time to check this out further just now:
> (there was some IFS stuff around to make this useful but it turns out that's
> not necessary)
>
> % readonly vers=foo
> % vers=(${=ZSH_VERSION})
> Segmentation fault (core dumped)
Unfortunately read-only variables are not handled very well in most places.
Here is a fix. After that zsh prints error message when you attempt to
change a read-only variable. Patch applies to both zsh-3.0.2 and zsh-3.1.0
It makes createparam() fail and return NULL when you attempt to crearte an
existing non-local parameter.
Zoltan
*** Src/builtin.c 1997/01/05 23:33:32 3.1.1.10
--- Src/builtin.c 1997/01/07 16:27:56
***************
*** 1842,1847 ****
--- 1842,1851 ----
}
} else {
if (bit) {
+ if (pm->flags & PM_READONLY) {
+ on |= ~off & PM_READONLY;
+ pm->flags &= ~PM_READONLY;
+ }
if (!asg->value)
asg->value = dupstring(getsparam(asg->name));
unsetparam(asg->name);
***************
*** 1850,1857 ****
addlinknode(locallist, ztrdup(asg->name));
} LASTALLOC;
}
! /* create a new node for a parameter with the flags in `on' minus the readonly flag */
pm = createparam(ztrdup(asg->name), on & ~PM_READONLY);
pm->ct = auxlen;
if (func != BIN_EXPORT)
pm->level = locallevel;
--- 1854,1863 ----
addlinknode(locallist, ztrdup(asg->name));
} LASTALLOC;
}
! /* create a new node for a parameter with the *
! * flags in `on' minus the readonly flag */
pm = createparam(ztrdup(asg->name), on & ~PM_READONLY);
+ DPUTS(!pm, "BUG: parameter not created");
pm->ct = auxlen;
if (func != BIN_EXPORT)
pm->level = locallevel;
*** Src/exec.c 1997/01/06 20:41:03 3.1.1.6
--- Src/exec.c 1997/01/07 16:09:45
***************
*** 1806,1813 ****
if (removelist) {
/* remove temporary parameters */
! while ((s = (char *) ugetnode(removelist)))
! unsetparam(s);
}
if (restorelist) {
--- 1806,1818 ----
if (removelist) {
/* remove temporary parameters */
! while ((s = (char *) ugetnode(removelist))) {
! if ((pm = (Param) paramtab->getnode(paramtab, s)) &&
! !(pm->flags & PM_SPECIAL)) {
! pm->flags &= ~PM_READONLY;
! unsetparam_pm(pm, 0);
! }
! }
}
if (restorelist) {
*** params.c 1997/01/05 21:07:31 3.1.1.7
--- params.c 1997/01/07 16:56:19
***************
*** 173,187 ****
spec = oldpm && (oldpm->flags & PM_SPECIAL);
if ((oldpm && oldpm->level == locallevel) || spec) {
pm = oldpm;
pm->ct = 0;
oldpm = pm->old;
! pm->flags = (flags & (PM_EXPORTED | PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z |
! PM_LOWER | PM_UPPER | PM_READONLY | PM_TAGGED)) |
(pm->flags & (PM_SCALAR | PM_INTEGER | PM_ARRAY | PM_SPECIAL));
! if (pm->ename && (altpm = (Param) paramtab->getnode(paramtab, pm->ename))) {
! altpm->flags &= ~(PM_UNSET | PM_EXPORTED | PM_LEFT | PM_RIGHT_B |
! PM_RIGHT_Z | PM_LOWER | PM_UPPER | PM_READONLY | PM_TAGGED);
}
} else {
pm = (Param) zcalloc(sizeof *pm);
--- 173,192 ----
spec = oldpm && (oldpm->flags & PM_SPECIAL);
if ((oldpm && oldpm->level == locallevel) || spec) {
+ if (oldpm && !(oldpm->flags & PM_UNSET))
+ return NULL;
pm = oldpm;
pm->ct = 0;
oldpm = pm->old;
! pm->flags = (flags & (PM_EXPORTED | PM_LEFT | PM_RIGHT_B |
! PM_RIGHT_Z | PM_LOWER | PM_UPPER |
! PM_READONLY | PM_TAGGED | PM_UNIQUE)) |
(pm->flags & (PM_SCALAR | PM_INTEGER | PM_ARRAY | PM_SPECIAL));
! if (pm->ename &&
! (altpm = (Param) paramtab->getnode(paramtab, pm->ename))) {
! altpm->flags &= ~(PM_UNSET | PM_UNIQUE | PM_UPPER | PM_LEFT |
! PM_RIGHT_B | PM_RIGHT_Z | PM_LOWER |
! PM_READONLY | PM_TAGGED | PM_EXPORTED);
}
} else {
pm = (Param) zcalloc(sizeof *pm);
***************
*** 771,776 ****
--- 776,782 ----
MUSTUSEHEAP("setstrvalue");
if (v->pm->flags & PM_READONLY) {
+ zerr("read-only variable: %s", v->pm->nam, 0);
zsfree(val);
return;
}
***************
*** 847,854 ****
{
char buf[DIGBUFSIZE];
! if (v->pm->flags & PM_READONLY)
return;
switch (PM_TYPE(v->pm->flags)) {
case PM_SCALAR:
case PM_ARRAY:
--- 853,862 ----
{
char buf[DIGBUFSIZE];
! if (v->pm->flags & PM_READONLY) {
! zerr("read-only variable: %s", v->pm->nam, 0);
return;
+ }
switch (PM_TYPE(v->pm->flags)) {
case PM_SCALAR:
case PM_ARRAY:
***************
*** 880,885 ****
--- 888,894 ----
setarrvalue(Value v, char **val)
{
if (v->pm->flags & PM_READONLY) {
+ zerr("read-only variable: %s", v->pm->nam, 0);
freearray(val);
return;
}
***************
*** 1060,1065 ****
--- 1069,1075 ----
}
if (!(v = getvalue(&s, 1))) {
pm = createparam(t, PM_INTEGER);
+ DPUTS(!pm, "BUG: parameter not created");
pm->u.val = val;
return pm;
}
***************
*** 1088,1095 ****
Param oldpm, altpm;
int spec;
! if ((pm->flags & PM_READONLY) && pm->level <= locallevel)
return;
spec = (pm->flags & PM_SPECIAL) && !pm->level;
switch (PM_TYPE(pm->flags)) {
case PM_SCALAR:
--- 1098,1107 ----
Param oldpm, altpm;
int spec;
! if ((pm->flags & PM_READONLY) && pm->level <= locallevel) {
! zerr("read-only variable: %s", pm->nam, 0);
return;
+ }
spec = (pm->flags & PM_SPECIAL) && !pm->level;
switch (PM_TYPE(pm->flags)) {
case PM_SCALAR:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: readonly bug
1997-01-07 17:09 ` Zoltan Hidvegi
@ 1997-01-07 17:28 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1997-01-07 17:28 UTC (permalink / raw)
To: zsh-workers
Zoltan Hidvegi wrote:
> Unfortunately read-only variables are not handled very well in most places.
> Here is a fix. After that zsh prints error message when you attempt to
> change a read-only variable. Patch applies to both zsh-3.0.2 and zsh-3.1.0
Thanks. Actually, I was relying on the failure being silent,
otherwise what I was trying to do (suppress an error message from a
bad assignment in a system script I couldn't access) wouldn't work.
However, this corresponds to what ksh does. I suppose I can't expect
unsupported hacks to work. The script's now been fixed anyway.
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-01-07 17:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-07 13:56 readonly bug Peter Stephenson
1997-01-07 17:09 ` Zoltan Hidvegi
1997-01-07 17:28 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).