zsh-workers
 help / color / mirror / code / Atom feed
* zkbd fails: must be run as a function or shell script, not sourced
@ 2008-03-13 20:27 Frank Terbeck
  2008-03-13 20:35 ` Mikael Magnusson
  2008-03-13 23:28 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Frank Terbeck @ 2008-03-13 20:27 UTC (permalink / raw)
  To: zsh workers

Hi workers,

The zkbd function currently fails to start. In particular, it seems to
be the following test (I don't actually understand how that test works
at all :-):

[snip]
[[ -o interactive ]] && {
    local -i ARGC
    (ARGC=0) 2>/dev/null || {
        print -u2 ${0}: must be run as a function or shell script, not sourced
        return 1
    }
}
[snap]

Since this worked before, I git-bisected my way through the younger
zsh code history and I was able to find the commit that breaks it for
me.

The last working commit that works is this:

  2007-05-28 13:08 pws
      23478: crash in reverse-menu-complete if no completion

And the next commit (the one that breaks it) is:

  2007-05-28 22:57 pws
      see 23479: add initial features support for modules

Since these are commits in a cvs->git conversion of the zsh tree, here
is some extra information to locate the change I'm referring to (in
case the conversion is not accurate enough):

The commit adds this Changelog entry:

[snip]
       * Not posted but see 23479:Completion/Unix/Command/_chmod,
       Completion/Unix/Command/_chown, Completion/Unix/Command/_cvs,
       Completion/Unix/Type/_list_files, Completion/Zsh/Command/_stat,
       Completion/Zsh/Command/_zstyle,
       Completion/Zsh/Type/_file_descriptors,Doc/Zsh/builtins.yo,
       Doc/Zsh/compsys.yo, Doc/Zsh/mod_stat.yo,
       Etc/zsh-development-guide, Src/builtin.c, Src/cond.c, Src/exec.c
       Src/init.c, Src/mkbltnmlst.sh, Src/mkmakemod.sh, Src/modentry.c,
       Src/module.c, Src/params.c, Src/zsh.h, Src/Builtins/rlimits.c,
       Src/Builtins/sched.c, Src/Modules/cap.c, Src/Modules/clone.c,
       Src/Modules/datetime.c, Src/Modules/example.c,
       Src/Modules/files.c, Src/Modules/langinfo.c,
       Src/Modules/langinfo.mdd, Src/Modules/mapfile.c,
       Src/Modules/mathfunc.c, Src/Modules/parameter.c,
       Src/Modules/pcre.c, Src/Modules/regex.c, Src/Modules/socket.c,
       Src/Modules/stat.c, Src/Modules/system.c, Src/Modules/tcp.c,
       Src/Modules/termcap.c, Src/Modules/terminfo.c, Src/Modules/zftp.c,
       Src/Modules/zprof.c, Src/Modules/zpty.c, Src/Modules/zselect.c,
       Src/Modules/zutil.c, Src/Zle/compctl.c, Src/Zle/complete.c,
       Src/Zle/complist.c, Src/Zle/computil.c, Src/Zle/deltochar.c,
       Src/Zle/zle_main.c, Src/Zle/zle_thingy.c, Src/Zle/zle_tricky.c,
       Src/Zle/zleparameter.c, Test/B02typeset.ztst,
       Test/V01zmodload.ztst, Test/V04features.ztst: add "zmodload -F"
       and internal features support for modules.
[snap]

Unfortunately, the commit is rather big, so I won't be able to find
the problematic part on my own. I did create a diff between the two
commits in question and uploaded it to:

  <http://ft.bewatermyfriend.org/tmp/zsh_breaks.diff>

I hope that helps.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zkbd fails: must be run as a function or shell script, not sourced
  2008-03-13 20:27 zkbd fails: must be run as a function or shell script, not sourced Frank Terbeck
@ 2008-03-13 20:35 ` Mikael Magnusson
  2008-03-13 20:52   ` Frank Terbeck
  2008-03-13 23:28 ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2008-03-13 20:35 UTC (permalink / raw)
  To: zsh workers

On 13/03/2008, Frank Terbeck <ft@bewatermyfriend.org> wrote:
> Hi workers,
>
>  The zkbd function currently fails to start. In particular, it seems to
>  be the following test (I don't actually understand how that test works
>  at all :-):
>
>  [snip]
>  [[ -o interactive ]] && {
>     local -i ARGC
>     (ARGC=0) 2>/dev/null || {
>         print -u2 ${0}: must be run as a function or shell script, not sourced
>         return 1
>     }
>  }
>  [snap]
>
>  Since this worked before, I git-bisected my way through the younger
>  zsh code history and I was able to find the commit that breaks it for
>  me.

fwiw, with current cvs i get this, which seems to be the intended result:
{21:31:03|~}% zsh .zsh/zkbd
Enter current terminal type: [rxvt-unicode]
{21:31:07|~}% source .zsh/zkbd
.zsh/zkbd: must be run as a function or shell script, not sourced
{21:31:09|~}% .zsh/zkbd
zsh: command not found: .zsh/zkbd
{21:31:12|~}% +x .zsh/zkbd
{21:31:12|~}% .zsh/zkbd
Enter current terminal type: [rxvt-unicode]

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zkbd fails: must be run as a function or shell script, not sourced
  2008-03-13 20:35 ` Mikael Magnusson
@ 2008-03-13 20:52   ` Frank Terbeck
  0 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2008-03-13 20:52 UTC (permalink / raw)
  To: zsh workers

Mikael Magnusson <mikachu@gmail.com>:
> On 13/03/2008, Frank Terbeck <ft@bewatermyfriend.org> wrote:
> >  The zkbd function currently fails to start. In particular, it seems to
[...]
> >  Since this worked before, I git-bisected my way through the younger
> >  zsh code history and I was able to find the commit that breaks it for
> >  me.
> 
> fwiw, with current cvs i get this, which seems to be the intended result:

No, it does not work as intended (this is the current CVS HEAD):

[snip]
% zsh -f
zsh% autoload zkbd
zsh% zkbd
zkbd: must be run as a function or shell script, not sourced
[snap]

This *is* calling zkbd as a function, which worked before and breaks
now.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zkbd fails: must be run as a function or shell script, not sourced
  2008-03-13 20:27 zkbd fails: must be run as a function or shell script, not sourced Frank Terbeck
  2008-03-13 20:35 ` Mikael Magnusson
@ 2008-03-13 23:28 ` Bart Schaefer
  2008-03-14 19:57   ` Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2008-03-13 23:28 UTC (permalink / raw)
  To: zsh workers

On Mar 13,  9:27pm, Frank Terbeck wrote:
}
} The zkbd function currently fails to start. In particular, it seems to
} be the following test (I don't actually understand how that test works
} at all :-):
} 
} [snip]
} [[ -o interactive ]] && {
}     local -i ARGC
}     (ARGC=0) 2>/dev/null || {
}         print -u2 ${0}: must be run as a function or shell script, not sourced
}         return 1
}     }
} }
} [snap]

If you remove the "2>/dev/null" you get the error message:

zkbd:5: read-only variable: ARGC

The trick here is that, at the top level of the shell, declaring ARGC to
be local is a no-op.  Inside a function, however, declaring it local is
creating a new parameter, which should lose its read-only-ness.  Somehow
ARGC has lost the PM_HIDE attribute.

Changing "local -i ARGC" to "local -ih ARGC" to explicitly hide the
special-ness of ARGC will make zkbd work again, but I am puzzled as to
why it suddenly became necessary to include "-h".  The call signature
of load_module() changed a bit and consequently so did module.c, but
I can't see how that would have changed the way the builtin special
parameters are created; the IPDEF1 macro and its usage for ARGC have
not changed in quite some time.

So although I say "lost PM_HIDE", in point of fact I don't know how it
had PM_HIDE in the first place.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zkbd fails: must be run as a function or shell script, not sourced
  2008-03-13 23:28 ` Bart Schaefer
@ 2008-03-14 19:57   ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2008-03-14 19:57 UTC (permalink / raw)
  To: zsh workers

On Thu, 13 Mar 2008 16:28:18 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> If you remove the "2>/dev/null" you get the error message:
> 
> zkbd:5: read-only variable: ARGC
> 
>...
> So although I say "lost PM_HIDE", in point of fact I don't know how it
> had PM_HIDE in the first place.

It didn't.  I think the relevant change is this:

@@ -2033,6 +2033,10 @@
 	 * because we've checked for unpleasant surprises above.
 	 */
 	pm->node.flags = (PM_TYPE(pm->node.flags) | on | PM_SPECIAL) & ~off;
+	/*
+	 * Readonlyness of special parameters must be preserved.
+	 */
+	pm->node.flags |= tpm->node.flags & PM_READONLY;
 	if (newspecial == NS_SECONDS) {
 	    /* We save off the raw internal value of the SECONDS var */
 	    tpm->u.dval = getrawseconds();

So what was happening before was that ARGC wasn't being hidden, it was
staying special but was incorrectly being marked as not readonly, which
doesn't make sense since the special meaning is by definition a readonly
one (and goodness knows what effect changing it had).  It seems to me
therefore that adding the "-h" in zkbd is the pukka thing to do.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-03-14 19:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-13 20:27 zkbd fails: must be run as a function or shell script, not sourced Frank Terbeck
2008-03-13 20:35 ` Mikael Magnusson
2008-03-13 20:52   ` Frank Terbeck
2008-03-13 23:28 ` Bart Schaefer
2008-03-14 19:57   ` 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).