Dixi quod…

>Commit ID:     10058E5A1067AFA1BBA

>Log message:
>fix reentrancy of 'typeset -f' output in the face of aliases; also,
>move alias handling for COMSUBs and friends to parse time by request
>of Martijn Dekker (and for consistency with function definitions)

Oh well. For the sake of consistency. But fixing this DID uncover
a re-entrancy bug in 'typeset -f' ouput (which IS also used in some
other places internally):

The old comsub-5 tested this:

        print '#!/bin/mksh\nfor x in "$@"; do print -r -- "$x"; done' >pfn
        chmod +x pfn
        alias echo='echo a'
        foo() {
                ./pfn "$(echo foo)"
        }
        typeset -f foo
expected-stdout:
        foo() {
                ./pfn "$(echo foo )"
        }

But what if we try to re-enter it?

        print '#!/bin/mksh\nfor x in "$@"; do print -r -- "$x"; done' >pfn
        chmod +x pfn
        alias echo='echo a'
        foo() {
                echo moo
                ./pfn "$(echo foo)"
        }
        typeset -f foo >x
        cat x
        foo
        . ./x
        typeset -f foo
        foo

When deferring alias interpretation until the end, we do get:

        foo() {
                echo a moo
                ./pfn "$(echo foo )"
        }
        a moo
        a foo
        foo() {
                echo a a moo
                ./pfn "$(echo foo )"
        }
        a a moo
        a foo

With this, we also get:

        alias echo=print
        x() { echo a; (echo b); x=$(echo c); }
        typeset -f x
⇒
        x() {
                print a
                ( print b )
                x=$(echo c )
        }

This is problematic (in the first two) and inconsistent (in the last) case.

With the code I committed, we get:

        foo() {
                \echo a moo
                ./pfn "$(\echo a foo )"
        }
        a moo
        a foo
        foo() {
                \echo a moo
                ./pfn "$(\echo a foo )"
        }
        a moo
        a foo

To make this work but not get “\./pfn” stupidly, I had to limit the
allowed characters in “alias”, but ksh93 does so too, as does POSIX.


So, in the end… yes, thank you.

Welterusten,
//mirabilos (who doesn’t get enough Cider for this)

PS: sleepless unite! ☺
-- 
<igli> exceptions: a truly awful implementation of quite a nice idea.
<igli> just about the worst way you could do something like that, afaic.
<igli> it's like anti-design.  <mirabilos> that too… may I quote you on that?
<igli> sure, tho i doubt anyone will listen ;)

Reply via email to