Re: [PATCH] Use malloca instead alloca

2013-01-07 Thread Roland McGrath
Paul's points are valid as a generic thing. But they aren't the key points for considering changes to libc. The entire discussion about maximum usable size is unnecessary fritter. We already have __libc_use_alloca, alloca_account, etc. (include/alloca.h) to govern that decision for libc code. If

Re: [PATCH] Use malloca instead alloca

2012-12-30 Thread KOSAKI Motohiro
>> For platform specific way best solution is to read where bottom of stack is >> and allocate only when at least say 32768 bytes are left. >> > > And when knowing stack boundaries I could also recognize stack pointer > by single comparison. > > It needs to define _STACK_TOP,_STACK_CUP, _STACK_SIZE

Re: [PATCH] Use malloca instead alloca

2012-12-30 Thread KOSAKI Motohiro
> And on linux it will always succeed and be killed by oom later. I suspect you forgot /proc/sys/vm/overcommit_memory=2 (i.e. account always mode). Moreover, the default mode (/proc/sys/vm/overcommit_memory=1, ie account guess mode) also may return failure if you try obvious big size allocation.

Re: [PATCH] Use malloca instead alloca

2012-12-30 Thread Andreas Schwab
Ondřej Bílka writes: > static inline freea(void * __r) void Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."

Re: [PATCH] Use malloca instead alloca

2012-12-30 Thread Ondřej Bílka
On Sat, Dec 29, 2012 at 05:23:17PM +0100, Ondřej Bílka wrote: > On Sat, Dec 29, 2012 at 03:29:36PM +0100, Petr Baudis wrote: > > > > So it is still unsafe to call malloca() in a loop. This is also > > something that should be documented. Or can't we do better? I think even > > having an alternativ

Re: [PATCH] Use malloca instead alloca

2012-12-30 Thread Ondřej Bílka
On Sat, Dec 29, 2012 at 06:21:55PM -0800, Paul Eggert wrote: > On 12/29/2012 11:18 AM, Ondřej Bílka wrote: > > > alloca caused segfault on oom condition and null pointer > > access has equivalent behaviour. > > alloca doesn't always cause a SEGV on out of memory. > That's part of the problem that

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Paul Eggert
On 12/29/2012 11:18 AM, Ondřej Bílka wrote: > alloca caused segfault on oom condition and null pointer > access has equivalent behaviour. alloca doesn't always cause a SEGV on out of memory. That's part of the problem that we're trying to cure. If alloca is given too large a number, it might SEGV

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Petr Baudis
Hi! I applaud any effort that absolves us of the current unholy pointer flags we need to keep track of now. On Sat, Dec 29, 2012 at 11:33:15AM +0100, Ondřej Bílka wrote: > /* Safe automatic memory allocation. >Copyright (C) 2012 Free Software Foundation, Inc. > >This program is free

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Ondřej Bílka
On Sat, Dec 29, 2012 at 09:38:04AM -0800, Paul Eggert wrote: > Thanks for looking into this. Three comments. > > First, as far as correctness goes, one cannot simply replace > { P = alloca (N); use (*P); } with > { P = malloca (N); use (*P); freea (P); }, > as was done in the examples in >

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Paul Eggert
Thanks for looking into this. Three comments. First, as far as correctness goes, one cannot simply replace { P = alloca (N); use (*P); } with { P = malloca (N); use (*P); freea (P); }, as was done in the examples in . This is because mall

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Ondřej Bílka
On Sat, Dec 29, 2012 at 03:29:36PM +0100, Petr Baudis wrote: > Hi! > > I applaud any effort that absolves us of the current unholy pointer > flags we need to keep track of now. > > On Sat, Dec 29, 2012 at 11:33:15AM +0100, Ondřej Bílka wrote: > > /* Safe automatic memory allocation. > >Co

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Andreas Schwab
Ondřej Bílka writes: > #define malloca(n) ({\ > size_t __n__ = n;\ Macro arguments must be properly parenthesised. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."

Re: [PATCH] Use malloca instead alloca

2012-12-29 Thread Ondřej Bílka
On Fri, Dec 28, 2012 at 03:17:30PM -0500, Rich Felker wrote: > On Fri, Dec 28, 2012 at 06:38:23PM +0100, Ondřej Bílka wrote: > > /* malloca(N) is a safe variant of alloca(N). It allocates N bytes of > > memory allocated on the stack or heap for large requests. > > It must be freed usin

Re: [PATCH] Use malloca instead alloca

2012-12-28 Thread Ondřej Bílka
On Fri, Dec 28, 2012 at 09:08:39AM -0800, Paul Eggert wrote: > On 12/28/2012 05:29 AM, Ondřej Bílka wrote: > >Initialy I examined gnulib one but it uses hash tables and is hard to > >inline so I wrote faster variant. > > Where is the faster variant? Below. I fixed few details since first submiss

Re: [PATCH] Use malloca instead alloca

2012-12-28 Thread Paul Eggert
On 12/28/2012 05:29 AM, Ondřej Bílka wrote: Initialy I examined gnulib one but it uses hash tables and is hard to inline so I wrote faster variant. Where is the faster variant? Should/could it be merged into gnulib?