zsh-workers
 help / color / mirror / code / Atom feed
* local variable setting problem/bug
@ 1996-11-19 21:31 Robert F Tobler
  1996-11-20  1:41 ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Robert F Tobler @ 1996-11-19 21:31 UTC (permalink / raw)
  To: Zsh Workers

I encountered the following problem when writing a function (this is in zsh  
3.00 on Nextstep, confirmed in zsh 3.01 on Nextstep, zsh 3.00 on Irix and zsh  
2.6-beta13 on linux:

I wanted to create local variables and set them to empty lists (could  
probably done more elegantly, or is maybe unnecessary, but I did it this way):

    myfun ()
    {
	local aopt=() eopt=() dopt=()
	...	

Since the 'locality' did not work I found out that introducing the empty  
lists produced the following effect (using 'functions' to print out what zsh  
thinks about 'myfun'):

    myfun () {
	    local aopt= () {
		    eopt=() dopt=()
	    }
	    ...

This in itself is highly nonintuitive: I guess the first =() is interpreted
as a start of a new function definition, as opposed to a variable
initialization the way I think it should be (or am I mistaken? - I haven't
programmed zsh all that long).

But even worse than that, try the following function:

    bug()
    {
	local a=()
	local b
	local c
    }

On Nextstep 3.3 running zsh 3.00 or zsh 3.01 (with -f option) I get:
	zsh: 24224 segmentation fault  zsh -f

On Linux 1.3.52 running zsh 2.6-beta13 I get (after a while):
	zsh: fatal error: out of memory

And on Irix 5.2 running zsh 3.00 it also consumes memory and
won't terminate normally.

Nevertheless I am very fond of zsh, and therefore I hope you can fix this problem!

------------------------------------------------------------------------
  Robert F. Tobler                 -  tel:+43(1)58801-4585,fax:5874932
  Institute of Computer Graphics   -  mailto:rft@cg.tuwien.ac.at
  Vienna University of Technology  -  http://www.cg.tuwien.ac.at/~rft/


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

* Re: local variable setting problem/bug
  1996-11-19 21:31 local variable setting problem/bug Robert F Tobler
@ 1996-11-20  1:41 ` Zoltan Hidvegi
  1996-11-20  2:02   ` Hrvoje Niksic
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-11-20  1:41 UTC (permalink / raw)
  To: rft; +Cc: zsh-workers

> But even worse than that, try the following function:
> 
>     bug()
>     {
> 	local a=()
> 	local b
> 	local c
>     }
> 
> On Nextstep 3.3 running zsh 3.00 or zsh 3.01 (with -f option) I get:
> 	zsh: 24224 segmentation fault  zsh -f
> 
> On Linux 1.3.52 running zsh 2.6-beta13 I get (after a while):
> 	zsh: fatal error: out of memory
> 
> And on Irix 5.2 running zsh 3.00 it also consumes memory and
> won't terminate normally.

That's not surprising since local a=() in fact defined a function local and
a function a= which executed local b.  So the function called local
recursively calls itself and there is not exit from this recursion.  You
probably wanted to use it as

bug() {
	local a
	a=()
	...
}

You cannot initialise local variables with an array at declaration.  You
must use a separate assignment for that.

Zoltan


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

* Re: local variable setting problem/bug
  1996-11-20  1:41 ` Zoltan Hidvegi
@ 1996-11-20  2:02   ` Hrvoje Niksic
  1996-11-20 15:33     ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Hrvoje Niksic @ 1996-11-20  2:02 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: rft, zsh-workers

Zoltan Hidvegi (hzoli@cs.elte.hu) wrote:
> That's not surprising since local a=() in fact defined a function local and
> a function a= which executed local b.  So the function called local
> recursively calls itself and there is not exit from this recursion.
> You

Couldn't zsh check its recursion depth?  It shouldn't be too hard to
implement, and would be a win in these cases.

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
`VI' - An editor used by those heretics that don't subscribe to
       the Emacs religion.


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

* Re: local variable setting problem/bug
  1996-11-20  2:02   ` Hrvoje Niksic
@ 1996-11-20 15:33     ` Zoltan Hidvegi
  1996-11-20 19:32       ` Hrvoje Niksic
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-11-20 15:33 UTC (permalink / raw)
  To: Hrvoje Niksic; +Cc: rft, zsh-workers

Hrvoje Niksic wrote:
> Couldn't zsh check its recursion depth?  It shouldn't be too hard to
> implement, and would be a win in these cases.

That was already discussed some time ago.  The problem is that one may want
to use recursive functions on purpose and an artificial limit is
undesirable here.

Zoltan


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

* Re: local variable setting problem/bug
  1996-11-20 15:33     ` Zoltan Hidvegi
@ 1996-11-20 19:32       ` Hrvoje Niksic
  0 siblings, 0 replies; 5+ messages in thread
From: Hrvoje Niksic @ 1996-11-20 19:32 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: rft, zsh-workers

Zoltan Hidvegi (hzoli@cs.elte.hu) wrote:
> Hrvoje Niksic wrote:
> > Couldn't zsh check its recursion depth?  It shouldn't be too hard to
> > implement, and would be a win in these cases.
> 
> That was already discussed some time ago.  The problem is that one may want
> to use recursive functions on purpose and an artificial limit is
> undesirable here.

Of course.  But the artificial limit can be set quite high, so that it
server _only_ to prevent core dumps.  E.g. XEmacs has max-specpdl-size
set to 3000.  I suppose it could be easy to add an ulimit-like
mechanism to control this value.

What do you think of that?

-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
`VI' - An editor used by those heretics that don't subscribe to
       the Emacs religion.


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

end of thread, other threads:[~1996-11-20 19:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-19 21:31 local variable setting problem/bug Robert F Tobler
1996-11-20  1:41 ` Zoltan Hidvegi
1996-11-20  2:02   ` Hrvoje Niksic
1996-11-20 15:33     ` Zoltan Hidvegi
1996-11-20 19:32       ` Hrvoje Niksic

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).