On 6/10/19 5:54 AM, Andrew Haley wrote:
> On 6/10/19 8:24 AM, Martin Liška wrote:
> 
>> I've just noticed that we have couple of alloca (0) in libiberty:
>>
>> #ifndef REGEX_MALLOC
>> # ifdef C_ALLOCA
>>       alloca (0);
>> # endif
>> #endif
>>
>> If I'm correct the value 0 has a special meaning that tells a C library
>> to clean up all previous alloca allocations.
>>
>> man alloca does not document the behavior
> 
> I'm sure it doesn't. This alloca(0) behaviour is a libiberty-internal
> thing.
It's not really libiberty-internal, the C-alloca implementation on top
of malloc was commonly copied into various free software packages in the
90s.

In that implementation alloca(0) had special meaning -- it asked for a
cleanup which was useful in certain circumstances when the C
implementation couldn't detect you'd previously left a scope and thus
wasn't aware it could clean up stuff.  We used to have alloca(0)
sprinkled all over the GCC sources to deal with these issues.


> 
>> Question is how legacy is alloca call from a standard library?
> 
> alloca(3) is implemented by GCC as a builtin. It's fast, simple, and
> widely used. These days you might use variable-length arrays instead,
> which are at least portable.
> 
> Is there some problem that you want to solve?
Certainly the GCC builtin is better as are VLAs compared to the old C
implementation on top of malloc.
jeff

Reply via email to