Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] posix_builtins: allow exporting a reaonly



Op 18-04-18 om 22:07 schreef Bart Schaefer:
On Wed, Apr 18, 2018 at 12:58 PM, Martijn Dekker <martijn@xxxxxxxx> wrote:
POSIX_BUILTINS incorrectly prohibits exporting a readonly variable. All
other POSIX shells allow this and there is nothing in the POSIX text[*] that
says it's not allowed. The attached patch fixes this.

I hope it's really that simple -- see thread about typeset -T and
read-only and resulting confusion, e.g. zsh-workers/42061 and
references.

I can't really find anything in that thread or its references that seems relevant.

Exporting readonly variables was already possible with POSIXBUILTINS off, so I don't see how it could harm anything to allow it with POSIXBUILTINS on.

Here is some more context than was provided by the patch. Note that all of this is only executed if POSIXBUILTINS is on.

    if (isset(POSIXBUILTINS)) {
        /*
         * Stricter rules about retaining readonly attribute in this case.
         */
        if ((on & (PM_READONLY|PM_EXPORTED)) &&
            (!usepm || (pm->node.flags & PM_UNSET)) &&
            !ASG_VALUEP(asg))
            on |= PM_UNSET;
        else if (usepm && (pm->node.flags & PM_READONLY) &&
                 !(on & PM_READONLY) && !(on & PM_EXPORTED)) {
            zerr("read-only variable: %s", pm->node.nam);
            return NULL;
        }
    }

As the comment says, that block applies stricter rules about retaining the readonly attribute for POSIXBUILTINS. I merely removed the restriction that readonly variables cannot be exported by adding:

	 && !(on & PM_EXPORTED)

Note that the restriction was already inconsistent: this code did not block unset readonly variables from being given the export flag.

FWIW, the test suite passes cleanly with this patch.

Thanks,

- M.



Messages sorted by: Reverse Date, Date, Thread, Author