Hmm.. thought I replied to this already, but the mail seems to have
gone to lala land.  My apologies if people get two replied.

> On Friday, 02 July 2010, at 01:31:13 (-0700),
> Enlightenment SVN wrote:
> 
> > Log:
> >   Don't check alloca, it's like checking the stack exists.
> 
> It can't fail on *GNU* libc, but there's nothing in the standard that
> stops it from returning NULL on stack overflow.  In fact, the man page
> implies that other platforms do exactly that. 

So did you read the man page you are quoting?

Alloca is not part of any major standard.  As the alloca man page on
linux says:
        "This function is not in POSIX.1-2001."
Which also tells us it's not part of C89.  It's not part of C99 (VLAs
are instead).  It's not part of SUS either.  At this point we are
pretty much out of useful standards.  So I'm not sure which is "the
standard" you refer too.

Alloca is generally implemented as single adjustment of the stack
pointer (hence alloca(0)[1] is a well known technique to get the address
of the stack pointer).  To call the OS to check if there is enough
stack pointer kinda ruins the whole point as it's meant to fast.

As for other platforms:
        Linux: Probably get a SIGSEGV: No NULLs
        FreeBSD: May give you pointers to other memory: No NULLs
        Solaris: 'Undefined' if too large: Maybe a NULL, also may
                execute /usr/games/nethack, or a case of nasal demons.
        Windows: Generates a structured exception: Doesn't return a
                NULL.
        Glib: Wraps it in a macro.  Point out it never returns NULL[2]
        
If you do know of a platform which can return a null[3], I'd be
interested to hear.  As it would be an essentially unique
implementation, or using a malloc and garbage collection.

Until then, I'm going to continue to put people checking the alloca
return value in the category of "doesn't know what alloca does, and
unable to read documentation".

>                                                So this change is
> likely wrong.

So nope, it's likely correct.

        nash


[1] Which is broken by the autofoo work-around for systems without
alloca.
[2]
http://library.gnome.org/devel/glib/stable/glib-Memory-Allocation.html#g-alloca
[3] I suppose you could do: alloca((size_t)alloca(0));  But then
it's returning NULL as a success.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to