[PATCH 1/2] Revert "ash: use alloca to get rid of setjmp"
Xabier Oneca -- xOneca
xoneca at gmail.com
Wed Jul 22 23:05:04 UTC 2015
2015-07-22 14:48 GMT+02:00 Ron Yorston <rmy at pobox.com>:
> Xabier Oneca wrote:
>>I'm not an expert, but why not just use plain ol' malloc?
>
> That's what the code in question did originally.
>
> This is in the shell parser which is recursive and has to allow errors
> to propagate upwards. The code in this case had setjmp/longjmp calls
> to avoid leaking allocated memory when a parse error was detected at a
> lower level. This made the code more obscure (and bigger!).
>
> Using alloca allows the memory to be freed automatically when the function
> returns and results in simpler (and smaller!) code.
>
> Ron
Thanks for the explanation. Now I have read and understand more about
setjmp. Didn't know it was used to implement an exception handler...
Shell parsing is hell! :S
Cheers,
Xabier Oneca_,,_
More information about the busybox
mailing list