From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25458 invoked by alias); 26 Mar 2011 07:14:34 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15903 Received: (qmail 2080 invoked from network); 26 Mar 2011 07:14:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110326001415.ZM31882@torch.brasslantern.com> Date: Sat, 26 Mar 2011 00:14:15 -0700 In-reply-to: Comments: In reply to nix@myproxylists.com "Re: How to add string to end of each array element without loops" (Mar 26, 4:39am) References: <9861b13e6828d43041a5b489f016664a.squirrel@gameframe.net> <110325150350.ZM30913@torch.brasslantern.com> <9cf85fb41e83cdaa17ad01277e478571.squirrel@gameframe.net> <110325191023.ZM31052@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: How to add string to end of each array element without loops MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Mar 26, 4:39am, nix@myproxylists.com wrote: } } Line 143: print -l ${(n)PROXIES} >> $Proxy_List causes segfault. I can't } see where the problem is, if you try IP range up to one million, it will } work good. Aha. I'm able to reproduce this with typeset -A a a=({5000000..1} {1..5000000}) print -l $a >> /dev/null What's actually failing is builtin.c line 283, the declaration VARARR(char *, argarr, argc + 1); This is attempting to allocate the entire argument list of "print" (which in my example is 5 million words) on the C function call stack. Even with "unlimit stacksize" this is likely to overflow. The program merely doesn't discover that this has failed until a few lines later when it tries to use the first element of the array. There's really nothing that can be done about this. The whole shell paradigm of passing arguments as an argv[] array means that $a has to be expanded and then "print" called with the words by value. So what you have to do to work around this is NOT rely on "print -l" to insert the newlines, and instead insert them yourself: print ${(F)PROXIES} >> $Proxy_List This passes a single giant word with embedded newlines to "print" and thus avoids allocating all that space on the C stack. You're really past the design limits here of what a language with the semantic rules of a command shell is meant to deal with. If "print" were not a builtin you'd have blown out the limits of argument passing before even getting as far as you did; even with the (F) trick, using /bin/echo will fail with "argument list too long". I noticed you loaded the mapfile module even though you don't use it. It should work to do mapfile[$Proxy_list]=${(F)PROXIES} but whether that's actually faster than "print >>" I haven't checked.