This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] malloca v2

On Sun, Jan 13, 2013 at 12:34:23PM -0800, Paul Eggert wrote:
> Some comments:
> On 01/13/2013 02:05 AM, OndÅej BÃlka wrote:
> >    When memory cannot be allocated from heap
> >    malloca aborts.
> Isn't it common for functions to want to fail (setting errno ==
> ENOMEM, say) when memory cannot be allocated?  These functions can't
> call malloca if it has the described behavior.  Shouldn't malloca, or
> a variant, support such functions?

There was comment that malloca should abort on out of memory condition.
I change it back to returning NULL and letting function set ENOMEM.

> >    You must write MALLOCA_INIT() at start of each function that uses malloca.
> >    Memory is freed automaticaly. 
> The documentation should explain more carefully how the memory is
> allocated and freed, and any restrictions on it.  Is it OK to put
> declarations before MALLOCA_INIT?  Is it OK to put MALLOCA_INIT inside
> a nested block?  If the latter, does the storage allocated by malloca
> have a lifetime equal to that of the calling function, or of the
> containing block?  If the calling function is inlined, does the
> allocated storage persist into the calling function's caller?  Can one
> use malloca and variable-length arrays in the same function, and if
> so, how do they interact?  That sort of thing.
This behaviour depends on compiler. For simplicity I would allow it only
on start of function.  
Putting MALLOCA_INIT into nested block is possible but then
stack allocated memory is freed on end function but heap allocated on
end of block. 

As inlining is concerned gcc does not inline functions with alloca/VLA.
When inlined by icc/llvm it is freed when function returns.

malloca and VLA should not cause a problem. 

> > #undef alloca_account
> > #define alloca_account(n, var) ({                 \
> >   void *__r = alloca(n);                          \
> >   __r;                                            \
> > })
> Why is this needed?  A comment perhaps.

Not exactly needed, point is that when using __libc_use_alloca that I
proposed alloca_account as is now will count memory usage twice.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]