[PATCH 2 of 2] osutil.c: replace alloca() with malloc() and remove <alloca.h>

Hasso Tepper hasso at estpak.ee
Mon Oct 8 08:31:45 UTC 2007


Benoit Boissinot wrote: 
> I've seen the following code in other places:
> 
> #if defined(__FreeBSD__)
> #include <stdlib.h>
> #elif defined(_WIN32)
> #include <malloc.h>
> #else
> #include <alloca.h>
> #endif

Which is wrong at least in sense that AFAIK all BSD platforms have
alloca() defined in stdlib.h. So, in this will you will end up using at
least:

#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
#include <stdlib.h>
#elif defined(_WIN32)
#include <malloc.h>
#else
#include <alloca.h>
#endif

I think that it makes much more sense to test existance of the alloca.h
and use something like this:

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#elif defined(_WIN32)
#include <malloc.h>
#else
#include <stdlib.h>
#endif


-- 
Hasso Tepper



More information about the Mercurial-devel mailing list